# CS 160, Summer 2016 Programming Assignment P2 Grade Calculator

## Objectives

This programming assignment has the goal to help you further understand the Java Scanner class for input, and to practice some simple arithmetic expressions.

### Description

This program requires the user to input 4 assignment scores, 3 lab scores, and 2 exam scores. After data entry, the program computes the average score for each category, and the class grade, which is a weighted average described below.

### Instructions

For this assignment, you must follow directions exactly. Create a P2 project in Eclipse then write a class P2 with a main method, and put all of the following code into the main method:
1. Declare and initialize the following variables of type double:
• assign0, assign1, assign2, assign3
• lab0, lab1, lab2
• exam0, exam1
• assignAverage, labAverage, examAverage
2. Instantiate a Scanner object to read from the keyboard.
3. Use System.out.print to display the prompt "First assignment: ".
4. Use the Scanner to read a double value from the user into assign0.
5. Repeat for the second, third, and fourth assignments, adjusting the prompts.
6. Use System.out.print to display the prompt "First lab: ".
7. Use the Scanner to read a double value from the user into lab0.
8. Repeat for the second and third labs, adjusting the prompts.
9. Use System.out.print to display the prompt "First exam: ".
10. Use the Scanner to read a double value from the user into exam0.
11. Repeat for the second exam, adjusting the prompt.
12. Compute the average assignment score and assign to assignAverage.
13. Compute the average lab score and assign to labAverage.
14. Compute the average exam score and assign to examAverage.
15. Compute the class grade based on the following formula:
```      class grade = (assignment average * 35%) + (lab average * 10%) + (exam average * 55%)
```
16. Print the assignment average, as shown in the output below.
17. Print the lab average, as shown in the output below.
18. Print the exam average, as shown in the output below.
19. Print the class total, as shown in the output below.
20. All output should have exactly 2 digits after the decimal point. (HINT: use System.out.printf)
21. Do not hard code anything, we will use different input values than those shown. You should also test your program on a range of different values. Use a calculator to check your answers.

### Sample output

Your program's output should match the example shown below, user input is shown in blue:
```  First assignment: 11
Second assignment: 22
Third assignment: 33
Fourth assignment: 44
First lab: 44
Second lab: 55
Third lab: 66
First exam: 88
Second exam: 99
Assignment average: 27.50
Lab average: 55.00
Exam average: 93.50
Class total: 66.55
```

### Specifications

Your program must meet the following specifications:
• Work on your own, as always.
• The name of the source code file must be exactly P2.java.
• Name the file exactly - upper and lower case matters!
• Comments at the top as shown in P1.
• Assignments should be implemented using Eclipse and Java 1.5 or 1.6 or 1.7 or 1.8.
• Make sure your code runs on machines in the COMSC 120 lab.
• Submit your program to the Checkin tab as you were shown in the recitation.
• Read the syllabus for the late policy.

• 100 points for perfect submission.
• 0 points for no submission, will not compile, submitted class file, etc.
• Preliminary Tests
• testCompile: checks that program compiles. (0 points)
• test1: checks the input of assignment scores. (10 points)
• test2: checks the input of lab scores. (10 points)
• test3: checks the input of exam scores. (10 points)
• test4: checks the calculation and output of the assignment average. (10 points)
• test5: checks the calculation and output of the lab average. (10 points)
• Preliminary testing uses the values shown above.
• Final Tests
• test6: checks the calculation and output of the exam average. (10 points)
• test7: checks the calculation and output of the class total, using the values shown. (10 points)
• test8: checks the assignment, lab, and exam averages using our own data. (15 points)
• test9: checks the calculation and output of the class total, using our own data. (15 points)
• Final testing includes the preliminary testing.
Submit your program to the Checkin tab on the course website, as you were shown in the recitation, and read the syllabus for the late policy (if necessary).