Presentation is loading. Please wait.

Presentation is loading. Please wait.

The 3 rd and 4 th tutoring session -- A case study about using variables Fall, 2012 Haidong(Haydon) Xue 5:30pm8:30pm 9/11/2012 and 9/12/2012.

Similar presentations


Presentation on theme: "The 3 rd and 4 th tutoring session -- A case study about using variables Fall, 2012 Haidong(Haydon) Xue 5:30pm8:30pm 9/11/2012 and 9/12/2012."— Presentation transcript:

1 The 3 rd and 4 th tutoring session -- A case study about using variables Fall, 2012 Haidong(Haydon) Xue 5:30pm8:30pm 9/11/2012 and 9/12/2012

2 CSc2310 Tutoring Time: 5:30pm-8:30pm Tutor: Haidong Xue (You can call me Haydon) There are 2 sections: 1. Review 5:30pm – 6:30pm A case study, and make a program for this case. 2. Q&A If you have any questions about Java programming, I am right here

3 Computing a course average -- Overview The CourseAverage program will calculate a class average, using the following percentages: Programs30% // 8 programs Quizzes10% // 5 quizzes Test 115% Test 215% Final exam30% courseAverage =.30 programAverage quizAverage test test finalExam The user will enter the grade for each program (0–20), the score on each quiz (0–10), and the grades on the two tests and the final (0–100). There will be eight programs and five quizzes.

4 Computing a course average – A legal output Welcome to the CSc2310 average calculation program. Enter program 1 score (0-20):20 Enter program 2 score (0-20):20 Enter program 3 score (0-20):20 Enter program 4 score (0-20):20 Enter program 5 score (0-20):20 Enter program 6 score (0-20):20 Enter program 7 score (0-20):20 Enter program 8 score (0-20):20 Enter quiz 1 score (0-10):10 Enter quiz 2 score (0-10):10 Enter quiz 3 score (0-10):10 Enter quiz 4 score (0-10):10 Enter quiz 5 score (0-10):10 Enter test 1 score (0-100):100 Enter test 2 score (0-100):100 Enter final exam score (0-100):100 The final grade is: 100 (Users inputs are in red font)

5 Computing a course average – What should we finish for it?

6 1. Print the introductory message ("Welcome to the CSc 2310 average calculation program"). 2. Prompt the user to enter eight program scores. 3. Compute the program average from the eight scores. 4. Prompt the user to enter five quiz scores. 5. Compute the quiz average from the five scores. 6. Prompt the user to enter scores on the tests and final exam. 7. Compute the course average from the program average, quiz average, test scores, and final exam score. 8. Round the course average to the nearest integer and display it.

7 Lets code it step by step! Please get your Eclipse ready Create a class named CourseAverage with main method If you are not very confident, please download and open this code first (it is the finished program): /CourseAverage.java

8 Lets code it step by step! 1. Print the introductory message ("Welcome to the CSc 2310 average calculation program"). Code:

9 Lets code it step by step! 1. Print the introductory message ("Welcome to the CSc 2310 average calculation program"). Code: // Print the introductory message System.out.println("Welcome to the CSc2310 average calculation program.");

10 Lets code it step by step! 2. Prompt the user to enter eight program scores. Code:

11 Lets code it step by step! 2. Prompt the user to enter eight program scores. Code: // Create a Scanner Scanner s = new Scanner(System.in); // Collect 8 program scores System.out.print("Enter program 1 score (0-20):"); double program1 = s.nextDouble(); System.out.print("Enter program 2 score (0-20):"); double program2 = s.nextDouble();

12 System.out.print("Enter program 3 score (0-20):"); double program3 = s.nextDouble(); System.out.print("Enter program 4 score (0-20):"); double program4 = s.nextDouble(); System.out.print("Enter program 5 score (0-20):"); double program5 = s.nextDouble(); System.out.print("Enter program 6 score (0-20):"); double program6 = s.nextDouble(); System.out.print("Enter program 7 score (0-20):"); double program7 = s.nextDouble(); System.out.print("Enter program 8 score (0-20):"); double program8 = s.nextDouble();

13 Lets code it step by step! 3. Compute the program average from the eight scores. Code:

14 Lets code it step by step! 3. Compute the program average from the eight scores. Code: // Calculate the average program score double programAverage = (program1 + program2 + program3 + program4 + program5 + program6 + program7 + program8)/8;

15 Lets code it step by step! 4. Prompt the user to enter five quiz scores. Code:

16 Lets code it step by step! 4. Prompt the user to enter five quiz scores. Code: // Collect 5 quiz scores System.out.print("Enter quiz 1 score (0-10):"); double quiz1 = s.nextDouble(); System.out.print("Enter quiz 2 score (0-10):"); double quiz2 = s.nextDouble(); System.out.print("Enter quiz 3 score (0-10):"); double quiz3 = s.nextDouble(); System.out.print("Enter quiz 4 score (0-10):"); double quiz4 = s.nextDouble(); System.out.print("Enter quiz 5 score (0-10):"); double quiz5 = s.nextDouble();

17 Lets code it step by step! 5. Compute the quiz average from the five scores. Code:

18 Lets code it step by step! 5. Compute the quiz average from the five scores. Code: // Calculate the average quiz score double quizAverage = (quiz1 + quiz2 + quiz3 + quiz4 + quiz5)/5;

19 Lets code it step by step! 6. Prompt the user to enter scores on the tests and final exam. Code:

20 Lets code it step by step! 6. Prompt the user to enter scores on the tests and final exam. Code: // Collect 2 test scores System.out.print("Enter test 1 score (0-100):"); double test1 = s.nextDouble(); System.out.print("Enter test 2 score (0-100):"); double test2 = s.nextDouble(); // Collect the final test score System.out.println("Enter final exam score (0-100):"); double finalExam = s.nextDouble();

21 Lets code it step by step! 7. Compute the course average from the program average, quiz average, test scores, and final exam score. Code:

22 Lets code it step by step! 7. Compute the course average from the program average, quiz average, test scores, and final exam score. Code: // Calculate the course average double courseAverage =.30 * programAverage * * quizAverage * * test * test * finalExam;

23 Lets code it step by step! 8. Round the course average to the nearest integer and display it. Code:

24 Lets code it step by step! 8. Round the course average to the nearest integer and display it. Code: // Output the course average System.out.println("The final grade is: " + Math.round(courseAverage));

25 Run this program Please run your code, and let me know your questions. The finished code is at: /CourseAverage.java

26 If you have any questions about this program or java programming, I will be here till 8:30pm


Download ppt "The 3 rd and 4 th tutoring session -- A case study about using variables Fall, 2012 Haidong(Haydon) Xue 5:30pm8:30pm 9/11/2012 and 9/12/2012."

Similar presentations


Ads by Google