日期:2014-05-20 浏览次数:20784 次
import com.horstmann.corejava.*;
import static java.lang.System.*;
public class Study
{
public static void main(String[] args)
{
Employee harry = new Employee("Harry Hacher", 5000, 1989, 10, 1);
harry.raiseSalary(5);
System.out.println("name = " + harry.getName());
}
}
package com.horstmann.corejava;
import java.util.*;
public 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)
{
salary = salary + salary*byPercent/100;
}
}