import java.util.*;public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("Tom",10000,1988,1,1);
staff[1] = new Employee("Bob",20000,1788,2,2);
staff[2] = new Employee("Jhom",30000,1968,3,3);
for(Employee e:staff)//想把这块改成for(int i=0;i<staff.length;i++的形式该怎么写)
e.raiseSalary(5);
for(Employee e:staff)//还有这块同上
System.out.println("name=" + e.getName()
+ "salary=" + e.getSalary()
+ "hireDay=" + e.getHireDay());
}
}class Employee
{
public Employee(String n, double s, int year,int month, int day)
{
name = n;
salary = s;
GregorianCalendar gc = new GregorianCalendar(year,month-1,day);
hireDay = gc.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;
}
楼主【cismylife】截止到2008-07-16 16:50:41的历史汇总数据(不包括此帖):
发帖的总数量:3 发帖的总分数:80 每贴平均分数:26
回帖的总数量:2 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:3 结贴的总分数:80
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!
for (int i = 0; i < staff.length; i++) {
staff[i].raiseSalary(5);
}
for (int i = 0; i < staff.length; i++) {
System.out.println("name=" + staff[i].getName() + " salary=" + staff[i].getSalary() + " hireDay=" + staff[i].getHireDay());
}
for (int i = 0; i < staff.length; i++) {
Employee e=staff[i];
e.raiseSalary(5);
}
for (int i = 0; i < staff.length; i++) {
Employee e=staff[i];
System.out.println("name=" + e.getName() + " salary=" + e.getSalary() + " hireDay=" + e.getHireDay());
}
呵呵,那个不是staff数组在调,表达式是:staff[i],这个表示的是一个Employee对象哈,你那个数组不是就装的是Employee吗?呵呵。