• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Exercise

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Task 1: Body Mass Index (BMI):

Body mass index is a measure of whether someone’s weight is appropriate for their height. A body-mass-index value between 19 and 25 is considered to be in the normal range. Here’s the formula for calculating body mass index:



Part A - Implement a program that prompts the user for height and weight values
and displays the associated body mass index.

Perform input validation by making sure that the user enters positive decimal numbers for height and weight. See the sample session for details. In particular, note the format for the echo-printed height and weight values and for the generated body-mass-index value.

For this program, there’s no need for multiple classes or even multiple methods. Just put all your code in a main method and put the main method in a BodyMassIndex class.

Sample session:

Enter height in inches: hi
Invalid inches value. Must be a decimal number.
Re-enter height in inches: 0
Invalid inches value. Must be positive.
Re-enter height in inches: 69.25
Enter weight in pounds: dog
Invalid pounds value. Must be a decimal number.
Re-enter weight in pounds: -3
Invalid pounds value. Must be positive.
Re-enter weight in pounds: 150.5

Height = 69.25"
Weight = 150.5 pounds
Body Mass Index (BMI) = 22.1

(25 marks)
Part B - The difference between this program and the previous program is that this program uses feet and inches for the height value rather than just feet.

Perform input validation by making sure that the user enters a positive integer number for feet, a nonnegative decimal number for inches, and a positive decimal number for weight. See the sample session for details. In particular, note the format for the echo-printed height and weight values and for the generated body-mass-index value.

Sample session:

Enter height using feet space inches (e.g., 5 6.25): hi there
Invalid feet value. Must be an integer.
Invalid inches value. Must be a decimal number.
Re-enter height using feet space inches (e.g., 5 6.25): 0 9
Invalid feet value. Must be positive.
Re-enter height using feet space inches (e.g., 5 6.25): 5.25 0
Invalid feet value. Must be an integer.
Re-enter height using feet space inches (e.g., 5 6.25): 5 9.25
Enter weight in pounds: 0
Invalid pounds value. Must be positive.
Re-enter weight in pounds: 150.5
height = 5'-9.25"
weight = 150.5 pounds
body mass index = 22.1

(10 marks)
Task 2: Payroll System:
Write an employee payroll program that uses polymorphism to calculate and print the weekly payroll for your company. There are three types of employees ─ hourly, salaried, and salaried plus commission. Each type of employee gets paid using a different formula. But for ALL employee types, if the calculated paycheck exceeds $1000, the actual paycheck must be decreased to $1000.

Use this class hierarchy:

Employee class:

Instance variables:
name
social security number
birthday month
birthday week.
load method :
Prompts the user for instance-variable values and loads the entries.
toString method:
Returns a string that shows the employee’s name, social security number, and paycheck. Use the String.format method (See Java API documentation to help you format the string as shown in the sample session’s paycheck report.) Here’s an example from the sample session:
employee: Biff Sanchez
social security number: 111-11-1111
paycheck: $800.00
getBonus method:
Generates a $100 employee birthday bonus. Compare the employee’s birthday with the current date found on your computer system. Use the Calendar class to generate the current date. (See Sun’s Java API documentation.) If the employee’s birthday month and birthday week match your computer system’s current month and current week, then increment the employee’s paycheck by $100. The birthdayMonth holds the month (1─12) in which the employee was born. The birthdayWeek holds the week (1─4) that the employee chooses to get paid his/her bonus.

Hourly class:
Instance variables:
hourly pay
hours worked during the past week

load method:
Prompts the user for instance-variable values and loads the entries.

Include a getEarnings method that calculates earnings for an hourly employee. Hourly employees are paid by the hour. If they work more than 40 hours in a week, then they receive overtime pay for their overtime work. Overtime pay equals one and a half times their normal hourly pay.

Salaried class:
Instance variables:
weekly salary

load method:
Prompts the user for instance-variable values and loads the entries.

Include a getEarnings method that calculates earnings for a salaried employee. Salaried employees are paid their fixed weekly salary regardless of the number of hours they work.

SalariedPlusCommission class:
Instance variables:
sales during the past week
commission rate

load method:
Prompts the user for instance-variable values and loads the entries.

Include a getEarnings method that calculates earnings for a SalariedPlusCommission employee. SalariedPlusCommission employees are paid a base salary plus a percentage of their sales. “Percentage of their sales” equates to the product of their sales times their commission rate.

Use initially declared named constants instead of hardcoded “magic numbers” embedded in the program. In the Employee class, include a getEarnings method that is abstract.

Use the public access modifier for the toString method in the Employee class and the load method in the Employee, Hourly, Salaried, and SalariedPlusCommission classes.

You are required to show/provide all the necessary validation by receive and display all the required data by using appropriate comments, variable usage, program logic, I/O statements, more interactive and user friendly with all the possible output screens. Provide a driver that generates the following queries and outputs.

Sample session (assuming current month = 10 and current week = 2):

Number of employees: 3

PROFILE FOR EMPLOYEE #1:
type Hourly(1), Salaried(2), Salaried plus Commission(3)
Enter 1, 2, or 3 ==> 1
Name ==> Biff Sanchez
Social security number ==> 111-11-1111
Birthday month (1-12) ==> 2
Birthday bonus week (1-4) ==> 3
Hourly pay ==> 20
Hours worked this past week ==> 30

PROFILE FOR EMPLOYEE #2:
type Hourly(1), Salaried(2), Salaried plus Commission(3)
Enter 1, 2, or 3 ==> 2
Name ==> Dirk Jones
Social security number ==> 222-22-2222
Birthday month (1-12) ==> 10
Birthday bonus week (1-4) ==> 2
Salary ==> 700

PROFILE FOR EMPLOYEE #3:
type Hourly(1), Salaried(2), Salaried plus Commission(3)
Enter 1, 2, or 3 ==> 3
Name ==> Suzie Que
Social security number ==> 333-33-3333
Birthday month (1-12) ==> 7
Birthday bonus week (1-4) ==> 3
Salary ==> 400
Sales for this past week ==> 2000
Sales commission rate (fraction paid to employee) ==> .25

PAYCHECK REPORT:

employee: Biff Sanchez
social security number: 111-11-1111
paycheck: $600.00

employee: Dirk Jones
social security number: 222-22-2222
paycheck: $800.00

employee: Suzie Que
social security number: 333-33-3333
paycheck: $900.00
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have a question?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and welcome to the Ranch
 
Yu Hang Lee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya. there is all my question.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yu Hang Lee wrote:Ya. there is all my question.


Please be specific about what you need help with. Nobody wants to pore through all that to try to figure out what you're having trouble with. And in case you misunderstood what this community is about, we help and advise beginners on how to solve their own problems; we won't do your homework for you.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic