java语言程序设计基础篇第十版第十三章练习答案Word下载.docx

上传人:b****1 文档编号:14057185 上传时间:2022-10-17 格式:DOCX 页数:43 大小:23.21KB
下载 相关 举报
java语言程序设计基础篇第十版第十三章练习答案Word下载.docx_第1页
第1页 / 共43页
java语言程序设计基础篇第十版第十三章练习答案Word下载.docx_第2页
第2页 / 共43页
java语言程序设计基础篇第十版第十三章练习答案Word下载.docx_第3页
第3页 / 共43页
java语言程序设计基础篇第十版第十三章练习答案Word下载.docx_第4页
第4页 / 共43页
java语言程序设计基础篇第十版第十三章练习答案Word下载.docx_第5页
第5页 / 共43页
点击查看更多>>
下载资源
资源描述

java语言程序设计基础篇第十版第十三章练习答案Word下载.docx

《java语言程序设计基础篇第十版第十三章练习答案Word下载.docx》由会员分享,可在线阅读,更多相关《java语言程序设计基础篇第十版第十三章练习答案Word下载.docx(43页珍藏版)》请在冰豆网上搜索。

java语言程序设计基础篇第十版第十三章练习答案Word下载.docx

}

}

classTriangleNewextendsGeometricObject{

privatedoubleside1=1.0,side2=1.0,side3=1.0;

/**Constructor*/

publicTriangleNew(){

publicTriangleNew(doubleside1,doubleside2,doubleside3){

this.side1=side1;

this.side2=side2;

this.side3=side3;

/**ImplementtheabstractmethodfindAreainGeometricObject*/

publicdoublegetArea(){

doubles=(side1+side2+side3)/2;

returnMath.sqrt(s*(s-side1)*(s-side2)*(s-side3));

/**ImplementtheabstractmethodfindCircumferencein

*GeometricObject

**/

publicdoublegetPerimeter(){

returnside1+side2+side3;

@Override

publicStringtoString(){

//Implementittoreturnthethreesides

return"

TriangleNew:

side1="

+side1+"

side2="

+side2+

"

side3="

+side3;

02

importjava.util.ArrayList;

publicclassExercise13_02{

ArrayList<

Number>

list=newArrayList<

();

list.add(14);

list.add(24);

list.add(4);

list.add(42);

list.add(5);

shuffle(list);

for(inti=0;

i<

list.size();

i++)

System.out.print(list.get(i)+"

publicstaticvoidshuffle(ArrayList<

list){

list.size()-1;

i++){

intindex=(int)(Math.random()*list.size());

Numbertemp=list.get(i);

list.set(i,list.get(index));

list.set(index,temp);

03

publicclassExercise13_03{

sort(list);

publicstaticvoidsort(ArrayList<

//Findtheminimuminthelist[i..list.length-1]

NumbercurrentMin=list.get(i);

intcurrentMinIndex=i;

for(intj=i+1;

j<

j++){

if(currentMin.doubleValue()>

list.get(j).doubleValue()){

currentMin=list.get(j);

currentMinIndex=j;

//S(i)withlist.get(currentMinIndex)ifnecessary;

if(currentMinIndex!

=i){

list.set(currentMinIndex,list.get(i));

list.set(i,currentMin);

04

importjava.util.*;

publicclassExercise13_04{

staticMyCalendarcalendar=newMyCalendar();

intmonth=calendar.get(MyCalendar.MONTH)+1;

intyear=calendar.get(MyCalendar.YEAR);

if(args.length>

2)

UsagejavaExercise13_04monthyear"

elseif(args.length==2){

//useuser-definedmonthandyear

year=Integer.parseInt(args[1]);

month=Integer.parseInt(args[0]);

calendar.set(Calendar.YEAR,year);

calendar.set(Calendar.MONTH,month-1);

elseif(args.length==1){

//useuser-definedmonthforthecurrentyear

calendar.set(Calendar.MONTH,month-1);

//setdatetothefirstdayinamonth

calendar.set(Calendar.DATE,1);

//printcalendarforthemonth

printMonth(year,month);

staticvoidprintMonth(intyear,intmonth){

//getstartdayoftheweekforthefirstdateinthemonth

intstartDay=getStartDay();

//getnumberofdaysinthemonth

intnumOfDaysInMonth=calendar.daysInMonth();

//printheadings

printMonthTitle(year,month);

//printbody

printMonthBody(startDay,numOfDaysInMonth);

staticintgetStartDay(){

returncalendar.get(Calendar.DAY_OF_WEEK);

staticvoidprintMonthBody(intstartDay,intnumOfDaysInMonth){

//printpaddingspacebeforethefirstdayofthemonth

inti=0;

for(i=0;

startDay-1;

i++)

System.out.print("

for(i=1;

=numOfDaysInMonth;

if(i<

10)

+i);

else

if((i+startDay-1)%7==0)

System.out.println();

"

staticvoidprintMonthTitle(intyear,intmonth){

+calendar.getMonthName()+"

"

+year);

-----------------------------"

SunMonTueWedThuFriSat"

05

publicclassExercise13_05{

//Mainmethod

//Createtwocomparablecircles

Circle1circle1=newCircle1(5);

Circle1circle2=newCircle1(4);

//Displaythemaxcircle

Circle1circle=(Circle1)GeometricObject1.max(circle1,circle2);

Themaxcircle'

sradiusis"

+circle

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 教学研究 > 教学计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1