1350340122 刘光宇 实验三.docx

上传人:b****5 文档编号:2910432 上传时间:2022-11-16 格式:DOCX 页数:9 大小:16.13KB
下载 相关 举报
1350340122 刘光宇 实验三.docx_第1页
第1页 / 共9页
1350340122 刘光宇 实验三.docx_第2页
第2页 / 共9页
1350340122 刘光宇 实验三.docx_第3页
第3页 / 共9页
1350340122 刘光宇 实验三.docx_第4页
第4页 / 共9页
1350340122 刘光宇 实验三.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

1350340122 刘光宇 实验三.docx

《1350340122 刘光宇 实验三.docx》由会员分享,可在线阅读,更多相关《1350340122 刘光宇 实验三.docx(9页珍藏版)》请在冰豆网上搜索。

1350340122 刘光宇 实验三.docx

1350340122刘光宇实验三

院(系)计算机学院专业计科(嵌入式)班级13计科3班

姓名刘光宇学号1350340122同组人无

实验室S4305组号日期2015.10.14

课程Java程序设计指导教师余慧成绩

实验项目编号8103200403实验项目名称面向对象编程

一、实验目的

熟悉并掌握Java中类的定义,类的成员变量和方法的定义。

二、实验环境

WindowsXP操作系统

Eclipse

三、实验原理

使用面向对象编程中设计类的基本原则,对实验二中的BuildingHouse程序进行重构

四、算法设计

【任务一】请重构实验二中的BuildingHouse程序。

五、主要代码及说明

【任务一】

Buildinghouse.java中:

importjava.util.Scanner;

publicclassBuildHouse{

publicstaticvoidmain(String[]args){

Scannersc=newScanner(System.in);

Stringtest;

test="livingroom";

System.out.println("nowroom:

"+test);

System.out.print("Pleaseimportroomname:

");

Roomdining=newRoom("dining");

dining.decoration="Acrystalchandelier";

Roomwdlivingroom=newRoomwd("livingroom");

//livingroom.name="livingroom";

livingroom.decoration="Anantiquecarpe";

livingroom.ShowDoor("Anantiquecarpe");

Roomwdkitchen=newRoomwd("kitchen");

//kitchen.name="kitchen";

kitchen.decoration="stainlesssteelapplience";

kitchen.ShowDoor("Stainlesssteelappliance");

Outwdbackyard=newOutwd("backyard");

//backyard.name="backyard";

backyard.temperature="hot";

backyard.ShowDoor("Ascreendoor");

OutwdFrontYard=newOutwd("FrontYard");

//FrontYard.name="FrontYard";

FrontYard.temperature="nothot";

FrontYard.ShowDoor("Anoakdoorwithabrassknob");

Outsidegarden=newOutside("garden");

//garden.name="garden";

garden.temperature="nothot";

garden.aisle[0]=FrontYard;

garden.aisle[1]=backyard;

FrontYard.aisle[0]=livingroom;

FrontYard.aisle[1]=garden;

backyard.aisle[0]=kitchen;

backyard.aisle[1]=garden;

kitchen.aisle[0]=dining;

kitchen.aisle[1]=backyard;

livingroom.aisle[0]=dining;

livingroom.aisle[1]=FrontYard;

dining.aisle[0]=livingroom;

dining.aisle[1]=kitchen;

while(true)

{

Stringhouse=sc.nextLine();

if(house.equals(dining.name))

{

if(test.equals(dining.aisle[0].name)||test.equals(dining.aisle[1].name))

{

System.out.println(dining.GetDecription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

System.out.print("Pleaseimportroomname:

");

}

}

elseif(house.equals(livingroom.name))

{

if(test.equals(livingroom.aisle[0].name)||test.equals(livingroom.aisle[1].name))

{

System.out.println(livingroom.GetDecription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

System.out.print("Pleaseimportroomname:

");

}

}

elseif(house.equals(kitchen.name))

{

if(test.equals(kitchen.aisle[0].name)||test.equals(kitchen.aisle[1].name))

{

System.out.println(kitchen.GetDecription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

System.out.print("Pleaseimportroomname:

");

}

}

elseif(house.equals(backyard.name))

{

if(test.equals(backyard.aisle[0].name)||test.equals(backyard.aisle[1].name))

{

System.out.println(backyard.GetDescription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

System.out.print("Pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

}

}

elseif(house.equals(FrontYard.name))

{

if(test.equals(FrontYard.aisle[0].name)||test.equals(FrontYard.aisle[1].name))

{

System.out.println(FrontYard.GetDescription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

System.out.print("Pleaseimportroomname:

");

}

}

elseif(house.equals(garden.name))

{

if(test.equals(garden.aisle[0].name)||test.equals(garden.aisle[1].name))

{

System.out.println(garden.GetDescription());

test=house;

System.out.println("nowroom:

"+test);

System.out.print("pleaseimportroomname:

");

}

else

{

System.out.println("youcanoutcomeintheroom");

System.out.print("Pleaseimportroomname:

");

}

}

else

{

System.out.println("youimportroomnameiserror!

");

System.out.print("Pleaseimportroomname:

");

}

if(house.equals("##")){

break;

}

}

}

}

House.java中:

publicabstractclassHouse{

protectedStringname;

protectedStringdescription;

protectedHouse[]aisle=newHouse[2];

protectedStringGetDescription()

{

for(int

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

当前位置:首页 > 高等教育 > 历史学

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

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