所以我一直在为实验室编写一个代码,我们需要创建一个名为payroll的类,其中我们有名字,地址,工资和工作小时数的getter和setter,然后创建一个方法来打印地址和名称和另一种计算工作小时数的方法x支付并在另一个名为demoPayroll的类上打印地址和名称。我的getter和setter并没有转移到demoPayroll。这是我的代码。非常感谢任何帮助!
{{1}}
答案 0 :(得分:0)
首先,我可能认为您已从外部源复制了该程序, 因为有很多编译错误。 无论如何... 试试这个可行的方法......
import java.util.Scanner;
公共课DemoPayroll {
public static void main(String[] args) {
Payroll newEmpInfoObject = new Payroll();
System.out.println("Enter name");
Scanner keyboard = new Scanner(System.in);
String name = keyboard.nextLine();
System.out.println("Enter Address");
String address = keyboard.nextLine();
System.out.println("Enter Hourly Pay");
double payrate = keyboard.nextDouble();
System.out.println("Enter Hours Worked");
double hours = keyboard.nextDouble();
System.out.println("Enter Weeks");
int week = keyboard.nextInt();
Payroll pay=new Payroll();
pay.printEmpInfo(name,address);
System.out.println(pay.getGrossPayEarned(payrate,hours,week));
}
}
班级薪资{
private double payrate;
private double hours;
public Object printEmpInfo(String name,String address) {
System.out.println(name);
System.out.println(address);
return address;
}
public double getGrossPayEarned(double payrate,double hours,int week) {
return (hours)*((hours/week)*52)/12;
}
}