1 answer

ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will...

Question:

ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION

THANK YOU

Write a program GS.java that will be responsible for reading in the names and grades for a group of students, then reporting some statistics about those grades. The statistics to be gathered are the number of scores entered, the highest score and the name(s) of the student(s) who earned that score, the lowest score and the name(s) of the student(s) who earned that score, and the average score for the class.

So if the names and scores are as follows:

Jake 76

Meghan 99

Liu 34

Alice 99

Joshua 25

program would print output: There were 5 scores, averaging 66.6.

The lowest score was 25 by Penny.

The highest score was 99 by Hermione and Linus.

INSTRUCTIONS: The program will need loops in two places: (i) to be able to read in data repeatedly, and (ii) to ensure that any erroneous input is detected and re-read until a valid input is obtained. 

The program should read in names (single-word names are sufficient here) and scores until the name is entered as "done", at which time we stop reading names and scores and report the final statistics. 

All scores should be in a valid range 0 to 100. If a score is entered outside of that range, your program should issue an appropriate message and re-read only the score (not the name, we already know that!) until a valid score is entered. 

The program will need to keep track of a running total of the number of scores entered and the total number of points (to be used later to compute the average). 

The program will need to keep track of the highest (and lowest) score seen so far and the name(s) of the students who earned that highest (and lowest) score. 

Correct initialization of the variables you will use to keep track of high and low scores is essential to get this right. Note that the first score read in should become both the high and low score after the first time through the main loop. Think about how you can initialize those variables so that they will be set to the first score on the first loop iteration without treating that iteration as a special case (that is, the body of your loop does exactly the same thing on the first iteration as it will do on all subsequent iterations). 

Note that if there is a tie (among any number of students) for the highest and/or lowest score, all students who tied the high or low should have their name included in the printouts at the end. Hint: think string concatenation. 

If no valid names and scores are entered, a special message "You did not enter any scores!" should be printed rather than potentially erroneous stats. 

Prompt for and read in both the name (which you may still assume consists of a single word) and score (which you may assume is an integer) in one step. That is, issue one prompt, then have two calls to your Scanner: one to read the name, the next to read the score. If the name is read as done, then do not attempt to read any score given on that line (nor report any error if no such score is present on the input).

Note that all comparisons of String values should use the equals method, and any comparisons of numeric values should use== and !=. 

Define named constants to represent the highest possible score and the special name that is used to stop the loop. Those definitions should be the only places in the program where I see the int literal 100 or the String literal "done". 

Remember to take the proper precautions when computing your average (which should be a double) from the scores (which are all ints). When you print your average, use a DecimalFormat object to make sure it prints with exactly one digit after the decimal point.


Answers

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

  1. Created a class GS.java
  2. Defined constants to represent the maximum score and the termination word.
  3. Defined methods to read the name and score.
  4. Implemented a main method, initialized the required variables and set up a loop which will loop again and again until user inputs ‘done’, then the stats are displayed.
  5. Comments are included explaining every statements , If you have any doubts, feel free to ask, Thanks

//GS.java

import java.text.DecimalFormat;

import java.util.Scanner;

public class GS {

      static final int MAX_SCORE = 100;

      static final String NAME_TO_END = "done";

      static Scanner scanner;

      public static void main(String[] args) {

            /**

            * Initializing scanner object

            */

            scanner = new Scanner(System.in);

            /**

            * initializing variables required for running the program

            */

            String highscorer = null, lowscorer = null, name = "";

            double highscore = 0, lowscore = 0, score = 0;

            double totalScore = 0;

            int numberOfEntries = 0;

            boolean firstEntry = true; /* to denote if any scores are added or not */

            /**

            * Loops until 'done' is entered

            */

            do {

                  name = readName();

                  if (!name.equalsIgnoreCase(NAME_TO_END)) {

                        score = readScore();

                        if (firstEntry) {

                              /**

                              * In the first input, both high and low scores are the

                              * same, by the same person

                              */

                              highscorer = name;

                              lowscorer = name;

                              highscore = score;

                              lowscore = score;

                              firstEntry = false; /*

                                                            * one input is added, so any further

                                                            * inputs are not considered as first

                                                            * entry

                                                            */

                        } else {

                              if (score < lowscore) {

                                    /**

                                    * new low score

                                    */

                                    lowscore = score;

                                    lowscorer = name;

                              } else if (score == lowscore) {

                                    /**

                                    * another person with same lowest score

                                    */

                                    lowscorer += " and " + name;

                              }

                              if (score > highscore) {

                                    /**

                                    * new high score

                                    */

                                    highscore = score;

                                    highscorer = name;

                              } else if (score == highscore) {

                                    /**

                                    * another person with same highest score

                                    */

                                    highscorer += " and " + name;

                              }

                        }

                        /**

                        * Adding to the total score, and incrementing the number of

                        * entries to calculate average

                        */

                        totalScore += score;

                        numberOfEntries++;

                  } else {

                        if (firstEntry) {

                              /**

                              * No inputs are added

                              */

                              System.out.println("You did not enter any scores!");

                        } else {

                              double average = (double) totalScore / numberOfEntries;

                              /**

                              * Formatter to format the average to maximum of one digit after point

                              */

                              DecimalFormat decimalFormat = new DecimalFormat("#.#");

                              System.out.println("There were " + numberOfEntries

                                          + " scores, averaging "

                                          + decimalFormat.format(average));

                              System.out.println("The lowest score was " + lowscore

                                          + " by " + lowscorer);

                              System.out.println("The highest score was " + highscore

                                          + " by " + highscorer);

                        }

                  }

            } while (!name.equalsIgnoreCase(NAME_TO_END));

      }

      /**

      * method to read and return the name

      */

      static String readName() {

            String name = "";

            System.out.println("Enter name (or 'done' to stop): ");

            name = scanner.nextLine();

            return name;

      }

      /**

      * method to read and return the score will ask repetitively in case of

      * invalid input

      */

      static double readScore() {

            double score = 0;

            System.out.println("Enter score (0-100):");

            try {

                  score = Double.parseDouble(scanner.nextLine());

                  if (score < 0 || score > MAX_SCORE) {

                        System.out.println("Score should be between 0-100");

                        return readScore();

                  }

                  return score;

            } catch (Exception e) {

                  System.out.println("Invalid input, try again");

                  return readScore();

            }

      }

}

/*OUTPUT*/

Enter name (or 'done' to stop):

Jake

Enter score (0-100):

600

Score should be between 0-100

Enter score (0-100):

76

Enter name (or 'done' to stop):

Meghan

Enter score (0-100):

99

Enter name (or 'done' to stop):

Liu

Enter score (0-100):

300

Score should be between 0-100

Enter score (0-100):

234

Score should be between 0-100

Enter score (0-100):

34

Enter name (or 'done' to stop):

Alice

Enter score (0-100):

99

Enter name (or 'done' to stop):

Joshua

Enter score (0-100):

25

Enter name (or 'done' to stop):

done

There were 5 scores, averaging 66.6

The lowest score was 25.0 by Joshua

The highest score was 99.0 by Meghan and Alice

.

Similar Solved Questions

1 answer
How do I do this integral? #int sin^3x cos^2x dx#
I tried to do it with half-angle formulas and got #1/4cosx - 1/16sin4x#, but it wasn't right... The book gives an answer of #cos^5x/5 - cos^3x/3 + C#....
1 answer
What is the production philosophy of Under Armour company?
what is the production philosophy of Under Armour company?...
1 answer
How do you write 6.7 in scientific notation?
How do you write 6.7 in scientific notation?...
1 answer
Where should policy writers look to find supporting material when developing the policies for their organization?
Where should policy writers look to find supporting material when developing the policies for their organization?...
1 answer
Units Manufactured 100 Direct Materials (in $'s): Total Cost for Your Direct Material Number 1 Total...
Units Manufactured 100 Direct Materials (in $'s): Total Cost for Your Direct Material Number 1 Total Cost for Your Direct Material Number 2 Total Cost for Your Direct Material Number 3 Total Direct Materials (in $'s) 11,616 6,970 4,646 23,232 Direct Labor (in $'s) 16,616 Variable Factory...
1 answer
Which of the following statements about the steady state approximation is/are correct? The change of intermediate...
Which of the following statements about the steady state approximation is/are correct? The change of intermediate concentration with time is negligible. II. The concentration of the intermediate is assumed zero. III. The rate of intermediate increases initially then reach a plateau. I....
1 answer
A civil engineer conducted a study to compare the compressive strength of concrete obtained using four...
A civil engineer conducted a study to compare the compressive strength of concrete obtained using four different aggregates. The results of his experiment are given in the dataset file. a) Does there seem to be differences between the average strengths of concrete with different aggregates? Use ?=0....
1 answer
Given the mass of a particular gas and the molar mass of the atoms or molecules...
Given the mass of a particular gas and the molar mass of the atoms or molecules in the gas, how do you find the number of moles? Divide the molar mass by the mass of the gas. OR Multiply the mass of the gas by the molar mass. OR Divide the mass of the gas by the molar mass....
1 answer
1. S2.1.04 Clancy, the owner of Clancy Farms, can produce up to 1300 barrels of corn...
1. S2.1.04 Clancy, the owner of Clancy Farms, can produce up to 1300 barrels of corn on his farm. His seasonal cost is C(q) = 550+ 804-0.0292 When q barrels of corn are sold to the market, his seasonal revenue is 127q-0.04q2 Determine the marginal revenue and marginal cost at q = 940 MC(940) - MR(94...
1 answer
Which of the following hormones would be expected to increase after an individual consumes a meal...
Which of the following hormones would be expected to increase after an individual consumes a meal high in calcium? Calcitonin Insulin Endorphins Parathyroid hormone....
1 answer
0.4. Suppose that Yi and Y2 are discrete independent random variables with the following moment generating...
0.4. Suppose that Yi and Y2 are discrete independent random variables with the following moment generating functions: 6 10 102 I. Find the mean and variance of Yi 1-...
1 answer
17. Two runners start running in the same direction at the same instant, t- 0.00. Runner...
17. Two runners start running in the same direction at the same instant, t- 0.00. Runner A starts from a point that is 20.0 meters in front of runner B. Runner A starts with and maintains a constant acceleration of 2.00 m/s for 3.00 seconds, and then runs at a constant velocity. Runner B starts with...
1 answer
Dylan paid $640 for a new refrigerator he placed in service in his rental house in...
Dylan paid $640 for a new refrigerator he placed in service in his rental house in May 2018. He did not take the special depreciation allowance and is depreciating the refrigerator using regular MACRS and the half-year convention. Dylan sold the rental house with the refrigerator in March 2019. How ...
2 answers
Centre Of Mass
from the base of a hemisphere a right cone of height R/2 and same base has been scooped out.Find the centre of mass of the remaining part....
1 answer
Name the corresponding part if polygon WXYZ polygon PQRS
Name the corresponding part if polygon WXYZ polygon PQRS.YZ =...
1 answer
Question 1 -- / 10 What should a company consider if it is thinking of changing...
Question 1 -- / 10 What should a company consider if it is thinking of changing prices? Type your answer Question 2 -- / 10 Briefly outline the main sections of a marketing plan. Type your answer Question 3 -- / 10 A situation analysis includes a discussion of customers. What should be included here...
1 answer
Experiment 1 Consider the open-loop system, modelled as V (s) 6(s) GM(s) where GM(s) is given by ...
Experiment 1 Consider the open-loop system, modelled as V (s) 6(s) GM(s) where GM(s) is given by equation7 In this experiment, we will find the responise and investigate the characteristics of this open-loop system. a) Write instructions to create the ILTI (linear time-invariant) transfer function r...
1 answer
0/0.1 pts Question 10 Suppose that the number of matches in the labor market is given...
0/0.1 pts Question 10 Suppose that the number of matches in the labor market is given by V0.25. U0.75 М What is the job-finding rate when labor market tightness is 0.5? 84...