Description
Part 1 (30 points)
The protocol for this program is for this program only. The project may be done on a lab
computer or on you own laptop. Enter the program. given below into NetBeans, and put
your name on the first comment line of the program, as below. Duplicate the format of
the program exactly as given. The spacing is important.
Show this program working directly to the peer mentor. Also show the peer mentor that
you can set a breakpoint in the program, run the program step by step, and check the
status of a variable.
When you have completed the above, get a printout of the program and a printout of a
sample run, and have a peer mentor sign the program in handwriting. The signature is
to confirm that the peer mentor has observed your run of the program AND your step by
step use of the debugger.
Part 2 (30 points)
Unit Pricing Write your own Java program to read the unit price of an item and the
quantity ordered, and then calculate the total amount of the purchase (all integers). You
must give the EXACT input and output as shown below. (Boldface values are what the
user enters.)
Please enter the Quantity desired: 5
Please enter the Unit price: 10
The Quantity desired is : 5
The Unit Price is : $10
The Total Amount is : $50
Program for Part 1
import java.util.Scanner;
public class CalcAverage {
// Written by: George Washington
// Computes the average of a set of values entered by the user, e.g. with
// 10.0 5.0 6.0 9.0 0.0
// the average is 7.5
public static void main(String[ ] args) {
Scanner stdin = new Scanner(System.in);
int count;
double number, runningTotal;
runningTotal = 0;
count = 0;
System.out.println(“Type the numbers, the last being 0”);
number = stdin.nextDouble();
while (number != 0) {
runningTotal = runningTotal + number;
count = count + 1;
number = stdin.nextDouble();
}
System.out.print(“The average of the “);
System.out.print(count);
System.out.print(” numbers is “);
System.out.println(runningTotal/count);
}}