java新手提问啦...
发布网友
发布时间:2022-04-19 21:10
我来回答
共3个回答
热心网友
时间:2024-10-01 07:07
staff数组没有定义
----------------------------
import java.util.*;
public class EmployeeTest {
public static void main(String[] args) {
Employee[] staff = new Employee[3];//添上这句就全ok了
staff[0] = new Employee("张三", 75000, 1987, 12, 15);
staff[1] = new Employee("李四", 50000, 1989, 10, 1);
staff[2] = new Employee("王五", 40000, 1990, 3, 15);
for (int i = 0; i < staff.length; i++)
staff[i].raiseSalary(5);
for (int i = 0; i < staff.length; i++) {
Employee e = staff[i];
System.out.println("姓名" + e.getName() + ",工资" + e.getSalary()
+ ",工作时间=" + e.GetHireDay());
}
}
}
class Employee {
public Employee(String n, double s, int year, int month, int day) {
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
hireDay = calendar.getTime();
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public Date GetHireDay() {
return hireDay;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
private String name;
private double salary;
private Date hireDay;
}
热心网友
时间:2024-10-01 07:14
应该是没有配置环境变量!
热心网友
时间:2024-10-01 07:12
staff这个变量你要先定义啊.
先定义,后使用,
你不能在main函数里直接用它的.
热心网友
时间:2024-10-01 07:12
staff数组没有定义
----------------------------
import java.util.*;
public class EmployeeTest {
public static void main(String[] args) {
Employee[] staff = new Employee[3];//添上这句就全ok了
staff[0] = new Employee("张三", 75000, 1987, 12, 15);
staff[1] = new Employee("李四", 50000, 1989, 10, 1);
staff[2] = new Employee("王五", 40000, 1990, 3, 15);
for (int i = 0; i < staff.length; i++)
staff[i].raiseSalary(5);
for (int i = 0; i < staff.length; i++) {
Employee e = staff[i];
System.out.println("姓名" + e.getName() + ",工资" + e.getSalary()
+ ",工作时间=" + e.GetHireDay());
}
}
}
class Employee {
public Employee(String n, double s, int year, int month, int day) {
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
hireDay = calendar.getTime();
}
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public Date GetHireDay() {
return hireDay;
}
public void raiseSalary(double byPercent) {
double raise = salary * byPercent / 100;
salary += raise;
}
private String name;
private double salary;
private Date hireDay;
}
热心网友
时间:2024-10-01 07:11
应该是没有配置环境变量!
热心网友
时间:2024-10-01 07:09
staff这个变量你要先定义啊.
先定义,后使用,
你不能在main函数里直接用它的.