CS 160, Summer 2016
Programming Assignment P2
Grade Calculator
Programming due Monday, June 20 at 6:00pm; late deadline at 11:59 pm.
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:
- Declare and initialize the following variables of type double:
- assign0, assign1, assign2, assign3
- lab0, lab1, lab2
- exam0, exam1
- assignAverage, labAverage, examAverage
- classGrade
- Instantiate a Scanner object to read from the keyboard.
- Use System.out.print to display the prompt "First assignment: ".
- Use the Scanner to read a double value from the user into assign0.
- Repeat for the second, third, and fourth assignments, adjusting the prompts.
- Use System.out.print to display the prompt "First lab: ".
- Use the Scanner to read a double value from the user into lab0.
- Repeat for the second and third labs, adjusting the prompts.
- Use System.out.print to display the prompt "First exam: ".
- Use the Scanner to read a double value from the user into exam0.
- Repeat for the second exam, adjusting the prompt.
- Compute the average assignment score and assign to assignAverage.
- Compute the average lab score and assign to labAverage.
- Compute the average exam score and assign to examAverage.
- Compute the class grade based on the following formula:
class grade = (assignment average * 35%) + (lab average * 10%) + (exam average * 55%)
- Print the assignment average, as shown in the output below.
- Print the lab average, as shown in the output below.
- Print the exam average, as shown in the output below.
- Print the class total, as shown in the output below.
- All output should have exactly 2 digits after the decimal point. (HINT: use System.out.printf)
- 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.
Grading Criteria
- 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).
© 2016 CS160 Colorado State University. All Rights Reserved.