日期:2014-05-20  浏览次数:20639 次

Java程序设计
Java程序设计  

1.   import   java.util.*;  
2.  
3.   public   class   EmployeeTest  
4.   {  
5.   public   static   void   main(String[]   args)  
6.   {  
7.   //   fill   the   staff   array   with   three   Employee   objects  
14.   //   raise   everyone 's   salary   by   5%  
18.   //   print   out   information   about   all   Employee   objects  
}  
24.   }  
25.  
26.   class   Employee  
27.   {  
28.   public   Employee(String   n,   double   s,   int   year,   int   month,   int   day)  
37.   public   String   getName()  
42.   public   double   getSalary()  
47.   public   Date   getHireDay()  
52.   public   void   raiseSalary(double   byPercent)  
58.   private   String   name;  
59.   private   double   salary;  
60.   private   Date   hireDay;  
61.   }


------解决方案--------------------
要补充完成这些功能么?
// fill the staff array with three Employee objects
// raise everyone 's salary by 5%
// print out information about all Employee objects

------解决方案--------------------
你要干嘛 把这个类实现吗
------解决方案--------------------
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class EmployeeTest {
  public static void main(String[] args) {

    // fill the staff array with three Employee objects
    Employee[] emp = new Employee[3];
    emp[0] = new Employee( "Tom ", 1000.00, 1970, 4, 1);
    emp[1] = new Employee( "Jerry ", 1200.00, 1971, 5, 2);
    emp[2] = new Employee( "Kate ", 1300.00, 1972, 12, 3);

    // raise everyone 's salary by 5%
    for (int i = 0; i < emp.length; i++) {
      emp[i].raiseSalary(0.05);
    }

    // print out information about all Employee objects
    SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd ");
    for (int i = 0; i < emp.length; i++) {      
      String date = sdf.format(emp[i].getHireDay()).toString();      
      System.out.println( "============================== ");
      System.out.printf( " Employee Name: %s%n ", emp[i].getName());
      System.out.printf( "Employee Salary: %7.2f%n ", emp[i].getSalary());
      System.out.printf( " Hire Date: %s%n ", date);
    }
  }
}

class Employee {

  private String name;
  private double salary;
  private Date hireDay;

  public Employee(String n, double s, int year, int month, int day) {
    this.name = n;
    this.salary = s;
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONDAY, month - 1);
    cal.set(Calendar.DATE, day);
    this.hireDay = cal.getTime();
  }

  public String getName() {
    return this.name;
  }

  public double getSalary() {
    return this.salary;
  }

  public Date getHireDay() {
    return this.hireDay;