java程序设计(第二版)课后习题答案

来源:网络收集 时间:2025-04-29 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xuecool-com或QQ:370150219 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

//习题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(\名字:\工资:\雇佣年份:\ }//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(\

staff[1]=new Employee(\ staff[2]=new Employee(\ester\ int integerValue;

System.out.println(\ 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; intValue=-7000; longValue=200l; shortValue=20000; floatValue=9.997E-5f;

doubleValue=floatValue*floatValue;

System.out.println(\

System.out.println(\布尔类型变量flag=\ System.out.println(\字符型变量yesChar=\ System.out.println(\字节型变量finByte=\ System.out.println(\整型变量intValue=\ System.out.println(\长整型变量longValue=\ System.out.println(\短整型变量shortValue=\ System.out.println(\浮点型变量floatValue=\

System.out.println(\双精度浮点型变量doubleValue=\

}//end main() }

//习题2.9 import java.util.*; class PubTest1{ private int ivar1; private float fvar1,fvar2; public PubTest1(){ fvar2=0.0f; }

public float sum_f_I(){ fvar2=fvar1+ivar1; return fvar2; }

public void print(){

System.out.println(\ }

public void setIvar1(int ivalue){ ivar1=ivalue; }

public void setFvar1(float ivalue){ fvar1=ivalue; } }

public class PubMainTest {

public static void main(String[] args) { PubTest1 pubt1=new PubTest1(); pubt1.setIvar1(10); pubt1.setFvar1(100.02f); pubt1.sum_f_I(); pubt1.print(); } }

//习题2.10 import java.util.*; class Date { private int year; private int month; private int day;

public Date(int day, int month, int year) { //构造函数,构造方法 this.year = year; this.month = month; this.day = day;

} //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 Date

public class Teacher { String name;//教师名字

boolean sex;//性别,true表示男性 Date birth;//出生日期 String salaryID;//工资号 String depart;//教师所在系所 String posit;//教师职称 String getName() { return name; }

void setName(String name) { this.name = name; }

boolean getSex() { return sex; }

void setSex(boolean sex) { this.sex = sex; }

Date getBirth() { return birth; }

void setBirth(Date birth) { this.birth = birth; }

String getSalaryID() { return salaryID; }

void setSalaryID(String salaryID) { this.salaryID = salaryID; }

String getDepart() { return depart; }

void setDepart(String depart) { this.depart = depart; }

String getPosit() { return posit; }

void setPosit(String posit) { this.posit = posit; }

public Teacher(){

System.out.println(\父类无参数的构造方法!!!!!!!\ }//如果这里不加上这个无参数的构造方法将会出错!!!! public Teacher(String name,boolean sex,Date birth, String salaryid,String depart,String posit){ this.name=name; this.sex=sex; this.birth=birth; this.salaryID=salaryid; this.depart=depart; this.posit=posit; }//end Teacher() public void print(){

System.out.print(\ System.out.println(this.getName()); System.out.print(\ if(this.getSex()==false){ System.out.println(\女\ } else{

System.out.println(\男\ }

System.out.print(\

System.out.println(this.getBirth().getYear()+\ this.getBirth().getMonth()+\ this.getBirth().getDay()); System.out.print(\ System.out.println(this.getSalaryID()); System.out.print(\ System.out.println(this.getPosit()); System.out.print(\ System.out.println(this.getDepart()); }//end print()

public static void main(String[] args) { Date dt1=new Date(11,23,1989); Date dt2=new Date(2,6,1975);

百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典综合文库java程序设计(第二版)课后习题答案在线全文阅读。

java程序设计(第二版)课后习题答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.70edu.com/wenku/209429.html(转载请注明文章来源)
Copyright © 2020-2025 70教育网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:370150219 邮箱:370150219@qq.com
苏ICP备16052595号-17
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:7 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219