Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,757 members, 8,000,201 topics. Date: Tuesday, 12 November 2024 at 03:42 AM

Please Solve This Java Problem. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Solve This Java Problem. (2779 Views)

Please HELP Me With This Java Program / Help Me Solve This Java Regex Problem / When Your Brain Throws Stackoverflow Error - Debug This JAVA Code If You Can (2) (3) (4)

(1) (Reply) (Go Down)

Please Solve This Java Problem. by lekropasky(m): 12:39pm On Aug 20, 2015
Develop a Java application that determines the Gross pay for each of three employees. The company pays straight time for the first 40hours worked by each employee and time and a half for all hours worked in excess of 40hours. You're given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee. Then determine and display the employee"s gross pay.
Use class scanner to input the data.

Goodluck.
Re: Please Solve This Java Problem. by OracleMxNelson(m): 12:43pm On Aug 20, 2015
nsobu
Re: Please Solve This Java Problem. by DonSegmond(m): 1:56pm On Aug 20, 2015
lekropasky:
Develop a Java application that determines the Gross pay for each of three employees. The company pays straight time for the first 40hours worked by each employee and time and a half for all hours worked in excess of 40hours. You're given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee. Then determine and display the employee"s gross pay.
Use class scanner to input the data.

Goodluck.


For each employee:
employee.pay = employee.hours * REGULAR_PAYRATE
if employee.hours > 40:
employee.pay = employee.pay + ((employee.hours - 40) * 0.5 * REGULAR_PAYRATE)
print employee.pay



Now, write it in Java your damn self. Goodluck!

2 Likes

Re: Please Solve This Java Problem. by khaynoni(m): 5:47pm On Aug 20, 2015

no_of_employees = 3
k = 1
hourly_pay = float(raw_input())
while k <= no_of_employees:
print "Employee", k
hours = int(raw_input())
if hours <= 40:
gross_pay = hours * hourly_pay
else:
overtime = hours - 40
overtime_pay = overtime * 1.5 * hourly_pay
gross_pay = overtime_pay + (40*hourly_pay)
k += 1
print gross_pay


I hope this helps. Though the sad news is that it is written in Python wink so like the guy up there said, rewrite it in Java. cheesy grin

1 Like

Re: Please Solve This Java Problem. by lekropasky(m): 7:29pm On Aug 20, 2015
khaynoni:

no_of_employees = 3
k = 1
hourly_pay = float(raw_input())
while k <= no_of_employees:
print "Employee", k
hours = int(raw_input())
if hours <= 40:
gross_pay = hours * hourly_pay
else:
overtime = hours - 40
overtime_pay = overtime * 1.5 * hourly_pay
gross_pay = overtime_pay + (40*hourly_pay)
print gross_pay


I hope this helps. Though the sad news is that it is written in Python wink so like the guy up there said, rewrite it in Java. cheesy grin

WoW....thanks Bro.
You Rocks.
I have some questions...

-I dont know the use of the 'k' and why it appears in the print statement.

-and i dont understand where you use 1.5 in the variable overtime_pay.

Thank You.
Re: Please Solve This Java Problem. by khaynoni(m): 7:57pm On Aug 20, 2015
lekropasky:
Develop a Java application that determines the Gross pay for each of three employees. The company pays straight time for the first 40hours worked by each employee and time and a half for all hours worked in excess of 40hours. You're given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee. Then determine and display the employee"s gross pay.
Use class scanner to input the data.

Goodluck.

The bolded explains why I used 1.5, note that a time and a half is the same as 1 1/ 2 = 3/2 = 1.5.
As for the "k", if you run the program, you'll understand how it works.
Re: Please Solve This Java Problem. by khaynoni(m): 8:11pm On Aug 20, 2015
By the way, have you tried writing the codes in Java? When you run it, what was the output? Do you know that you still need to modify my code so as to enable the user know what to input? Do you know that you have to ensure that every value the user enters is the data type you would want to be inputted; for example, in the case of the code above where the user is being asked to enter the hourly_pay, if he inputs twenty instead of 20, do you know it will give an error msg?
These are just part of the modifications you'll have to make. Good luck wink

(1) (Reply)

Cleandesktop Full Version Open Source Released / Top 10 Richest Software Programmers In The World / Are There Nigerian Companies Using These Languages?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.