Question

In: Computer Science

Ask the user to enter test scores. Once they have entered -1, print out the highest...

Ask the user to enter test scores. Once they have entered -1, print out the highest grade. Ensure that the grade entered is an integer.(Using Java Language)

Enter integers between 0 and 100, -1 when finished.

Enter a test score: [asdf]

Enter an integer.

Enter a test score: [32.5]

Enter an integer.

Enter a test score: [42]

Enter a test score: [99]

Enter a test score: [87]

Enter a test score: [x]

Enter an integer.

Enter a test score: [-1]

The max grade is: 99

Solutions

Expert Solution

import java.util.Scanner;

public class MaximumGrade {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int score, maxScore = Integer.MIN_VALUE;
        while (true) {
            System.out.print("Enter a test score: ");
            try {
                score = in.nextInt();
                if (score > maxScore)
                    maxScore = score;
                if (score == -1)
                    break;
            } catch (Exception e) {
                in.nextLine();
                System.out.println("Enter an integer.");
            }
        }
        System.out.println("The max grade is: " + maxScore);
    }
}



Related Solutions

C++ program that will ask the user for how many test scores will be entered. Setup...
C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. The data will include the student’s first name and midterm score Print out the completed test scores to a file (midTermScores.txt) . Print out list of students names and grades in the print out, a letter grade should replace numeric score using standard grading (a = 90 – 100, b=80-90, c=70-80, d=60-70, f=below 60)
Write in C# please! Ask the user to enter all of their exam grades. Once they...
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter...
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be : [srivatss@athena shell]> ./mult.sh I will be printing the multiplication table Please enter a number 10 1 x 10 = 10 2 x 10 = 20 3 x 10 = 30 4 x 10 = 40 5 x 10 = 50 6 x 10 = 60 7 x 10 = 70 8 x 10...
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Q3) ​Write a main function to test your SortTriple will ask the user to enter the...
Q3) ​Write a main function to test your SortTriple will ask the user to enter the three values, then uses ​SortTriple ​to reorder the values if required. The main function should print the value in the correct order and a message to indicate if the values were in the correct order or not. ​[20 points] ● You are NOT allowed to use loops or arrays in your code​ ​[- 30 points] ● You are ​NOT​ allowed to use global variables....
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
write a c++ program . Ask the user to enter a number less than 100. Test...
write a c++ program . Ask the user to enter a number less than 100. Test the input to make sure it is correct, and use a while loop to continuously ask the user for correct input value if they don't follow the input rule. After receiving the correct input, test the number to see if it is even or odd. If it is odd, use a while loop to do the following: Output to the monitor all odd numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT