Question

In: Computer Science

Write a java code that gets student test scores from the user. Each test score will...

Write a java code that gets student test scores from the user. Each test score will be an integer in the range 0 to 100. Input will end when the user enters -1 as the input value. After all score have been read, display the number of students who took the test, the minimum score, the maximum score, the average score (with decimal point, and the number of A where an A is a score in the range 90-100.

Solutions

Expert Solution

//MinMaxAvgScore.java
import java.util.Scanner;

public class MinMaxAvgScore {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        int min = Integer.MAX_VALUE,max = Integer.MIN_VALUE,sum = 0;
        double avg;
        int i = 0, gradeA = 0;

        System.out.print("Enter score in the range 0 to 100: ");
        n=sc.nextInt();

        while (n!=-1){
            i++;
            if(min>n){
                min = n;
            }
            if(max<n){
                max = n;
            }
            sum += n;
            if(n>90){
                gradeA += 1;
            }

            System.out.print("Enter score in the range 0 to 100: ");
            n=sc.nextInt();
        }
        if(i>0) {
            avg = sum / i;
            System.out.println("Number of tests: "+i);
            System.out.println("Minimum score: "+min);
            System.out.println("Maximum score: "+max);
            System.out.println("Average score: "+avg);
            System.out.println("Number of grade A scores: "+gradeA);
        }

    }
}


Related Solutions

Sections 7.1 Write a program that reads student scores, gets the best score, and the assigns...
Sections 7.1 Write a program that reads student scores, gets the best score, and the assigns grades based on the following scheme: Grade is A if scores is >= best - 10; Grade is B if scores is >= best - 20; Grade is C if scores is >= best - 30; Grade is D if scores is >= best - 40; Grade is F otherwise. The program prompts the user to enter the total number of students, then prompts...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
Instructions Write a Java program that asks the user t enter five test scores. The program...
Instructions Write a Java program that asks the user t enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: * calcAverage -- This method should accept five test scores as arguments and return the average of the scores. * determineGrade -- This method should accept a test score as an argument and return a letter grade for the score, based on the following...
Can you write code or class in java accepting from the user a + b as...
Can you write code or class in java accepting from the user a + b as a string and accepting their value from the user and the out but will be the sum of the variables.
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
Write a java code that allows the user to input any word/name from the console (10...
Write a java code that allows the user to input any word/name from the console (10 words/names only) and then sorts and alphabetizes them into an array without using predefined methods (.compareTo(), or any sorter functions) and then print out the results. you must have three methods that can: Compare multiple strings Swap elements Sort and alphabetize string ***REMEMBER DO NOT USE ANY PRE-DEFINED METHODS*** Example of how the code should work: Enter names/words (10 only): "james, john, alex, aaron,...
JAVA Write code which takes three decimal inputs from the user, creates a circle with a...
JAVA Write code which takes three decimal inputs from the user, creates a circle with a radius equal to the first input and a rectangle with length and width equal to the second and third input respectively, then prints both of these shapes. Sample run: Type a radius: 3.7 Type a length: 4.9 Type a width: 8.6 circle with radius 3.7 rectangle with length 4.9, width 8.6
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 an application that allows a user to enter any number of student quiz scores, as...
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT