Question

In: Computer Science

Program 5A: Determine which student has the highest grade Write a Java program that determines which...

Program 5A: Determine which student has the highest grade Write a Java program that determines which student has the highest grade. You will ask the user to enter the number of students. Then you will ask for each student and their grade. You will output the name and grade of the student with the highest grade. You will NOT use an array for this assignment.

Call your class Program5A, so your filename will be Program5A.java. It is essential for grading purposes that everyone have the same class name. 2. Create several lines of comments of identification and description at the top of the file (it doesn’t have to look exactly like this, in particular, if your editor wants to put * in front of every line, that’s fine):

Use comments liberally to document exactly what you are doing in the program. 4. Use descriptive variable names in camel-case with the first letter in lowercase. 5. Ask the user for the number of students and assign that to a variable of type int called numStudents using the nextInt method of Scanner.

At this point, try to compile and run your program. Don’t move on until this part is working. It would be good to enter a temporary print statement just to make sure this is working: System.out.printf("numStudents = %d\n", numStudents); It should be commented out before turning in the program (put // in front of it) or delete the line.

We need variables for highestName and highestScore of types String and int, respectively. Set highestName to the empty string and highestScore to 0.

Create a for loop. (Do NOT put a semi-colon after the for statement. Put an open curly brace instead, and go ahead and put the closing brace if your IDE doesn’t do it automatically, then put all the statement to be repeated BETWEEN the curly braces):

for (int i = 0; i < numStudents; i++) { a. As the first statement in the loop, add an extra line that reads to the end of the line: input.nextLine(); This is needed after a nextInt if you are going to then read a String. This basically burns the rest of the line (it ignores everything else to and including the end of the line which in this case will just be an end-of-line character '\n'), even though there is nothing there that you can see. You will need to do this any time that you have read in an int as you did for the number of students. (You could have done it right after you read the number of students, but then you would have to do it again in the loop right after reading the score. Doing it here takes care of both with one line of code.) b. Ask the user for name and score, which will be String and int types, respectively, which will require nextLine and nextInt. c. Compare score to highestScore. If score is greater than highestScore, then assign highestScore equal to score and highestName equal to name. There will not be an else. (If they are equal, we are NOT going to change the highest score so that in the event of a tie, the first one wins. However, in real life we would deal with ties in a better manner.) d. This is the end of the for loop, so put the closing brace if it’s not already there.

Outside of the for loop, print highestName and highestScore

ample Runs: (Enter this data exactly and make screen-prints to paste into a Word document that you will turn in to prove that your program works correctly. On the last one, just hit the Enter key without entering anything; it should sit there still waiting for integer input; if you then enter an integer, everything is fine and works like normal.):

Please enter number of students:4

Enter student name:Gus

Enter score:70

Enter student name:Suzy

Enter score:80

Enter student name:Allie

Enter score:100

Enter student name:Robert

Enter score:90

Highest score: Allie 100

Process finished with exit code 0

Solutions

Expert Solution

/*********************************Program5A.java****************************/

import java.util.Scanner;

public class Program5A {

   public static void main(String[] args) {
       //scanner class for reading input
       Scanner scan = new Scanner(System.in);
       int highestScore = 0;//variable for highest score
       String highestName = "";//variable for highest scorer
       System.out.print("Please enter number of students: ");//prompt for number of student
       int numStudents = scan.nextInt();//read number of student
       scan.nextLine();//skip the buffer after integer or scan.next

       /*
       * for loop till the number of students
       */
       for (int i = 1; i <= numStudents; i++) {

           System.out.print("Enter Student name: ");//prompt for name
           String name = scan.nextLine();//read name
           System.out.print("Enter Score: ");//prompt for score
           int score = scan.nextInt();//read score
           scan.nextLine();//clear buffer
           /*
           * find highest Score
           */
           if (highestScore < score) {

               highestScore = score;//save highest Score
               highestName = name;//save highest scorer
           }

       }

       System.out.println("Highest Score: " + highestName + " " + highestScore);//print detail
       scan.close();
   }
}
/*********************output********************/

Please enter number of students: 4
Enter Student name: Gus
Enter Score: 70
Enter Student name: Suzy
Enter Score: 80
Enter Student name: Allie
Enter Score: 100
Enter Student name: Robert
Enter Score: 90
Highest Score: Allie 100

Please let me know if you have any doubt or modify the answer, Thanks:)


Related Solutions

Lab 3.4 Write a program that determines a student’s grade. The student will enter a grade...
Lab 3.4 Write a program that determines a student’s grade. The student will enter a grade and the program will determine if that grade is an A, B, C, D, or E. The student can only enter number 0-100. A = 90-100 B = 80-89 C = 70-79 D= 60-69 E = 59 or less Save the file as Lab3.4 and submit the file. Use https://repl.it/ THIS LANGUAGE IS PYTHON Thank you :)
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The program should allow creation an array of object instances to assign firstName, lastName and mark from input user and perform and assign grade based on mark’s criteria displayed below. MARKS INTERVAL 95 - 100 90 - <95 85 - <90 80 - <85 75 - <80 70 - <75 65 - <70 60 - <65 0 - <60 LETTER GRADE A+ A B+ B...
Write a program that determines a student’s grade. The program will read three types of scores...
Write a program that determines a student’s grade. The program will read three types of scores (quiz, mid-term, and final scores) and determine the grade based on the following rules: -if the average score =90% =>grade=A -if the average score >= 70% and <90% => grade=B -if the average score>=50% and <70% =>grade=C -if the average score<50% =>grade=F Using Switch Statement Need to code to be simple to understand. No pointers should be used
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else statement logic​​​​​​​​​ b)​Write a Matlab program for sensor selection of temperature, pressure, flow sensor with if-else statement logic​​​​​​​​​ ​ 2.​Assume there are four letters from an information source with probabilities as A1 0.5 A2 0.3 A3 0.1 A4 0.1 Generate the tag and find the corresponding gaps and binary values for each stage and the sequence of the symbols which are coded are a1a3a2a4a1.​​​...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade...
Write a c++ program that given a set of letter grade/credit hour combiniation, determines the grade point average (GPA) Each A is worth 4 points. Each B is worth 3 points. Each C is worth 2 points. Each D is worth 1 point, and Each F is worth 0 points. The total quality points earned is the sum of the product of letter grade points and associated course credit hours. The GPA is the quotient of the quality points divided...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
Write a program in JAVA that takes in two words, and then it recursively determines if...
Write a program in JAVA that takes in two words, and then it recursively determines if the letters of the first word are contained, in any order, in the second word. If the size of the first word is larger than the second then it should automatically return false. Also if both strings are empty then return true. YOU MAY NOT(!!!!!!!!!!): Use any iterative loops. In other words, no for-loops, no while-loops, no do-while-loops, no for-each loops. Use the string...
Write a java program using the following instructions: Write a program that determines election results. Create...
Write a java program using the following instructions: Write a program that determines election results. Create two parallel arrays to store the last names of five candidates in a local election and the votes received by each candidate. Prompt the user to input these values. The program should output each candidates name, the votes received by that candidate, the percentage of the total votes received by the candidate, and the total votes cast. Your program should also output the winner...
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT