Question

Write a JAVA program that prompts the user for student grades and displays the highest and...

Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values.

Starter code:

import java.util.Scanner;

public class MaxMinGrades{

  public static void main(String[] args){

    Scanner input = new Scanner(System.in);

    System.out.println("Enter as many student grades as you like. Enter a character to stop.");

    double grade = input.nextDouble();

    double minGrade = Double.MAX_VALUE;

    double maxGrade = Double.MIN_VALUE;

    while (Character.isDigit(grade)) {

      if (grade == 0) {

          break;

      }

      if (grade < minGrade) {

          minGrade = grade;

      }

      if (grade > maxGrade) {

         maxGrade = grade;

      }

    }

    System.out.println("The highest grade is: " + maxGrade);

    System.out.println("The lowest grade is: " + minGrade);

  }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class MaxMinGrades{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Enter as many student grades as you like. Enter a character to stop.");
        int grade = input.nextInt();
        double minGrade = Double.MAX_VALUE;
        double maxGrade = Double.MIN_VALUE;
        while (!Character.isDigit(grade)) {
            if (grade == 0) {
                break;
            }

            if (grade < minGrade) {
                minGrade = grade;
            }

            if (grade > maxGrade) {
                maxGrade = grade;
            }
            try {
                grade = input.nextInt();
            }
            catch (Exception ex){
                break;
            }
        }
        System.out.println("The highest grade is: " + maxGrade);
        System.out.println("The lowest grade is: " + minGrade);
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a JAVA program that prompts the user for student grades and displays the highest and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that prompts the user for student grades and displays the highest and lowest grades in the class.

    Write a program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values.example Enter as many student grades as you like. Enter a character to stop. The highest grade is: 92.0 The lowest grade is: 10.65# in java

  • Write a program that prompts the user for student grades, calculates and displays the average grade...

    Write a program that prompts the user for student grades, calculates and displays the average grade in the class. The user should enter a character to stop providing values.

  • (Process a string) Write a program that prompts the user to enter a string and displays...

    (Process a string) Write a program that prompts the user to enter a string and displays its length and its first character. java StringLength Enter a string:Does quantum determinacy have anything to with whether human cognition is deterministic? The string is of length 88 and the first character is D import java.util.Scanner; class StringLength{    public static void main (String args[]){        Scanner input = new Scanner(System.in);        System.out.println("Enter a string:");        String ans = input.nextLine();        System.out.println("The string...

  • Complete the following program so it prompts the user for 3 integers and displays the smallest...

    Complete the following program so it prompts the user for 3 integers and displays the smallest of the 3 numbers. For instance, if the user provided 7 4 and 12, then the program would display 4. import java.util.Scanner; public class Program3{ public static void main(String[] args) { Scanner kb = new Scanner(System.in);

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • this is the qestion it has to be in java Example of what i need y...

    this is the qestion it has to be in java Example of what i need y Booleato Tools Window Help Hesustor X C C CB https:/class.mimiloassignments/e645f0d9-8eb-4d9b-818-6bb684bBeb/do/90db2810 O Reset to Starter 10 points possible CH4 Exerc. Seved Question 3 Question 3 Write a program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to providing values Grading Full Screen • MaxMinGrades.Java New } catch (Exception e) {...

  • Java Program 1. Write a class that reads in a group of test scores (positive integers...

    Java Program 1. Write a class that reads in a group of test scores (positive integers from 1 to 100) from the keyboard. The main method of the class calls a few other methods to calculate the average of all the scores as well as the highest and lowest score. The number of scores is undetermined but there will be no more than 50. A negative value is used to end the input loop. import java.util.Scanner; public class GradeStat {...

  • JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the...

    JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the user for the width and height of the rectangle. For example: Enter the width and the height of our box. 3 5 *** * * * * * * *** import java.util.Scanner; public class DrawBox { public static void main(String[] args) { Scanner in = new Scanner(System.in);        System.out.println("Enter the width and the height of our box."); /* Type your code here. */...

  • LAB: Student grades (HashMap)

    LAB: Student grades (HashMap)Given a HashMap pre-filled with student names as keys and grades as values, complete main() by reading in the name of a student, outputting their original grade, and then reading in and outputting their new grade.Ex: If the input is:Quincy Wraight 73.1the output is:Quincy Wraight's original grade: 65.4 Quincy Wraight's new grade: 73.1StudentGrades.java:import java.util.Scanner; import java.util.HashMap; public class StudentGrades {            public static void main (String[] args) {       Scanner scnr = new Scanner(System.in);       String studentName;       double studentGrade;              HashMap<String, Double> studentGrades = new HashMap<String, Double>();              // Students's grades (pre-entered)       studentGrades.put("Harry Rawlins", 84.3);       studentGrades.put("Stephanie Kong", 91.0);       studentGrades.put("Shailen Tennyson", 78.6);       studentGrades.put("Quincy Wraight", 65.4);       studentGrades.put("Janine Antinori", 98.2);              // TODO: Read in new grade for a student, output initial        //       grade, replace with new grade in HashMap,       //       output new grade           } }

  • The program prompts the user to input three words, then display them in      sorted order....

    The program prompts the user to input three words, then display them in      sorted order. Strings have to be compared with compareTo method. */ import java.util.Scanner; public class Lab4Part13{     public static void main(String[] args){         Scanner input = new Scanner(System.in);         // Write rest of the code here     } }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT