Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

DESCRIPTION Objectives To convert a simple program from Scala to Java To use basic data types to store information To get user input to acquire

DESCRIPTION
Objectives
To convert a simple program from Scala to Java
To use basic data types to store information
To get user input to acquire information
To present stored information to the user as output
To use simple expressions to manipulate information
To use conditionals to change behavior based on information
To use while loops to repeat behavior (perform basic iteration)
Description
Write a program (LetterGrades.java) that takes a list of grades and determines the number of grades that are As, Bs, Cs, Ds, and Fs. In this problem, we will assume a grade g is an A if g 90, that is greater than or equal to 90, a B if 90 > g 80, a C if 80 > g 70, a D if 70 > g 60, and an F if g < 60.
The program should start by prompting the user with, "How many grades are there?" It should then read in the number of grades N and print out the message: "Please enter all N grades. One per line." where N is replaced with the value entered by the user. The program should then proceed to read in N grades, and for each grade determine what letter grade it is and track the total for the letter grade. After all of the N grades have been entered, the program should output how many of each letter grade were entered, in the form as described below in the sample running.
Sample Run
The following is a sample run. It includes both input and output. For clarity, the input lines are preceded by the symbol >. The input and output are separated afterwards.
How many grades are there?
> 10
Please enter all 10 grades. One per line.
> 65
> 82
> 95
> 73
> 43
> 50
> 90
> 110
> 2
> 86
A: 3
B: 2
C: 1
D: 1
F: 3
Input
Here is just the sample input to the program.
10
65
82
95
73
43
50
90
110
2
86
Output
Here is just the sample output to the program. Notice that the prompts are part of the program's output.
How many grades are there?
Please enter all 10 grades. One per line.
A: 3
B: 2
C: 1
D: 1
F: 3
Hint
To solve this problem you might want to do this incrementally in stages. For example,
Start by reading in a single grade and printing out if it is an A, B, ...
Then have the program start by reading in a value N and reading in N grades. You will want to use a loop (while or do-while).
Then have the program count the number of As read in (and print it out once the N grades have been read).
Then have the program count the number of Bs, and then Cs, etc.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions