This is an individual homework assignment. You may receive help from other class
ID: 3586116 • Letter: T
Question
This is an individual homework assignment. You may receive help from other class mates, but you may NOT copy their work. Copied work will be considered plagiarism and dealt with according to the syllabus and university policy Objective: For this assignment, you will demonstrate that you can properly manipulate Java's built-in Scanner class, perform a variety of mathematical operations and data type conversions while using appropriate flow control and logical processing keywords to create a simple averaging program. grade Description: The ability to record user input and manipulate it mathematically is a frequent task in business computing. Business programmers often do not know ahead of time how much data will be entered by the user, therefore a frequently used skill is the ability to use flow control and to allow the user to enter however much data they need and to then signal the program to calculate by entering a special signal value. For this assignment, you will create a program that accepts an arbitrary number of grades (integer values) from the end user and when the user inputs the signal value (e.g. 999) to compute the average score and then also provide the letter grade associated with the computed average. Assignment: Create a command-line Java class that performs the following: Accepts an arbitrary number of grades from the user until the user enters a special signal value (e.g. 999) o You must use the Scanner class and read the values as a proper data type with an appropriate prompt Helpful tip: You should first check each entry to determine if the user entered the special signal value, if so make sure not to include the signal value into the calculated average . .Helpful tip: One way to solve this problem is to use a running tally which is simply the total of all values entered by the user, you may also find it helpful to maintain a counter that keeps track of how many times the loop has executed indicating how many grades the user has entered The final grade can then be calculated as the nming tally divided by the counter, make sure to provide this result as a decimal value " Helpful tip: Refer to pages 231 & 232 in your text for an example that is · very similar to portions of this assignment Once the user has entered the special signal value: o Correctly calculate the average of all entered grades as a decimal value Output this average to the user Output the appropriate letter grade associated with the average to the user " . See Table 1 below for example prompts, user interaction and output Upload your JAVA code file(s) to the appropriate Blackboard assignmentExplanation / Answer
Given below is the code for the question . The table 1 mentioned in the question is not uploaded. So I have assumed the following grades
> =90 - Grade A
>=80 and < 90 - Grade B
>= 70 and < 80, grade C
>= 60 and < 70 grade D
below 60 , grade F
You many change it according to the table (which is not given in question). If you need help post a comment , I will help. If the answer helped, please don't forget to rate it. Thank you.
import java.util.Scanner;
public class CalculateGrade {
public static void main(String[] args) {
Scanner keybd = new Scanner(System.in);//keyboard
int score;
double total = 0; //use double for type to avoid integer division
int n = 0;
double avg;
char grade;
do
{
System.out.print("Enter a grade (type 999 to stop): ");
score = keybd.nextInt();
if(score != 999) //add it to score only if its not the special value
{
total += score;
n++;
}
}while(score != 999);
avg = total / n;
if(avg >= 90)
grade = 'A';
else if(avg >= 80)
grade = 'B';
else if(avg >= 70)
grade = 'C';
else if(avg >= 60)
grade = 'D';
else
grade = 'F';
System.out.println("No. of scores input: " + n);
System.out.printf("Average: %.2f ", avg);
System.out.println("Grade: " + grade);
}
}
output
Enter a grade (type 999 to stop): 89
Enter a grade (type 999 to stop): 87
Enter a grade (type 999 to stop): 77
Enter a grade (type 999 to stop): 80
Enter a grade (type 999 to stop): 999
No. of scores input: 4
Average: 83.25
Grade: B
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.