首页 热点资讯 义务教育 高等教育 出国留学 考研考公

java新手提问啦...

发布网友 发布时间:2022-04-19 21:10

我来回答

3个回答

热心网友 时间:8分钟前

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, 19, 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;
}

热心网友 时间:1分钟前

应该是没有配置环境变量!

热心网友 时间:4分钟前

staff这个变量你要先定义啊.
先定义,后使用,
你不能在main函数里直接用它的.

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com