我不知道我在做什么。请帮帮我!
我应该:
将一个名为printEmployeeInfo的方法添加到Employee类中,该类将打印有关员工姓名,员工编号和当前工资的信息。
创建一个应用程序类EmployeeDemo(类似于DeclareTwoEmployee类),它创建两个Employee类型的对象,设置其数据字段的值并通过调用printEmployeeInfo方法打印它们的信息。
Public class Employee { // an application class
public static void main( String[] args) {
}
答案 0 :(得分:0)
创建一个包含姓名,员工编号和当前薪水的员工类。所以在你的班级中添加以下三个字段:
public class Employee {
String employeeName;
String employeeNumber;
double salary;
//declare printEmployeeInfo method like
public void printEmployeeInfo() {
System.out.println(employeeName....);
}
}
使用main方法创建Demo类,如:
class EmployeeDemo {
public static void main(String args[]) {
Employee e1 = ..//first employee
Employee e2 = ..//second employee instance
e1.printEmployeeInfo();//calling method which will print employee info
}
}
答案 1 :(得分:-1)
public class Employee {
private String name;
private String number ;
private String current_salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getCurrent_salary() {
return current_salary;
}
public void setCurrent_salary(String current_salary) {
this.current_salary = current_salary;
}
@Override
public String toString() {
return "Employee{" + "name=" + name + ", number=" + number + ", current_salary=" + current_salary + '}';
}
public void printEmployeeInfo()
{
System.out.println(this);
}
public static void main( String[] args) {
Employee e=new Employee();
e.setCurrent_salary("0");
e.setName("Lura Schiele");
e.setNumber("000-000-000");
e.printEmployeeInfo();
}
}