CSC 117 Lab 3 - Fall 2019 - Java Fundamentals (Chapter 1-3) Lab Objectives
CSC 117 Lab 3 - Fall 2019 - Java Fundamentals (Chapter 1-3) Lab Objectives
Exercise 1:
A firm hires you to debug the following program.
1. This program calculates the user’s gross pay by multiplying the number of hours worked by
hourly pay rate. However, it is not always calculated this way. What if you work 45 hours in a
week? The hours that worked over 40 hours are considered overtime. The user will need to be
paid time and a half for the overtime hours worked. The program calculates user’s gross pay
with or without overtime.
a. If this program correctly implemented?
No because the calculations were wrong .
b. Did you find syntax error? Which one(s)?
No I didn’t find no syntax errors.
c. Did you identify logic error? Which one(s).
These were the two errors on this code which I corrected to
if(hours > 40) - if(hours < 40)
pay = (hours + 40) * (1.2 * rate) + 40 * rate- pay = (hours - 40) * (1.5 * rate) + 40 *
rate;
20 10 200
40 10 400
60 10 600
80 10 800
//identifier declarations
double hours; //number of hours worked
double rate; //hourly pay rate
double pay; //gross pay
//calculations
if(hours > 40)
pay = hours * rate;
else
pay = (hours + 40) * (1.2 * rate) + 40 * rate;
//display results
System.out.println("You earned $" + pay);
}
}
This is make code
import java.util.Scanner;
//identifier declarations
double hours; //number of hours worked
double rate; //hourly pay rate
double pay; //gross pay
//calculations
if(hours <= 40) {
pay = hours * rate;
}
else
pay = (hours - 40) * (1.5 * rate) + 40 * rate;
//display results
System.out.println("You earned $" + pay);
}
}
Write a program that ask the user to enter the name of his favorite dish. Use a String variable(object) to
store the input. The program will display the following:
Last month Kareem purchased some stock in Alphabet. The details of the purchase are given
below:
The number of shares that Kareem purchased was 1,000
Kareem purchased stock with the share priced at $32.87 each
Kareem paid the stock broker a commission equivalent to 2% of the amount paid for the stock
Two weeks later Kareen sold the stock. The details of the sale are provided below:
The amount of commission Kareem paid his broker when he bought the stock
The amount of commission Kareem paid his broker when he sold the stock
Print the amount of profit/loss that Kareem made after selling his stock and paying the two commissions
to his broker.
Deliverables by 9/5