Can someone tell me what I am doing wrong on this java code? public class Main {
ID: 3871669 • Letter: C
Question
Can someone tell me what I am doing wrong on this java code?
public class Main {
double overTimeWage = 0;
double totalHourlyWage = 0;
public static void main(String[] args) {
// TODO Auto-generated method stub
Object e1 = new Object();
Object e2 = new Object();
Object e3 = new Object();
System.out.println("Employee1 salary is: " + e1.hoursPay(7.50, 35));
System.out.println("Employee2 salary is: " + e2.hoursPay(8.50, 47));
System.out.println("Employee3 salary is: " + e3.hoursPay(10.00, 73));
}
public double Pay(double pay, int hours){
while(pay>=8.00 && hours<= 40){
totalHourlyWage = hours * pay;
if(hours > 40 && hours < 60){
overTimeWage = pay * 1.5;
}else{
System.out.println("Error: You have exceeded 60 hours");
}
}
System.out.println("Error: the minimun wage is less than 8");
return this.totalHourlyWage + this.overTimeWage;
}
Explanation / Answer
solution: I think your compiling the above program in the IDE so that it is generating comments like // TODO Auto-generated method stub
According to the information given by you ,There isno need of using [ Object e1 = new Object(); Object e2 = new Object(); Object e3 = new Object(); ]
you are creating e1.hoursPay (7.50,35) which not the method in the object call.
My suggestion is to create the object of the same class and use it . in case any suggestion needed your can comment the solution.
MODIFIED CODE:
public class Main {
double overTimeWage = 0;
double totalHourlyWage = 0;
public static void main(String[] args)
{
//commenting the old code
/*// TODO Auto-generated method stub
Object e1 = new Object();
Object e2 = new Object();
Object e3 = new Object();
System.out.println("Employee1 salary is: " + e1.hoursPay(7.50, 35));
System.out.println("Employee2 salary is: " + e2.hoursPay(8.50, 47));
System.out.println("Employee3 salary is: " + e3.hoursPay(10.00, 73));
*/
Main m= new Main();
System.out.println("Employee1 salary is: " + m.hoursPay(7.50, 35));
System.out.println("Employee2 salary is: " + m.hoursPay(8.50, 47));
System.out.println("Employee3 salary is: " + m.hoursPay(10.00, 35));
}
public double hoursPay(double pay, int hours){
if (pay>=8.00 && hours<= 40)
{
totalHourlyWage = hours * pay;
if(hours > 40 && hours < 60)
{
overTimeWage = pay * 1.5;
}
else
{
System.out.println("Error: You have exceeded 60 hours");
}
return this.totalHourlyWage + this.overTimeWage;
}
else
{
System.out.println("Error: the minimun wage is less than 8");
return 0.0;
}
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.