Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Java program using Itellij - JDK Write a Java program that determines which student has the highest grade. You will ask the

Need help with Java program using Itellij - JDK

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. Note: If two scores are tied for highest, you do NOT need to handle that as a special case in this assignment. (Without the use of arrays, that would be very difficult.)

Objectives:

To learn to use for loops

To learn to use comparisons (if statements)

To learn to use additional local variables to save contents of other variables (in this case, both an integer and a String)

To learn to deal with garbage at the end of a users input line by burning the rest of it with input.nextLine()

To learn the very common coding pattern of finding the highest number in a set of numbers entered by the user without using an array.

To test various scenarios to make sure all solutions work as intended

To debug any problems that you might run into Instructions:

3. 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. Revised: 10/2/2017 6:15:00 AM 2

6. At this point, try to compile and run your program. Dont 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 ", numStudents); It should be commented out before turning in the program (put // in front of it) or delete the line.

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

8. 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 doesnt do it automatically, then put all the statement to be repeated BETWEEN the curly braces): for (int i = 0; i < numStudents; i++) { a. 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, even though there is nothing there that you can see. 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 its not already there.

9. Outside of the for loop, print highestName and highestScore.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions