Question

In: Computer Science

I have entered this line of code for exercise 6-8 saying to Write an application that...

I have entered this line of code for exercise 6-8 saying to 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. I only have 96%. done with one result missing saying that the score must be between 10 and 0 even though i see that its there, what do i need to change if anything?

import java.util.*;

public class QuizScoreStatistics {

   public static void main(String[] args) {

       int quizScore = 0, validScores = 0;

       int highestScore = 0;

       int lowestScore = 10;

   double sum =0, average=0.0;

   Scanner scan = new Scanner(System.in);

   do {

       //prompt & read score from user

       System.out.print("Enter the quiz score : ");

       quizScore = scan.nextInt();

     

       if(quizScore == 99)

           break;

     

       if(quizScore<0 || quizScore>10) {

           System.out.println("Score must must be between 10 and 0: ");

       }

       else {

           //Calculate sum of quiz score

           sum += quizScore;

           //Increment valid score counter

           validScores++;

           //Determine highest score

           if(quizScore > highestScore)

               highestScore = quizScore;

           //Determine lowest score

           if(quizScore < lowestScore)

               lowestScore = quizScore;

       }

     

   }while(true);

   //calculating the average

   average = sum / validScores;  

   //Printing the results

   System.out.println("Number of valid scores: " + validScores);

   System.out.println("Highest Score: " + highestScore);

   System.out.println("Lowest Score: " + lowestScore);

   System.out.println("Arithmetic average: " + String.format("%.2f", average));

   }

}

Solutions

Expert Solution

The given program works perfectly and found no error.But in quiz score validation,the out put message is "Score must must be between 10 and 0: ". The word "must" is repeated and there is a colon also.Please eliminate the repeated word and the colon(:).The correct statement would be System.out.println("Score must be between 10 and 0"); .Please try this change,the problem will be solved.If find any difficulty,feel free to ask in comment section.Please do upvote the answer.Thank you.

Source code with small correction

import java.util.Scanner;
public class QuizScoreStatistics {
    public static void main(String[] args) {
        int quizScore = 0, validScores = 0;
        int highestScore = 0;
        int lowestScore = 10;
        double sum =0, average=0.0;
        Scanner scan = new Scanner(System.in);
        do {
            //prompt & read score from user
            System.out.print("Enter the quiz score : ");
            quizScore = scan.nextInt();
            if(quizScore == 99)
                break;
            if(quizScore<0 || quizScore>10) {
                System.out.println("Score must be between 10 and 0");
            }
            else {
                //Calculate sum of quiz score
                sum += quizScore;
                //Increment valid score counter
                validScores++;
                //Determine highest score
                if(quizScore > highestScore)
                    highestScore = quizScore;
                //Determine lowest score
                if(quizScore < lowestScore)
                    lowestScore = quizScore;
            }
        }while(true);
        //calculating the average
        average = sum / validScores;
        //Printing the results
        System.out.println("Number of valid scores: " + validScores);
        System.out.println("Highest Score: " + highestScore);
        System.out.println("Lowest Score: " + lowestScore);
        System.out.println("Arithmetic average: " + String.format("%.2f", average));
    }
}

Screen shot of the output


Related Solutions

Write a Java application that accepts a bar code as a command line parameter and prints...
Write a Java application that accepts a bar code as a command line parameter and prints out the ZIP code. Assume that the bar code uses the symbols "|" and ":" for the long and short bars, respectively. Provide warnings on errors in the bar code specifying what exactly is wrong. The bar code input should be in the format specified in Problem 1, including the pair of the full bars at the beginning and at the end. Important: The...
I need from 6 to 8 line What is interoperability as used in the EHR and...
I need from 6 to 8 line What is interoperability as used in the EHR and what is its importance?
Write a Java application that prompts the user for an age. If the age entered is...
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in...
C# I need working code please Write a console application that accepts the following JSON as...
C# I need working code please Write a console application that accepts the following JSON as input: {"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "ZoomIn", "label": "Zoom In"}, {"id": "ZoomOut", "label": "Zoom Out"}, {"id": "OriginalView", "label": "Original View"}, null, {"id": "Quality"}, {"id": "Pause"}, {"id": "Mute"}, null, {"id": "Find", "label": "Find..."}, {"id": "FindAgain", "label": "Find Again"}, {"id": "Copy"}, {"id": "CopyAgain", "label": "Copy Again"}, {"id": "CopySVG", "label": "Copy SVG"}, {"id": "ViewSVG", "label": "View...
I am trying to write the code for an 8 bit adder in VHDL so that...
I am trying to write the code for an 8 bit adder in VHDL so that I can program it onto my Elbert V2 Spartan 3A FPGA Development Board, but I keep getting errors. Any ideas what I am doing wrong? library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity adder8bit is Port ( a : in STD_LOGIC_VECTOR(7 downto 0); b : in STD_LOGIC_VECTOR(7 downto 0); cin : in STD_LOGIC; o : out STD_LOGIC_VECTOR(7 downto 0); cout : out STD_LOGIC); end adder8bit; architecture Behavioral...
Matlab code problems I have to write a code using functions to find out if a...
Matlab code problems I have to write a code using functions to find out if a year is a leap year. I'm on the write track i feel like but I keep getting an error message and matlab isnt helping to troubleshoot. The issue is on line 30. Here is my code: function project_7_mfp() %   PROJECT_7_ABC   project_7_abc() creates a function that prompts the user %   enter a year after 1582 It then determines if it is a leap year %...
Do you have a sample of Business Improvement plan? Any tips? I need to write 6-8...
Do you have a sample of Business Improvement plan? Any tips? I need to write 6-8 pages Improvement plan for Kodak company?
*Please write code in C++* Write a program to verify the validity of the user entered...
*Please write code in C++* Write a program to verify the validity of the user entered email address.   if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid" else : output the statement that the email is invalid and list all the violations ex:  "The email sarahwinchester.com is invalid" * @ symbol * Missing Domain name The program should keep validating emails until user enter 'q' Upload your source code. ex: main.cpp
please, I need 7-8 meaningful sentences as an answer ( reply saying how i liked the...
please, I need 7-8 meaningful sentences as an answer ( reply saying how i liked the post or adding some details to it) to this post. I would really appreciate it ACTIVITY BASED COSTING AND ANALYSIS Because overhead cannot be applied to the units of production in the same manner that direct labor and direct materials can, we assign overhead costs by using one of three allocation methods. The three different methods of assigning overhead costs are a single plantwide...
write a c++ code for following application You have been hired by XYZ Car Rental to...
write a c++ code for following application You have been hired by XYZ Car Rental to develop a software system for their business. Your program will have two unordered lists, one of Cars and one of Reservations. The Car class will have the following data: string plateNumber (this is the key) string make string model enum vehicleType (VehicleType Enumeration of options: sedan, suv, exotic) double pricePerDay bool isAvailable isAvailable should be set to true on initialization, and a public setter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT