CISC 1115
Introduction to Programming Using Java
Lab #2
Floating point, Weighted Averages

How to Develop and Submit your Labs

Lab 2.1 — A Floating Point Averager (ExamGrader)

Redo Lab 1.9 so that the average is calculated as a double. Sample Test Run
How many students?
2
last name? Weiss
first name? Gerald
exam1? 73
exam2? 84
final? 96
Gerald Weiss scored 73, 84, and 96 for an average of 84.33333333333333
Weiss, Gerald passes
last name? Doe
first name? John
exam1? 40
exam2? 51
final? 56
John Doe scored 40, 51, and 56 for an average of 49.0
Doe, John fails

Lab 2.2 — A Weighted Averager (WeightedAverager)

In a 'normal' (unweighted) average, all the elements carry the same weight — i.e., the all contribute equally to the average, and thus, to calculate such an average, one adds up the elements and divides by the number of elements. In a weighted average, the various elements contribute differently to the average, some counting more than other, and thus carry different weights. A weighted average is specified by providing the weight of each element. (As an example, as mentioned in the syllabus, your semester average for this course is a weighted average where the assignments, exams, and final contribute different amounts to the average.)

Weighted averages are typically expressed by specifying the percentage that each element contributes to the average. The percentages must sum to 100% for the average to be correct. To calculate the average, each element is multiplied by it's percentage (don't forget, 50% is actually .50), and the products then summed producing the average.

(Another way of calculating the weighted average is to treat each exam as counting for its percentage points out of 100 and then dividing the total by 100 (this works if you are restricting the calculations to integers and thus can't use something like .50). For example if an exam is worth 65%, you multiply the score by 65; f the other one is then 35%, you multiply it by 35, and after you've added those amount together, you divide by 100.)

Write a program that prompts the user for a project, midterm and final and displays their weighted average (as a floating point, i.e., double) according to the following table:

Project 20%
Midterm 30%
Final 50%

(Notice this is very similar yo the previous lab, but with weighted averages, and the prompts and output are different … but it still makes sense to copy Lab 2.1 for your starting point. Starting from a similar program is often simpler than starting from scratch and a useful skill to master.)

Sample Test Run

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

Enter project: 80
Enter midterm: 85
Enter final: 90
Weighted average: 86.5

Lab 2.3 — Revisiting Weighted Averages (WeightedAverager) Approval

Modify Lab 2.2 so that the user is prompted for the weights of the exams (see sample run).

Sample Test Run

Here is a sample execution of the program.
User input is in bold. Your program should replicate the prompts and output:

Enter project: 80
project %: 0.1
Enter midterm: 85
midterm %: 0.4
Enter final: 90
final %: 0.5
Weighted average: 87.0