Hi I posted s thread but did have any reply,
I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6 to 9 in the menu of options:
/*the next method to be implemented is the method presentResultsToUser() which is expected to print
a menu of options on the screen and also will ask the user to choose from that menu*/
public void presentResultsToUser(){ //method starst here
/* asking for a line of input from the user */
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));//asks for a line of input
int i;
boolean yes = false; /*declaration of the boolean yes which is the first condition for the while
statement*/
while(!yes){ //while statements starts here
//asking the user to print lines of options
System.out.println("What would you like to see now? ");
System.out.println(" ");
System.out.println("1. Sorted list of all students’ Last Names.");
System.out.println("2. Sorted list of all students’ First Names");
System.out.println("3. Sorted list of all students’ Matriculation Numbers.");
System.out.println("4. Sorted list of all students’ Final Grades.");
System.out.println("5. Quit the program.");
System.out.println("6. List all students and scores sorted by Last Name.");
System.out.println("7. List all students and scores sorted by First Name.");
System.out.println("8. List all students and scores sorted by Matriculation Number.");
System.out.println("9. List all students and scores sorted by Final Grade.");
System.out.println("choose one: ");
String che = stdin.readLine(); //gets a line of input
int intInput = Integer.parseInt(che); //converts input to an integer type
if(intInput==5){//if starts
yes=true; /*the boolean is true if the input is 5 hence the while statement
will not be handled*/
}//if ends
else{ //else starts here
switch(intInput){ //switch statement starts here
case 1: //first case of the switch
Collections.sort(StdLstName); /*the collections framework is used to call the sort
method*/
System.out.print("Sorted list of Last Names: "); //prints the line
for(i=0; i<StdLstName.size();i++){ //for loop starts here.
String obj = (String)StdLstName.get(i); /*unveils the vector by type casting
that is removes the object component of the vector StdLstName and put it back
to the String*/
System.out.print(obj.toString()+", "); /*Prints out the string after the sorting
of the vector using collections framework*/
}//for ends here
System.out.println(" "); //prints out an empty line
break; //Prevents the execution from continuing up to case 2
case 2: //second case of the switch
Collections.sort(StdFstName); /*the collections framework is used to call the sort
method*/
System.out.print("Sorted list of First Names: "); //prints the line
for(i=0; i<StdFstName.size(); i++){//for loop starts here for the vector StdFstName
String obj = (String)StdFstName.get(i); /*unveils the vector by type casting
that is removes the object component of the vector StdFstName and put it back
to the String*/
System.out.print(" "+obj.toString()); /*Prints out the string after the sorting
of the vector using collections framework*/
} //for loop ends here
System.out.println(" "); //prints out an empty line
break; //Prevents the execution from continuing up to case 3
case 3: //third case of the switch
Collections.sort(StdMatNum); /*the collections framework is used to call the sort
method*/
System.out.print("Sorted list of Matriculation Numbers: "); //prints the line
for(i=0; i<StdMatNum.size();i++){ //for loop starts here.
Integer obj = (Integer)StdMatNum.get(i);/*unveils the vector by type casting
that is removes the object component of the vector StdMatNum and put it back
to the String as an integer type*/
System.out.print(" " +obj.toString());/*Prints out the string after the sorting
of the vector using collections framework*/
} //for loop ends here
System.out.print("\n"); //prints out an empty line
break; //Prevents the execution from continuing up to case4
case 4: //fourth case of the switch
Collections.sort(StdFinGrade); /*the collections framework is used to call the sort
method*/
System.out.print("Sorted list of Final Grades: "); //prints the line
for(i=0; i<StdFinGrade.size();i++){ //for loop starts here.
Double obj = (Double)StdFinGrade.get(i);/*unveils the vector by type casting
that is removes the object component of the vector StdFinGrade and put it back
to the String as a double type becasuse the final grade is a double type*/
System.out.print(" "+obj.toString());/*Prints out the string after the sorting
of the vector using collections framework*/
} // for loop ends here
System.out.print("\n"); //prints out an empty line
break; //Prevents the execution from continuing up to case5
case 5: //fifth case of the switch
break; //Prevents the execution from continuing up to the default
default: //default of the switch
System.out.println("Error! Input "+intInput+" is not a valid choice."); /*printing for
the default*/
} //switch ends
}//else ends
}//while ends
System.out.println("Thank you! Goodbye!");