-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInClass8_FirstName_LastName.java
More file actions
57 lines (33 loc) · 1.63 KB
/
InClass8_FirstName_LastName.java
File metadata and controls
57 lines (33 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Name: [Enter Your Name Here]
* Date: [Enter Today's Date]
* Purpose: [Write program purpose here]
*
* In-Class Exercise: Practice calculating the average of grades using a while loop
* and sentinel value. This prepares you for the main lab where you'll calculate
* the geometric mean of processor speeds.
*/
// Import the Scanner class
public class InClass8_FirstName_LastName
{
public static void main(String[] args)
{
// Declare a Scanner object to accept keyboard input
// Declare a variable to hold the next grade entered by the user
// Declare a variable to hold the sum of all grades
// Hint: What should the initial value be for a sum?
// Declare a variable to hold the count (amount) of grades entered
// Hint: What should the initial value be for a count?
// Declare a variable to hold the final average
// Prompt the user to enter a grade or -1 to end
// Read the user's input and store it in your grade variable
// Write a while loop that continues as long as the grade is not -1
// Inside the loop, you should:
// 1. Add the grade to the sum
// 2. Increment the count
// 3. Prompt for and read the next grade
// After the loop ends, calculate the average
// Hint: Be careful with integer division! Cast to double if needed
// Display the average formatted to two decimal places
}
}