I am not sure how to do much with arrays yet and can't figure this out. Here is the full assignment.
- Write a JAVA program that maintains a list of computer games using an array. Your main program should display the following menu repeatedly.
i. insert game
s. search game
p. print list
q. Quit
Select:
The array stores a list of computer games and each game in the list consists of title(string, key), developer(string), genre(string), year of production(int), and price(float). The list should be maintained in the increasing order of the key(title).
Option i should read a game(title, developer, genre, year, price) and insert the game into the array. Note that the new game should be inserted into the right spot so that the entire array may remain sorted. Sorting entire array again after adding the new game at the end of the array is costly and hence not acceptable. Option s asks for a game title and lists all the games matching with the title entered. Note that two or more games may have the same title. Option p simply lists all the games stored in the array.
We will assume a maximum of 100 games.
And here is what I have so far
package lab12;
import java.util.Scanner;
// create second class to hold methods
class next {
// create "insert game" method
public void insert( ) {
System.out.println("Insert");
}
// create "search game" method
public void search( ) {
System.out.println("Search");
}
// create "print list" method
public void print( ) {
System.out.println("Print");
}
// create method to
}
public class Lab12 {
public static void main(String[] args) {
Scanner in = new Scanner( System.in );
// create string to see what user wishes to do
String choose;
// create instance of other class
next choice = new next();
do {
// see which method user wants to use
System.out.print("Do you want to insert game (i) or search game (s) "
+ "or print list (p) or quit (q)? ");
// create string to see which method to go to
choose = in.nextLine();
// send user to correct method
if ( choose.equals("i") || choose.equals("I"))
choice.insert();
else if ( choose.equals("s") || choose.equals("S") )
choice.search();
else if ( choose.equals("p") || choose.equals("P") )
choice.print();
} while ( choose.equals("i") || choose.equals("s") || choose.equals("p")
|| choose.equals("I") || choose.equals("S") || choose.equals("P"));
}
}
I'm not sure how to sort the games in the array, it says to sort it by key but I don't know how to put in the key with the string. I'm not good with arrays either so I don't know how you can have all of the information linked together. Thank you for all of your help! Sincerely, A stressed out college student.
Map
if you need a key, value pairing – redFIVE Dec 4 '15 at 21:24