代码没有错误,但是无法发送结果。

huangapple go评论80阅读模式
英文:

Code shows no errors but won't send results

问题

我一直在努力寻找缺失的链接,员工的展示,但薪水无法计算。我需要洞察力,因为我似乎没有注意到会引起这种情况的原因。我相信问题在于TestEmployee.java。

Employee.java

package salary;
public abstract class Employee {
    	
    public String fullName;
    
    public Employee() {
    }
    
    public String getFullName() {
        return fullName;
    }
    
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    
    public abstract double getBiWeeklyPay(); 
    
    public void printgetBiWeeklyPay() {
       System.out.println("员工 " + this.fullName + " 的" + "双周薪水是:");
    }
}

HourlyEmployee.java

package salary;
public class HourlyEmployee extends Employee {
    	
    public double hourlyRate;
    
    public double hoursPerWeek;
    
    public HourlyEmployee() {
    }
    
    public double getBiWeeklyPay() {
        return hourlyRate * (hoursPerWeek * 2);
    }
    
    public double getHourlyRate() {
        return hourlyRate;
    }
    
    public void setHourlyRate(double hourlyRate) {
        this.hourlyRate = hourlyRate;
    }
    
    public double getHoursPerWeek() {
        return hoursPerWeek;
    }
    
    public void setHoursPerWeek(double hoursPerWeek) {
        this.hoursPerWeek = hoursPerWeek;	
    }   
}

SalaryEmployee.java

package salary;
public class SalaryEmployee extends Employee {
    	
    public SalaryEmployee() {
    }
    
    public double salary;
    
    public double getBiWeeklyPay() {
        return salary / (52 * 2);
    }
    
    public double getSalary() {
        return salary;
    }
    
    public void setSalary(double salary) {
        this.salary = salary;
    }
}

TestEmployee.java

package salary;
import java.util.*;

public class TestEmployee {
    
    public static void main(String[] args){
    
    java.util.ArrayList<Employee> employees = new java.util.ArrayList<Employee>();
    
    SalaryEmployee john = new SalaryEmployee();
    john.setFullName("John Doe");
    john.setSalary(50000.00);
    employees.add(john);
           
    HourlyEmployee bob = new HourlyEmployee();
    bob.setFullName("Bob Smith");
    bob.setHourlyRate(15.00);
    bob.setHoursPerWeek(20.00);
    employees.add(bob);
    
    HourlyEmployee Joe = new HourlyEmployee();
    Joe.setFullName("Joe Moe");
    Joe.setHourlyRate(27.00);
    Joe.setHoursPerWeek(45.00);
    employees.add(Joe);
    
    HourlyEmployee Doe = new HourlyEmployee();
    Doe.setFullName("Doe Joe");
    Doe.setHourlyRate(20.00);
    Doe.setHoursPerWeek(25.00);
    employees.add(Doe);
    
    print(employees);
    
    }

    public static void print(ArrayList<Employee> employees){   
        for(Employee e: employees){
          e.printgetBiWeeklyPay();
        }
    }
    
}

员工、薪水、按小时计算的薪水都是预先制作的,以及TestEmployee,我按照指示进行操作。我阅读了教材和老师的讲座,一切似乎都是有序的。希望有人能给我一个提示,我会有更好的理解。

英文:

I have been stuck trying to find the missing link, the employee's show but the pay won't calculate. I could use the insight as i can't seem to notice what would cause this. I do belive the problem lies in TestEmployee.java.

Employee.java

package salary;
public abstract class Employee {
    	
    public String fullName;
    
    public Employee() {
    }
    
    public String getFullName() {
        return fullName;
    }
    
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    
    public abstract double getBiWeeklyPay(); 
    
    public void printgetBiWeeklyPay() {
       System.out.println(&quot;Employee &quot;+this.fullName+ &quot;&#39;s&quot;+ &quot;Bi-weekly pay is:&quot;);
    }
}

HourlyEmployee .java

package salary;
public class HourlyEmployee extends Employee {
    	
    public double hourlyRate;
    
    public double hoursPerWeek;
    
    public HourlyEmployee() {
    }
    
    public double getBiWeeklyPay() {
        return hourlyRate * (hoursPerWeek *2);
    }
    
    public double getHourlyRate() {
        return hourlyRate;
    }
    
    public void setHourlyRate(double hourlyRate) {
        this.hourlyRate = hourlyRate;
    }
    
    public double getHoursPerWeek() {
        return hoursPerWeek;
    }
    
    public void setHoursPerWeek(double hoursPerWeek) {
        this.hoursPerWeek = hoursPerWeek;	
    }   
}

SalaryEmployee.java

package salary;
public class SalaryEmployee extends Employee {
    	
    public SalaryEmployee() {
    }
    
    public double salary;
    
    public double getBiWeeklyPay() {
        return salary/(52*2) ;
    }
    
    public double getSalary() {
        return salary;
    }
    
    public void setSalary(double salary) {
        this.salary = salary;
    }
}

TestEmployee.java

package salary;
import java.util.*;

public class TestEmployee {
    
    public static void main(String[] args){
    
    java.util.ArrayList&lt;Employee&gt; employees = new java.util.ArrayList&lt;Employee&gt;();
    
    SalaryEmployee john = new SalaryEmployee();
    john.setFullName(&quot;John Doe&quot;);
    john.setSalary(50000.00);
    employees.add(john);
           
    HourlyEmployee bob = new HourlyEmployee();
    bob.setFullName(&quot;Bob Smith&quot;);
    bob.setHourlyRate(15.00);
    bob.setHoursPerWeek(20.00);
    employees.add(bob);
    
    HourlyEmployee Joe = new HourlyEmployee();
    Joe.setFullName(&quot;Joe Moe&quot;);
    Joe.setHourlyRate(27.00);
    Joe.setHoursPerWeek(45.00);
    employees.add(Joe);
    
    HourlyEmployee Doe = new HourlyEmployee();
    Doe.setFullName(&quot;Doe Joe&quot;);
    Doe.setHourlyRate(20.00);
    Doe.setHoursPerWeek(25.00);
    employees.add(Doe);
    
    print(employees);
    
    }

    public static void print(ArrayList&lt;Employee&gt; employees){   
        for(Employee e: employees){
          e.printgetBiWeeklyPay();
        }
    }
    
}

Employee, salary, hourly were mostly premade along with TestEmployee i was instructed. I read through my textbook and my teachers lectures, and everything seems to be in order. Hopefully someone could give me a hint and i will have a better understanding.

答案1

得分: 1

我建议您通过实际调用预期方法来改进printgetBiWeeklyPay()的实现。

英文:

I suggest you improve the implementation of printgetBiWeeklyPay() by actually invoking the intended method.

答案2

得分: 0

public void printgetBiWeeklyPay() {
   System.out.print("Employee " + this.fullName + "'s" + "Bi-weekly pay is: " + String.valueOf(this.getBiWeeklyPay()));
}
英文:
public void printgetBiWeeklyPay() {
   System.out.println(&quot;Employee &quot;+this.fullName+ &quot;&#39;s&quot;+ &quot;Bi-weekly pay is:&quot;);
} 

Referring to your code above, your method printgetBiWeeklyPay() just did what you have mentioned, printing the employee name and bi-weekly pay but without the number... Can you see that you are missing the crucial variable in the print statement? Where is your variable for biweekly pay? You never call it, hence no output of the biweekly pay is produced.

Perhaps:

public void printgetBiWeeklyPay() {
   System.out.print(&quot;Employee &quot;+this.fullName+ &quot;&#39;s&quot;+ &quot;Bi-weekly pay is:&quot; + String.valueOf(this.getBiWeeklyPay());
}

huangapple
  • 本文由 发表于 2020年4月4日 13:54:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/61024312.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定