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 presentResultsT oUser() 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 presentResultsT oUser(){ //method starst here
/* asking for a line of input from the user */
BufferedReader stdin = new BufferedReader( new InputStreamRead er(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.prin tln("What would you like to see now? ");
System.out.prin tln(" ");
System.out.prin tln("1. Sorted list of all students’ Last Names.");
System.out.prin tln("2. Sorted list of all students’ First Names");
System.out.prin tln("3. Sorted list of all students’ Matriculation Numbers.");
System.out.prin tln("4. Sorted list of all students’ Final Grades.");
System.out.prin tln("5. Quit the program.");
System.out.prin tln("6. List all students and scores sorted by Last Name.");
System.out.prin tln("7. List all students and scores sorted by First Name.");
System.out.prin tln("8. List all students and scores sorted by Matriculation Number.");
System.out.prin tln("9. List all students and scores sorted by Final Grade.");
System.out.prin tln("choose one: ");
String che = stdin.readLine( ); //gets a line of input
int intInput = Integer.parseIn t(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.sor t(StdLstName); /*the collections framework is used to call the sort
method*/
System.out.prin t("Sorted list of Last Names: "); //prints the line
for(i=0; i<StdLstName.si ze();i++){ //for loop starts here.
String obj = (String)StdLstN ame.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.prin t(obj.toString( )+", "); /*Prints out the string after the sorting
of the vector using collections framework*/
}//for ends here
System.out.prin tln(" "); //prints out an empty line
break; //Prevents the execution from continuing up to case 2
case 2: //second case of the switch
Collections.sor t(StdFstName); /*the collections framework is used to call the sort
method*/
System.out.prin t("Sorted list of First Names: "); //prints the line
for(i=0; i<StdFstName.si ze(); i++){//for loop starts here for the vector StdFstName
String obj = (String)StdFstN ame.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.prin t(" "+obj.toString( )); /*Prints out the string after the sorting
of the vector using collections framework*/
} //for loop ends here
System.out.prin tln(" "); //prints out an empty line
break; //Prevents the execution from continuing up to case 3
case 3: //third case of the switch
Collections.sor t(StdMatNum); /*the collections framework is used to call the sort
method*/
System.out.prin t("Sorted list of Matriculation Numbers: "); //prints the line
for(i=0; i<StdMatNum.siz e();i++){ //for loop starts here.
Integer obj = (Integer)StdMat Num.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.prin t(" " +obj.toString() );/*Prints out the string after the sorting
of the vector using collections framework*/
} //for loop ends here
System.out.prin t("\n"); //prints out an empty line
break; //Prevents the execution from continuing up to case4
case 4: //fourth case of the switch
Collections.sor t(StdFinGrade); /*the collections framework is used to call the sort
method*/
System.out.prin t("Sorted list of Final Grades: "); //prints the line
for(i=0; i<StdFinGrade.s ize();i++){ //for loop starts here.
Double obj = (Double)StdFinG rade.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.prin t(" "+obj.toString( ));/*Prints out the string after the sorting
of the vector using collections framework*/
} // for loop ends here
System.out.prin t("\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.prin tln("Error! Input "+intInput+ " is not a valid choice."); /*printing for
the default*/
} //switch ends
}//else ends
}//while ends
System.out.prin tln("Thank you! Goodbye!");