• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
chosenkill6

Ordering strings

7 posts in this topic

I have a method which loads data from a Student object. I would like to be able to get a string from that method which holds the data the student class contains.

	public static String getData(String order) throws IOException{
		
                //create string array for each type of data student object can hold
		String[] firstNames = new String[numberOfStudents];
		String[] lastNames = new String[numberOfStudents];
		String[] grade = new String[numberOfStudents];
		String[] age = new String[numberOfStudents];
		String[] email = new String[numberOfStudents];
		
		for(int i = 0; i < numberOfStudents; i++){
                        //get data from each student object
			firstNames[i] = readFirstName(studentArray[i]);
			lastNames[i] = readLastName(studentArray[i]);
			grade[i] = readGrade(studentArray[i]);
			age[i] = readAge(studentArray[i]);
			email[i] = readEmail(studentArray[i]);
		}
		//HERE i would like to be able to order by first name or last name but i                //would like to keep the last name and grades with its own first name
		if(order == "FIRST_NAME"){
			
		}else{
			
		}
		return "NULL";
	}

 

I hope I am being clear for what I am trying to achieve. It may be difficult to understand from just looking  at this method.

 

Thanks

0

Share this post


Link to post
Share on other sites

In this case you may be better off creating a Student class which contains the information for a single student, and then have an array of Students, instead of five disjoint arrays each containing some information about each student. Then you should be able to sort the Student array with a custom comparator (based on the first or last name, or anything else about each student), though I am not sure how to do this in C#. This will keep all the data together.

0

Share this post


Link to post
Share on other sites

That is exactly what I am doing. I have an array of 20 students. Each read method takes a student object as a parameter and reads the appropriate information from a file for that student. How would I implement such a custom comparator?

0

Share this post


Link to post
Share on other sites

That is exactly what I am doing. I have an array of 20 students. Each read method takes a student object as a parameter and reads the appropriate information from a file for that student. How would I implement such a custom comparator?

 

 I don't see an array of students. I see five arrays of strings each containing a piece of data for each student. So my idea was to ditch those string arrays (they are not helping you) and sort the studentArray according to whatever sort order you need. For comparing using a custom function, have you tried this?

 

http://support.microsoft.com/kb/320727

 

The idea is to provide some comparison function which will compare two arbitrary Student objects (in there you can decide whether to sort by first name, last name, etc..) and then feed this function to your standard library's sort function (actually, it should work directly if you implement the comparator properly, at least that's how it works in Java). Either way, this should sort the Students correctly and keep their data together (i.e. two students won't end up with wrong ages after sorting by name).

0

Share this post


Link to post
Share on other sites

The array of students is created elsewhere and each student contains firstname, lastname, grade, age, email. I would like to list by first name but then have the appropriate lastname, grade etc with that first name. So if i have student[0] and it contains 'b' for every field and i have student[1] and it contains 'a' for every field i would like to have output:

 

a a a a a

b b b b b

0

Share this post


Link to post
Share on other sites

In this case you may be better off creating a Student class which contains the information for a single student, and then have an array of Students, instead of five disjoint arrays each containing some information about each student. Then you should be able to sort the Student array with a custom comparator (based on the first or last name, or anything else about each student), though I am not sure how to do this in C#. This will keep all the data together.

@Bacterius: This is actually Java, not C#.
@nitishk: The advice offered by Bacterius to implement a Student class (rather than using an array for each property) along with a comparator is the way you want to go with this.

 

See the Javadoc for Comparator.

So you'll have a List<Student> and a StudentComparator and you can use Collections.sort to reorder the list according to the comparator.

2

Share this post


Link to post
Share on other sites

@Bacterius: This is actually Java, not C#.

 

Ah, thanks for the clarification blink.png I don't know why I assumed it was C#. Though I think the only distinguisher here is the "throws IOException" and the capitalized String type. Sorry!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0