62,567
社区成员




import java.util.Date;
import java.util.*;
public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("Simon Lo",2450,2006,8,25);
staff[1] = new Employee("Seven Huang",3500,2006,06,01);
staff[2] = new Employee("Eric Yap",5000,2000,01,15);
for (Employee e : staff)
e.raiseSalary(5);
for (Employee e : staff)
System.out.printf("\nName=" + e.getName() + "\nSalary=" + e.getSalary() + "\nHireDay=" + 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;
}
import java.util.*;
class Employee
{
private String name;
private double salary;
private Date hireDay;
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 = salary + raise;
}
//下面的main方法是用来测试Employee类的,并不会在整个程序中执行
public static void main(String args[])
{
Employee test = new Employee("Simon Lo",3000,2006,8,1);
test.raiseSalary(10);
System.out.println("There is some Unit Test blow this line:");
System.out.printf(test.getName() + "\t" + test.getSalary());
}
}
import java.util.*;
public class EmployeeTest
{
public static void main(String args[])
{
Employee[] staff = new Employee[3];
staff[0] = new Employee("Carl Cracker", 75000, 1987, 12, 15);
staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
staff[2] = new Employee("Tony Tester", 40000, 1990, 3, 15);
for (Employee e : staff)
e.raiseSalary(5);
for (Employee e : staff)
System.out.printf("Name=" + e.getName() + "\tsalary=" + e.getSalary() + "\thireDay=" + e.getHireDay() + "\n");
}
}