java程序设计(辛运帏饶一梅马素霞第二版)课后习题答案.doc
文本预览下载声明
以下是《Java程序设计》(第二版)的全部课后答案,不包括简答题,概念题,只是程序设计题目。
//习题2.2
import java.util.*;
class MyDate{
private int year;
private int month;
private int day;
public MyDate(int y,int m,int d){//构造函数,构造方法
year=y;
month=m;
day=d;
}//end public MyDate(int y,int m,int d)
public int getYear(){//返回年
return year;
}//end getYear()
public int getMonth(){//返回月
return month;
}//end getMonth()
public int getDay(){//返回日
return day;
}//end getDay()
}//end class MyDate
class Employee{
private String name;
private double salary;
private MyDate hireDay;
public Employee(String n,double s,MyDate d){
name=n;
salary=s;
hireDay=d;
}//end public Employee(String n,double s,MyDate d)
public void print(){
System.out.println(名字:+name+\n工资:+salary+\n雇佣年份:+hireYear()+\n);
}//end print()
public void raiseSalary(double byPercent){
salary*=1+byPercent/100;
}//end
public int hireYear(){
return hireDay.getYear();
}
}//end class Employee
public class MyTestClass {
public static void main(String[] args) {
Employee[]staff=new Employee[3];
staff[0]=new Employee(Harry Hacker,35000,new MyDate(1989,10,1));
staff[1]=new Employee(Carl Carcker,75000,new MyDate(1987,12,15));
staff[2]=new Employee(Tony Tester,38000,new MyDate(1990,3,12));
int integerValue;
System.out.println(The information of employee are:);
for(integerValue=0;integerValue=2;integerValue++){
staff[integerValue].raiseSalary(5);
}//end for()
for(integerValue=0;integerValue=2;integerValue++){
staff[integerValue].print();
}//end for()
}//end main()
}//end class MyTestClass
//习题2.4
import java.util.*;
public class DataType {
public static void main(String[] args) {
boolean flag;
char yesChar;
byte finByte;
int intValue;
long longValue;
short shortValue;
float floatValue;
double doubleValue;
flag=true;
yesChar=y;
finByte=30;
intValu
显示全部