Question

In: Computer Science

In JAVA • Write a program that calculates the average of a group of test scores,...

In JAVA

• Write a program that calculates the average of a group of test scores, where the
lowest score in the group is dropped. It should use the following methods:
• int getScore() should ask the user for a test score, store it in a reference
parameter variable, and validate it. This method should be called by main once
for each of the five scores to be entered.
• void calcAverage() should calculate and display the average of the four highest scores.

This method should be called just once by main, and should be passed
the five scores.
• int findLowest() should find and return the lowest of the five scores passed to it.
It should be called by calcAverage, which uses the method to determine one of
the five scores to drop.
The program should display a letter grade for each score and the average test
score.
Input Validation: Do not accept test scores lower than 0 or higher than 100.

*******(use random numbers 50-100. Don't ask the user to enter data)
********Show all test scores, the one that got dropped and the average.

*******For random numbers, use the Random class not Math.random()

Solutions

Expert Solution

Program:

import java.util.Scanner;

public class Main
{
public static double calcAvearge(int[] array)
{
int toDrop = findLowest(array);
int sum = 0;
for(int i=0;i<5;i++)
{
if(array[i]!=toDrop)
{
sum =sum + array[i];
  
}
}
  
return (double)sum/4;
}
  
public static int findLowest(int[] arr)
{
int lowest = arr[0];
for(int i=0;i<5;i++)
{
if(arr[i]<lowest)
{
lowest = arr[i];
}
}
  
return lowest;
}
  
public static int getScore()
{
Scanner s = new Scanner(System.in);
System.out.print("Enter score: ");
int userScore = s.nextInt();
return userScore;
}
  
   public static void main(String[] args) {
   double avg;
   int lowest;
   int[] score = new int[5];
   for(int i=0;i<5;i++)
   {
   while(true)
   {
   int value = getScore();
   if(value>0 && value<100)
   {
   score[i] = value;
   break;
   }
   else
   {
   System.out.println("Invalid score, Enter again.");
   continue;
   }
   }
  
   }
  
   avg = calcAvearge(score);
   System.out.println();
   for(int i=0;i<5;i++)
   {
   System.out.println();
   System.out.print("Score "+ score[i] +" and grade is: ");
   if(score[i]>=90)
   {
   System.out.print("A");
   }
   else if(score[i]>=80 && score[i]<=89)
   {
   System.out.print("B");
   }
   else if(score[i]>=70 && score[i]<=79)
   {
   System.out.print("C");
   }
   else if(score[i]>=60 && score[i]<=69)
   {
   System.out.print("D");
   }
   else
   {
System.out.print("E");  
   }
   }
  
   System.out.println();
   System.out.println("Average score is: "+ avg);
   }
}

Output:


Related Solutions

Write a program that calculates the average of a group of test scores, where the lowest...
Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage() should calculate and display the average of the four highest scores. This function...
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
Question 2: Write a java program that calculates the weighted average of three grades using the...
Question 2: Write a java program that calculates the weighted average of three grades using the method with header public static double CalculateWeightedAverage (double grade1, double grade2, double grade3), such that: [4 Marks] Weighted average = grade1 * 0.5 + grade2 * 0.25 + grade3 * 0.25 The program in the main method will: o ask the user to enter the three grades o and then call the method that will calculate the weighted average o and finally display the...
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...
Write a program that will find the class average of fifteen (15) test scores for five...
Write a program that will find the class average of fifteen (15) test scores for five (5) different tests. The class average must be stored into an integer array. You are to have three separate arrays: Note: _jd represents the initials of the programmer. Your array and function names should be named by replace the initials jd with your first and last initials Arrays Student Names Scores Averages Name of array students_jd scores_jd averages_jd Size of array [15][10] [15][5] .[5]...
(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...
Create a C++ program which will accept an unlimited number of scores and calculates the average...
Create a C++ program which will accept an unlimited number of scores and calculates the average score. You will also need to prompt for the total points possible. Assume each test is worth 100 points. Requirements. • Enter the Student ID first, then prompt for grades. Keep prompt- ing for grades until the client enters ’calc’. That triggers final pro- cessing. • Make your code as reliable as possible. • Make your program output easy to read. • You cannot...
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel....
IN JAVA Write a program that calculates the occupancy rate for each floor of a hotel. (Use a sentinel value and please point out the sentinel in bold.) The program should start by asking for the number of floors in the hotel. A loop should then iterate once for each floor. During each iteration, the loop should ask the user for the number of rooms on the floor and the number of them that are occupied. After all the iterations,...
Write a java program that calculates a speeding fine. The user is prompted for the speed...
Write a java program that calculates a speeding fine. The user is prompted for the speed of the vehicle, the posted speed limit and if the offence took place in the construction zone. The fine is calculated at $75 + 3$/ km over the speed limit for the first 20km over + $6 / km for the next 20 and $9/km after that. If the posted limit is 40km, the fine is doubled. If the offence took place in a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT