CISC 1115
Introduction to Programming Using Java
Lab #2
Floating point, Weighted Averages, Simple if, and if/else

How to Develop and Submit your Labs

Lab 2.1 — A Floating Point Average

Write a program that prompts the user for three (3) integers and displays their average (as a floating point, i.e., double).

Sample Test Run

Enter first number: 5
Enter second number: 7
Enter third number: 8
The average of 5, 7, and 8 is 6.666666666666667
More practice with input; floating point arithmetic.

Lab 2.2 — A Weighted Average

In a 'normal' 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.

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%

Sample Test Run

Enter project: 80
Enter midterm: 85
Enter final: 90
Weighted average: 86.5
Practice with calculating a weighted average.

Lab 2.3 — Out with the Old …

Implementation of the basic payroll system at PicoSoft was such a smashing success, they've decided to throw some more work your way and invest in further software development. The company requires downsizing, due to the sagging economy; and management has thus decided to institute a mandatory retirement age of 65.

Write a program that input an employee's last name, first name, and age, and if the employee is 65 or older, displays the employee's name together with the words "must retire" on the screen (nothing should be displayed if the employee is below the retirement age).

Here is a good opportunity to prctice your copy/paste (or duplicate source file) skills. Feel free to use your original payroll program's (Lab 1.3/1.4) source as a starting point (it has some of the code you will be using-- the boilerplate of course, some of the declarations, the code to read in the last and first name, possibly the for loop,...)

Sample Test Run #1

Enter last name: Weiss
Enter first name: Gerald
Enter age: 50

Sample Test Run #2

Enter last name: Arnow
Enter first name: David
Enter age: 70
David Arnow must retire
Conditionals

Lab 2.4 — Bonuses!!! (Approval)

Your on a roll to taking over the world's payroll software market!

Now that the company has reduced it workforce and dramatically cut expenses, BONUSES can be given to the top-level executives (departments 1 and 2)! But given the public's anger at outrageous payouts to executives, management has decided to give EVERYONE a bonus: executives get cash, while the rest of the company get a cute little teddy bear with the comany name on its belly.

Write a program that reads in (from the keyboard) an employee's last name, first name, and department number, and displays the employee's name and the bounus they shoud receive: either the string "$$$!!!" or the string "Cute little Teddy Bear"

Sample Test Run #1

Enter last name: Weiss
Enter first name: Gerald
Enter department #: 2
Gerald Weiss gets $$$!!!

Sample Test Run #2

Enter last name: Arnow
Enter first name: David
Enter department #: 1
David Arnow gets $$$!!!
More conditionals