Question

In: Computer Science

Java Input, Output and for-loop function. Practice01) Write-an average SCORE application called TestScores01 This project reads...

Java Input, Output and for-loop function.

Practice01) Write-an average SCORE application called TestScores01 This project reads in a list of integers as SCOREs, one per line, until a sentinel value of -1. After user type in -1, the application should print out how many SCOREs are typed in, what is the max SCORE, the 2nd max SCORE, and the min SCORE, the average SCORE after removing the max and min SCORE.

When SCORE >= 90, the school will give this student scholarship.

Count how many scholarships the school will give and print it our in your results.

(hint, you can add all SCOREs to a total first, then when you need the average SCORE without min and max score, you can use the total - (min + max), then divided it by the (number of inputs minus two)

Please enter test scores:

? 90

? 45

? 99

? 68

? 80

?-1

Result:

There are total 4 SCORES

The min SCORE is 45

The max SCORE is 99

The 2nd min SCORE is 68

The 2nd max SCORE is 90

The average SCORE after removing max/min SCORE is: 80

Total 2 scholarships will be given

Solutions

Expert Solution

Explanation:I have written the class AverageScoreApplication which also has the main method to show the output of the program, please find the image attached with the answer.I have used Scanner to take inputs from user.Please upvote if you liked my answer and comment if you need any modification or explanation.

//code

import java.util.Scanner;

public class AverageScoreApplication {

   public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       int countScores = 0, maxScore = -1, secondMaxScore = -1,
               minScore = 1000000, secondMinScore = 1000000, totalScore = 0,
               countScholarship = 0;

       System.out.println("Please enter test scores:");
       while (true) {
           System.out.print("? ");
           int score = input.nextInt();
           if (score == -1) {
               break;
           }
           countScores++;
           totalScore += score;
           // logic to find minimum and second minimum score
           if (score < minScore) {
               secondMinScore = minScore;
               minScore = score;
           } else if (score < secondMinScore && score != minScore)
               secondMinScore = score;

           if (score >= 90) {
               countScholarship++;
           }
           // logic to find maximum and second maximum score
           if (score > maxScore) {
               secondMaxScore = maxScore;
               maxScore = score;
           } else if (score > secondMaxScore && score < maxScore) {
               secondMaxScore = score;
           }

       }
       System.out.println("Result:");
       System.out.println("There are total " + countScores + " SCORES");
       System.out.println("The min SCORE is " + minScore);
       System.out.println("The max SCORE is " + maxScore);
       System.out.println("The 2nd min SCORE is " + secondMinScore);
       System.out.println("The 2nd max SCORE is " + secondMaxScore);
       System.out.println("The average SCORE after removing max/min SCORE is:"
               + (totalScore - (minScore + maxScore)) / (countScores - 2));
       System.out.println(
               "Total " + countScholarship + " scholarships will be given");
       input.close();

   }

}

Output:


Related Solutions

Write a C++ function called parse that reads one line of user input from the keyboard...
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input.  Your function should be passed the array and a reference variable that is to be assigned the length of the array.  Prompt the user and read the input from within the function. For example:  If the user inputs copy this that, the resulting array would have length 3 and contain the strings “copy”, “this”, and “that”....
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to...
Trying to complete this in Java. Application called 'Coffee Shop' that uses a while loop to build a customer order. The Coffee Shops sells: Coffee ($3.25), Espresso ($4.25), and Tea ($2.75). The coffee selection presents the customer with the choices of iced (no charge), cream (50 cents), and sugar (50 cents). The espresso selection presents the customer with choice of caramel (no charge) and chocolate (no charge) with one shot (no charge) or two shots ($1.25) of espresso. Once the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the...
IN JAVA!!! In this project, you will use radix.txt as the input file, and output the integers SORTED USING RADIX SORT. You may assume all your input consists of integers <=9999. Your main program will input the integers and put them into a QUEUE. It will then pass this queue to a method called radixSort which will sort the numbers in the queue, passing the sorted queue back to main. The main program will then call another method to print...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
Write a Java program that reads an input graph data from a user. Then, it should...
Write a Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number of vertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2 0...
JAVA: This is my code, but when it runs, for the "Average Score" output, it only...
JAVA: This is my code, but when it runs, for the "Average Score" output, it only gives me NaN. How can I fix that? import java.util.Scanner; public class prog4 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); String name; double score; double minScore = 0; double maxScore = 0; int numberOfRecords = 0; double sum = 0; double average = sum / numberOfRecords; System.out.printf("%-15s %-15s %-15s\n", "Student#", "Name", "Score");           while (reader.hasNext()) { name...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT