Question

Implement a Java program using simple console input & output and logical control structures such that...

Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks

  • For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”.
  • After the 5 integer scores have been entered, the program counts the total number of passes as well as the total number of failures and prints those 2 count values with appropriate messages like “Total number of passes is: <count value1>” &  “Total number of failures is: <count value2>”.
  • After the 5 integer scores have been entered, the program finds the highest score as well as the lowest score and prints those 2 values with appropriate messages like “Highest score is: <value1>” &  “Lowest score is: <value2>”.
  • The program checks whether an input score is a number between 0 - 100 or not. If the input score value is otherwise or outside the above range, then it prints the error message saying “Invalid score” and prompts the user for a valid input.

import java.util.ArrayList;
import java.util.Scanner;

public class Problem3 {

       public static void main(String[] args)
       {

           int number;
          
           Scanner scanner = new Scanner(System.in);
          
           System.out.println("Enter each of the 5 scores as an integer between 0 and 100.");
           ArrayList<Integer> scoreList = new ArrayList<Integer>();   //Create ArrayList to store scores in
          
           //Prompt the user to enter 5 integer scores and puts them in an ArrayList
  

       }


   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

import java.util.ArrayList;
import java.util.Scanner;

public class Problem3 {

public static void main(String[] args)
{

int number;
  
Scanner scanner = new Scanner(System.in);
  
System.out.println("Enter each of the 5 scores as an integer between 0 and 100.");
ArrayList<Integer> scoreList = new ArrayList<Integer>(); //Create ArrayList to store scores in
  
//Prompt the user to enter 5 integer scores and puts them in an ArrayList
int ct1=0,ct2=0;
for(int i=0;i<5;i++)
{
System.out.print("Enter a score: ");
  
number=scanner.nextInt();
while(number<0||number>100)
{
System.out.println("Invalid score: ");
  
System.out.print("Enter a score: ");
  
number=scanner.nextInt();
}
scoreList.add(number);
if(number<60)
{
System.out.println("FAIL");
ct1++;
  
}
else
{
System.out.println("PASS");
ct2++;
}
}
int low=scoreList.get(0),high=scoreList.get(0);
for(int i=0;i<5;i++)
{
if(low>scoreList.get(i))
low=scoreList.get(i);
if(high<scoreList.get(i))
high=scoreList.get(i);
  
}
System.out.println("Total number of passes is: "+ct2);
System.out.println("Total number of failures is: "+ct1);
System.out.println("Highest score is: "+high);
System.out.println("Lowest score is: "+low);
  
}


}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Implement a Java program using simple console input & output and logical control structures such that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • In this lab, you complete a partially written Java program that includes methods that require multiple...

    In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • (Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber...

    (Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber from the use and will returs whether the eatered number is even or odd. For user input you can use JOptionlPane or Scanner (Pts 3) OR Qu.6 Write a java program which will allow user to enter the marks. If entered marks are mone tha 60 then program should print pass otherwise fail. For user input you can use JOptionPane O Scanner Pts 3)...

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • In Java Main method Your main program will prompt the user for a test name and...

    In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...

  • Write a JAVA program that prompts the user for student grades and displays the highest and...

    Write a JAVA program that prompts the user for student grades and displays the highest and lowest grades in the class. The user should enter a character to stop providing values. Starter code: import java.util.Scanner; public class MaxMinGrades{   public static void main(String[] args){     Scanner input = new Scanner(System.in);     System.out.println("Enter as many student grades as you like. Enter a character to stop.");     double grade = input.nextDouble();     double minGrade = Double.MAX_VALUE;     double maxGrade = Double.MIN_VALUE;     while (Character.isDigit(grade)) {       if (grade == 0)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT