Starting from:
$35

$29

Project 1 Solution

You should already have a directory named cs140 created during the lab session. Now make a new directory named project in cs140 and then change your working directory to project.




$cd cs140

$mkdir project

$cd project




Task #1: You are working for a FOO software development company as an hourly paid employee. In FOO, all hourly paid employees are required to work at least 15 hours but no more than 60 hours per week. Your weekly gross pay is calculated by multiplying the number of hours you worked in a week with your pay rate. However, if you work overtime (i.e. more than 40 hours in a week), the overtime pay rate is 1.5 times of normal rate. For example, if your pay rate is $20 per hour and you worked 45 hours this week, your gross pay for this week will be $20*40+$20*1.5*5=$950. Only whole hours are counted and entered (i.e. hours will be an integer.) If you work less than 15 hours this week, your pay will be deferred to next week and you get $0 paid this week. If you work more than 60 hours this week you only be paid for 60 hours and the remaining hours will be forfeited.

Write a Java program that reads in the number of hours you worked this week, your hourly pay rate, and then calculates and outputs the gross pay. The program should output appropriate message (e.g. hours deferred, overtime ignored, …) in addition to gross output. Test your program with the following data:




Hours worked
Hourly pay rate
35
$25.0
22
$18.5
42
$20
58
$22.8
12
$25
65
$25



Sample input/output test runs may look like: (user input shown in bold).




Please enter hours you worked this week: 42

Please enter your hourly pay rate: 20

Your gross pay is $860.




Please enter hours you worked this week: 10

Please enter your hourly pay rate: 20

Your gross pay is $0.

Sorry you need to work at least 15 hours to get paid this week.

Your hours worked will be deferred to next week.




Suggested steps for program development (apply to all the programming tasks)

(1) Develop an algorithm using pseudo code (see lecture demonstration).

(2) Write a program

(3) Compile the program and fix errors if any

(4) Run the program and fix errors if any

See Coding and Debugging notes on blackboard under Resources link.

Task #2: Write a Java program with switch and if-else statements that prompts the user for a month and day and then prints the season determined by the following rules.




Spring
3/21 – 6/20
Summer
6/21 – 9/20
Fall
9/21 – 12/20
Winter
12/21 – 3/20



If an invalid value of month (<1 or 12) or invalid day (<1 or 31) is input, the program should display an error message and stop. Test your program using the following test date:




Normal cases
1/5, 2/5, 4/10, 5/10, 7/15, 8/15, 10/20, 11/20
Boundary cases
3/20, 3/21, 6/20, 6/21, 9/20, 9/21, 12/20, 12/21
Abnormal cases
Invalid month, e.g. 0, -3, 13

Invalid day, e.g. 0, -5, 32



Below are some examples of input/output test runs, where the user’s input is shown in bold.




lyang@garrison ~/cs140/proj $ java Season

enter month (1-12): 0

Invalid month!




lyang@garrison ~/cs140/proj $ java Season

enter month (1-12): 1

enter day (1-31): -3

Invalid day!




lyang@garrison ~/cs140/proj $ java Season

enter month (1-12): 3

enter day (1-31): 20

3/20 is in the Winter season.




lyang@garrison ~/cs140/proj $ java Season

enter month (1-12): 3

enter day (1-31): 21

3/21 is in the Spring season.




Notes on programming style:

All your Java program must begin with the comments below and follow the naming and coding conventions posted on Blackboard under Resources link.




// your name

// CS140

// Project x, Problem y – descriptive title of the problem

// date




Submission requirements:

Create a script file that captures: program1 source code, all test runs for program 1, program 2 source code, all test runs for program 1. Submit three files (the script file, program1.java and program2.java) on blackboard assignment under project 1.

More products