₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,324,996 members, 8,419,859 topics. Date: Thursday, 04 June 2026 at 03:45 AM

Toggle theme

Please Solve This Java Problem. - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease Solve This Java Problem. (2905 Views)

1 Reply (Go Down)

Please Solve This Java Problem. by lekropasky(op): 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):
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!
Re: Please Solve This Java Problem. by khaynoni(m):

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
Re: Please Solve This Java Problem. by lekropasky(op): 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

Please HELP Me With This Java ProgramHelp Me Solve This Java Regex ProblemWhen Your Brain Throws Stackoverflow Error - Debug This JAVA Code If You Can234

creating your first Html5 hybrid appAverage Salary/hourly Wage For A Programmer In Nigeria These DaysHow Does A Rookie Java/j2ee Programmer Get A Job?