会java的来看看咋回事?在线等

来源:百度知道 编辑:UC知道 时间:2024/05/14 01:36:32
import java.util.*;
public class EmployeeTest
{
public static void main(String[] args)
{

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

代码如下修改就可以了,你就没有staff,怎么谈得上是再定义一次.
要先声明数组再声明数组中的元素.

public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];// 程序中没有定义staff怎么可能用呢!这是数组的声明方式.
staff[0] = new Employee("张三",75000,1987,12,15);
staff[1] = new Employee("李四",50000,1989,10,1);
staff[2] = new Employee("王五",40000,1990,3,15);

Employee[] staff=new Employee[3];
把上面这句加到main方法的第一行

对呀 你没有创建数组staff怎么就用啊 staff还没有初始化
“ Employee[] staff=new Employee[3];
把上面这句加到main方法的第一行“ 正解

import java.util.*;
public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
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++)
s