I am suppose to make a one dimensional array until the user enters "alldone", however i dont know how to make it . This what i have and i know it is wrong .
The instruction are "Design a solution that requests and receives student names and an exam score for each. Use one-dimensional arrays to solve this.
The program should continue to accept names and scores until the user inputs a student whose name is “alldone”. After the inputs are complete determine which student has the highest score and display that student’s name and score. Finally sort the list of names and corresponding scores in ascending order."
Code so far:
String name = "";
String highName = "";
int highScore = 0;
while (name != "alldone") {
System.out.println("Enter name of student");
name = input.nextLine();
System.out.println("Enter grade of student.");
int score = input.nextInt();
if (name != "alldone" && score > highScore)
highName = name;
highScore = score;
// System.out.println("Enter name"); name = input.nextLine(); }
// System.out.println(highName + " had the highest score which was "
// + highScore);
}
now i have done this
Scanner in = new Scanner(System.in);
int size= 1;
String[] studentNames= new String[size];
System.out.println("Enter name of student");
String input = in.nextLine();
String name = input;
if (!name.equals("alldone")) {
for (int i = 0; i < size; i++)
studentNames[i]= in.nextLine();
}
else return;
for (int k = 0; k<studentNames.length; k++) {
System.out.println(studentNames[k] + " "); //so it can display names