版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上本科生實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)課程 軟件設(shè)計(jì)與體系結(jié)構(gòu) 學(xué)院名稱 信息科學(xué)與技術(shù)學(xué)院 專業(yè)名稱 軟件工程 學(xué)生姓名 學(xué)生學(xué)號(hào) 指導(dǎo)教師 實(shí)驗(yàn)地點(diǎn) 6A502 實(shí)驗(yàn)成績(jī) 二零一五年一月十五日軟件設(shè)計(jì)與體系結(jié)構(gòu)實(shí)驗(yàn)報(bào)告摘要通過這系列的實(shí)驗(yàn)讓我們能夠在實(shí)際運(yùn)用環(huán)境中理解和掌握軟件設(shè)計(jì)與體系結(jié)構(gòu)的分析和設(shè)計(jì)方法,以及掌握面向?qū)ο笙到y(tǒng)分析和設(shè)計(jì)的UML建模語(yǔ)言,來實(shí)現(xiàn)對(duì)某一信息系統(tǒng)進(jìn)行系統(tǒng)分析和設(shè)計(jì)。關(guān)鍵詞:UML;java語(yǔ)言;算法;編程。第1章 工廠模式1.1 簡(jiǎn)單工廠模式1.1.1要求設(shè)計(jì)一個(gè)任務(wù)創(chuàng)建倉(cāng)。當(dāng)用戶在倉(cāng)門口喊一聲:“漢子!”該倉(cāng)就創(chuàng)建一個(gè)男性角色當(dāng)用戶喊“妹子!”,該倉(cāng)就
2、創(chuàng)建一個(gè)女性角色當(dāng)用戶喊“隨便!”,該倉(cāng)就隨機(jī)創(chuàng)建一個(gè)角色性別1.1.2代碼Women.javapublic class women extends SimpleFactoryvoid CreateCharator()System.out.println("已創(chuàng)建一個(gè)女性角色!");man.javapublic class man extends SimpleFactory void CreateCharator()System.out.println("已創(chuàng)建一個(gè)男性角色!");Person.javaimport java.util.Scanner;p
3、ublic class Person public static void main(String args)Scanner reader = new Scanner(System.in);System.out.println("請(qǐng)輸入你要?jiǎng)?chuàng)建的角色(“漢子”、“妹子”或“隨便”):");String s = reader.next();reader.close();if(s.equals("漢子")man men = new man();men.CreateCharator();else if(s.equals("妹子")women
4、 wm = new women();wm.CreateCharator();else if(s.equals("隨便")int n=(int)(Math.random()*10)%2);if(n = 0)man men = new man();men.CreateCharator();elsewomen wm = new women();wm.CreateCharator();SimpleFactory.javapublic abstract class SimpleFactory abstract void CreateCharator();1.1.3UML1.2 工廠模
5、式1.2.1要求設(shè)計(jì)一個(gè)游戲職業(yè)的構(gòu)造器,可以為用戶構(gòu)造不同的職業(yè)職業(yè)有,建筑師、魔法師、醫(yī)師、金工技師、廚師。請(qǐng)根據(jù)用戶傳遞的角色職業(yè)信息和姓名,為用戶生成不同的職業(yè)1.2.2代碼metalworkingTechnicians.javapublic class metalworkingTechnicians extends Gamevoid build()System.out.println("已創(chuàng)建一個(gè)金工技師角色! 名字為:"+name);magician.javapublic class magician extends Gamevoid build()System
6、.out.println("已創(chuàng)建一個(gè)魔法師角色! 名字為:"+name);Game.javapublic abstract class Game String name;abstract void build();architect .javapublic class architect extends Gamevoid build()System.out.println("已創(chuàng)建一個(gè)建筑師角色! 名字為:"+name);cook .javapublic class cook extends Gamevoid build()System.out.pri
7、ntln("已創(chuàng)建一個(gè)廚師角色! 名字為:"+name);doctor.javapublic class doctor extends Gamevoid build()System.out.println("已創(chuàng)建一個(gè)醫(yī)生角色! 名字為:"+name);Factory.javaimport java.util.Scanner;public class Factory public static void main(String args)System.out.println("請(qǐng)選擇要?jiǎng)?chuàng)建的角色:1、建筑師 2、魔法師 3、醫(yī)師 4、金工技師
8、5、廚師");int i;Scanner reader = new Scanner(System.in);i = reader.nextInt();if(i =1)architect myarchitect = new architect();System.out.print("請(qǐng)輸入角色名字:"); = reader.next();myarchitect.build();else if(i =2)magician mymagician = new magician();System.out.print("請(qǐng)輸入角色名字:
9、"); = reader.next();mymagician.build();else if(i =3)doctor mydoctor = new doctor();System.out.print("請(qǐng)輸入角色名字:"); = reader.next();mydoctor.build();else if(i =4)metalworkingTechnicians mymetalworkingTechnicians = new metalworkingTechnicians();System.out.print
10、("請(qǐng)輸入角色名字:");mymetalworkingT = reader.next();mymetalworkingTechnicians.build();else if(i =5)cook mycook = new cook();System.out.print("請(qǐng)輸入角色名字:"); = reader.next();mycook.build();elseSystem.out.println("創(chuàng)建失敗!");reader.close();1.2.3UML1.3抽象工廠模式1.
11、3.1要求為游戲人物創(chuàng)建不同的外觀分為:服飾、頭發(fā)、眼鏡、膚色、身高要求不同的職業(yè)有不同的外觀范圍,同一職業(yè)外觀相同。也可以設(shè)計(jì)成不同職業(yè)不同外觀,同一職業(yè)根據(jù)等級(jí)不同,外觀也有細(xì)微差異(如頭發(fā)長(zhǎng)短、瞳孔顏色深淺、身高高矮、服飾配飾多少的差異等等)1.3.2代碼clothes.javapublic interface clothes void Clothestype();cookBuild.javapublic class cookBuild extends Factory implements clothes,eye,hair,skin,heightpublic void Clothesty
12、pe()Clothestype = "廚師服"public void Eyecolor()Eyecolor = "黑色眼睛"public void Haircolor()Haircolor = "黑色頭發(fā)"public void Skincolor()Skincolor = "黃色皮膚"public void Heightcolor() Heightcolor = "身高177cm"void CreateClothes() System.out.println("已創(chuàng)建廚師角色!&qu
13、ot;); System.out.print(Clothestype+'t');void CreateHair() System.out.print(Haircolor+'t');void CreateEye() System.out.print(Eyecolor+'t');void CreateSkin() System.out.print(Skincolor+'t'); void CreateHeight() System.out.print(Heightcolor+'t'); doctorBuild.java
14、public class doctorBuild extends Factory implements clothes,eye,hair,skin,heightpublic void Clothestype()Clothestype = "醫(yī)生服"public void Eyecolor()Eyecolor = "藍(lán)色眼睛"public void Haircolor()Haircolor = "棕色頭發(fā)"public void Skincolor()Skincolor = "白色皮膚"public void Hei
15、ghtcolor() Heightcolor = "身高180cm"void CreateClothes() System.out.println("已創(chuàng)建廚師角色!"); System.out.print(Clothestype+'t');void CreateHair() System.out.print(Haircolor+'t');void CreateEye() System.out.print(Eyecolor+'t');void CreateSkin() System.out.print(Sk
16、incolor+'t'); void CreateHeight() System.out.print(Heightcolor+'t'); eye.javapublic interface eye void Eyecolor();Factory.javapublic abstract class Factory String Clothestype;String Eyecolor;String Haircolor;String Skincolor;String Heightcolor;abstract void CreateClothes();abstract v
17、oid CreateHair();abstract void CreateEye();abstract void CreateSkin();abstract void CreateHeight();hair.javapublic interface hair void Haircolor();height.javapublic interface height void Heightcolor();shixian.javaimport java.util.Scanner;public class shixian public static void main(String args)Scann
18、er reader = new Scanner(System.in);System.out.println("請(qǐng)選擇要選擇的角色:1、廚師 2、醫(yī)生");int i=reader.nextInt();reader.close();if(i = 1)cookBuild cook= new cookBuild();cook.Clothestype();cook.Eyecolor();cook.Haircolor();cook.Skincolor();cook.Heightcolor();cook.CreateClothes();cook.CreateHair();cook.Cr
19、eateEye();cook.CreateSkin();cook.CreateHeight();else if(i = 2)doctorBuild doctor = new doctorBuild();doctor.Clothestype();doctor.Eyecolor();doctor.Haircolor();doctor.Skincolor();doctor.Heightcolor();doctor.CreateClothes();doctor.CreateHair();doctor.CreateEye();doctor.CreateSkin();doctor.CreateHeight
20、();elseSystem.out.println("創(chuàng)建失??!請(qǐng)輸入正確的序號(hào)");skin.javapublic interface skin void Skincolor();1.3.3UML第2章 設(shè)計(jì)模式2.1單例模式2.1.1要求學(xué)號(hào)是我們每個(gè)同學(xué)的唯一標(biāo)示,要求同學(xué)們?cè)谌雽W(xué)的時(shí)候就分配學(xué)號(hào),在隨后的學(xué)習(xí)生活中,不允許分配學(xué)號(hào),只能使用該學(xué)號(hào),例如辦理圖書證,辦理飯卡,選課等活動(dòng)。要求采用該機(jī)制,實(shí)現(xiàn)學(xué)號(hào)的單例2.1.2代碼public class StudentCard String str;private static StudentCard stucard
21、=null;private StudentCard()public synchronized void setStudentCardNo(String str1)str=str1;System.out.println("卡號(hào):"+str);public String getStudentCardNo()return str;public void usecard(String str2)if(str2.equals("借書") System.out.println();System.out.println("現(xiàn)在執(zhí)行借書功能,請(qǐng)按要求操作。&q
22、uot;);System.out.println("注意:一次最多只能借20本書,工具書不外借,借書日期為60天,到期可以續(xù)借。");if(str2.equals("選課")System.out.println();System.out.println("現(xiàn)在執(zhí)行選課功能,請(qǐng)安要求操作。");System.out.println("注意:選修課最多只能選3門,多選或錯(cuò)選的課程將會(huì)被系統(tǒng)清理。");if(str2.equals("充卡")System.out.println();System.ou
23、t.println("現(xiàn)在執(zhí)行充卡功能,請(qǐng)安要求操作。");System.out.println("注意:請(qǐng)保管好自己的飯卡,如果丟失請(qǐng)立即掛失,以免不必要的損失。");public static StudentCard getStuCard()if(stucard=null)stucard=new StudentCard();stucard.setStudentCardNo("4 姓名:楊鶴 學(xué)院:信息科學(xué)與技術(shù)學(xué)院 專業(yè):軟件工程 ");return stucard;MainTest.javapublic class test p
24、ublic static void main(String args)StudentCard card1=StudentCard.getStuCard();card1.usecard("借書");card1.usecard("選課");card1.usecard("充卡");2.1.3UML2.2生成器模式2.2.1要求KFC點(diǎn)餐足球教練:在一場(chǎng)足球比賽中有各種的布陣方法(442,4231,433);教練在開場(chǎng)比賽之前確定陣型,比賽中可以隨時(shí)暫停更換隊(duì)形;當(dāng)有新隊(duì)型產(chǎn)生的時(shí)候,可以很容易讓教練學(xué)會(huì)新的隊(duì)形并使用。2.2.2代碼pack
25、age KFC;public class Meal String food;String drink;void setFood(String food)this.food = food;void setDrink(String drink)this.drink = drink; String getFood()return food;String getDrink()return drink;package KFC;public abstract class MealBuilder Meal meal = new Meal();abstract void buildFood();abstrac
26、t void buildDrink();Meal getMeal()return meal;package KFC;public class subMealBuilderA extends MealBuildervoid buildFood()meal.setFood("A,food");void buildDrink()meal.setDrink("A.drink");package KFC;public class subMealBuilderB extends MealBuildervoid buildFood()meal.setFood(&quo
27、t;B.food");void buildDrink()meal.setDrink("B.drink");package KFC;public class Waiter MealBuilder mb;void setMealBuilder(MealBuilder mb)this.mb = mb;Meal construct()mb.buildDrink();mb.buildFood();return mb.getMeal();package KFC;import java.util.Scanner;public class test public static v
28、oid main(String args)MealBuilder s;Waiter waiter = new Waiter();System.out.println("選擇套餐類型:A或B");Scanner reader = new Scanner(System.in);String type = reader.next();reader.close();if(type.equals("A")|type.equals("a")s=new subMealBuilderA();elses = new subMealBuilderB();
29、waiter.setMealBuilder(s);System.out.println(waiter.construct().getDrink()+'t'+waiter.construct().getFood();Footballimport java.util.Scanner;public class Build extends TypeString a;void BuildType()Scanner reader = new Scanner(System.in);String s;System.out.println("請(qǐng)教練確定隊(duì)形:");s = re
30、ader.next();Type.setType(s);System.out.println("隊(duì)形"+Type.getType();System.out.println("更換隊(duì)形?");a = reader.next();reader.close();public class FootballCoach String Type;void setType(String UType)Type = UType;String getType()return Type;public abstract class Type FootballCoach Type
31、= new FootballCoach();abstract void BuildType();public class test public static void main(String argsp)boolean answer = false;Build m = new Build();dom.BuildType();if(m.a.equals("y")|m.a.equals("Y")answer = true;elseanswer = false;while(answer);2.2.3UML2.3原型模式2.3.1要求為每個(gè)報(bào)道的新同學(xué)設(shè)計(jì)一個(gè)
32、原型,新生報(bào)到的時(shí)候進(jìn)行原型復(fù)制新生可以修改部分參數(shù),不會(huì)影響其他原型拷貝2.3.2代碼public class StudentF implements CloneableString name = "zhang",age = "18",sex = "男",classN = "00"public Object clone()Object object = null;tryobject = super.clone();catch(CloneNotSupportedException exception)System.
33、err.println("Not support cloneable");return object;public void setName(String n)name = n;public void setAge(String a)age = a;public void setSex(String s)sex = s;public void setClassN(String c)classN = c;public void show()System.out.println(name+'t'+age+'t'+sex+'t'+c
34、lassN);public class test public static void main(String args)StudentF student0 = new StudentF();student0.show();StudentF student1 = new StudentF();student1.setName("li");StudentF student2 = new StudentF();student2 = (StudentF)student1.clone();student2.show();student2.setSex("女");
35、student2.show();2.3.3UML2.4適配器模式2.4.1要求為電源插座(工具箱)開發(fā)一個(gè)適配器,使該插頭可以同時(shí)為交流電設(shè)備(三相、兩相)供電為該電源插座(工具箱)開發(fā)另一個(gè)適配器,可以為USB設(shè)備供電。分別采用類適配器和對(duì)象適配器實(shí)現(xiàn)2.4.2代碼public class toolBox public void electricityOut()System.out.println("充電中");public class Adapter extends toolBox implements equipmentpublic void electricityI
36、n()electricityOut();public interface equipment public abstract void electricityIn();public class test public static void main(String args)Adapter adapter = new Adapter();adapter.electricityIn();2public class Adapter extends USBprivate toolBox box;public Adapter(toolBox box)this.box = box;public void
37、 electricityIn()box.electricityOut();public class toolBox public void electricityOut()System.out.println("充電中");public class USB public void electricityIn();public class test public static void main(String args)toolBox b = new toolBox();Adapter usb = new Adapter(b); usb.electricityIn();2.4
38、.3UML2.5組合模式2.5.1要求人品最好的劉老師需要有人幫忙完成一項(xiàng)工作,但是她不知道誰可以不幫忙,于是將該指令傳達(dá)給大班班長(zhǎng)。大班班長(zhǎng)、分班班長(zhǎng)、寢室長(zhǎng)、寢室成員,逐層詢問查找,工作會(huì)落實(shí)到具體的成員身上。在查找過程中,不管是中間的管理人員,還是后面的執(zhí)行人員,都無差別地執(zhí)行相應(yīng)程序請(qǐng)將該班級(jí)模型描述出來,以便以后劉老師無差別,不用思考地分配其他的任務(wù)。2.5.2代碼package Client;import Component.*;import Composite.*;import Leaf.*;public class Client public static void main(
39、String args) MyElement element1=new ChiefMonitor(); element1.clean(); element1.newoperation(); MyElement element2=new Monitor(); MyElement element3=new DormitoryChief(); MyElement element4=new DormitoryMember(); ChiefMonitor element5=new ChiefMonitor(); element5.add(element2); element5.add(element3)
40、; element5.add(element4); element5.operation(); package Component;public abstract class MyElement public abstract void clean();public abstract void newoperation();package Composite;import java.util.ArrayList;import Component.*;public class ChiefMonitor extends MyElementprivate ArrayList list = new A
41、rrayList();public void clean()System.out.println("*");System.out.println("我是大班班長(zhǎng),我在為劉老師檫黑板。");public void newoperation()System.out.println("我是大班班長(zhǎng),我還能為劉老師做其它的事情。");System.out.println("*");public void add(MyElement element)list.add(element);public void remove(M
42、yElement element)list.remove(element);public void operation()for(Object obj:list)(MyElement)obj).clean();(MyElement)obj).newoperation();package Leaf;import Component.*;public class DormitoryChief extends MyElementpublic void clean()System.out.println("*");System.out.println("我是寢室長(zhǎng),我在為
43、劉老師收作業(yè)。");public void newoperation()System.out.println("我是寢室長(zhǎng),我還能為劉老師做其它的事情。");System.out.println("*");package Leaf;import Component.*;public class DormitoryMember extends MyElement public void clean()System.out.println("*");System.out.println("我是寢室成員,我在為劉老師收作
44、業(yè)。");public void newoperation()System.out.println("我是寢室成員,我還能為劉老師做其它的事情。");System.out.println("*");package Leaf;import Component.*;public class Monitor extends MyElementpublic void clean()System.out.println("*");System.out.println("我是分班班長(zhǎng),我在為劉老師收作業(yè)。");pub
45、lic void newoperation()System.out.println("我是分班班長(zhǎng),我還能為劉老師做其它的事情。");System.out.println("*");2.5.3UML2.6代理模式2.6.1要求冰淇淋廠商可以生產(chǎn)冰淇淋、銷售冰淇淋,查詢冰淇淋價(jià)格冰淇淋零售商是冰淇淋的代理,他對(duì)外代理的冰淇淋廠商服務(wù)為:價(jià)格查詢。冰淇淋銷售。冰淇淋作為一個(gè)獨(dú)立對(duì)象,包含5種不同種類用戶通過零售商完成冰淇淋購(gòu)買在代理行為中,冰淇淋零售商做了額外行為提價(jià):如查詢價(jià)格為3元的冰淇淋,代理行為后價(jià)格變?yōu)?元。銷售統(tǒng)計(jì):按照不同冰淇淋種類統(tǒng)計(jì)銷售(數(shù)
46、量或總)2.6.2代碼package daili;public class factory implements icecreamString name ="a","b","c","d","e"int price = 1,2,3,4,5;public void produce(String s)public void seal(String s)public int chaxun(String s)boolean m = true;int mm = 0;for(int i=0;i<5;i+
47、)if(s.equals(namei)m=true;mm= pricei;break;elsem=false;if(!m)mm = 0;return mm;package daili;public interface icecream abstract void seal(String s);abstract int chaxun(String s);package daili;public class store implements icecreamfactory fac = new factory();int Sealing=0,0,0,0,0;public void seal(Stri
48、ng s)for(int i = 0;i<5;i+)if(s.equals(i)Sealingi+;public int chaxun(String s)int p=fac.chaxun(s);return p+1;public void Number(String s)for(int i = 0;i<5;i+)if(s.equals(i)System.out.println("已銷售"+s+Sealingi+ "個(gè)");package daili;public class test public static
49、 void main(String args)store s = new store();s.seal("a");s.seal("a");s.seal("d");s.seal("b");s.seal("c");System.out.println(s.chaxun("a");s.Number("a");2.6.3UML2.7外觀模式2.7.1要求預(yù)售信息發(fā)布(用戶提供房屋參數(shù),中間人完成廣告設(shè)計(jì)發(fā)布)聯(lián)系買家(用戶提供聯(lián)系方式,中間人完成信息發(fā)布,接聽電話
50、,過濾電話,信息轉(zhuǎn)達(dá))協(xié)商看房(用戶提供鑰匙,中間人完成帶客人看房的操作)協(xié)商價(jià)格(用戶提供價(jià)格區(qū)間,中間人幫用戶完成議價(jià))客人只和中間人聯(lián)系,不關(guān)心后面的工作實(shí)現(xiàn)2.7.2代碼package waiguan;public class car public void drive()System.out.println("開車");package waiguan;public class middle tv TV = new tv();car CAR = new car();phone PHONE = new phone();mouse MOUSE = new mouse()
51、;public void information(String s)TV.on();public void contact(String number)PHONE.call();public void look(String key)CAR.drive();public void price(double min,double max)MOUSE.talk();package waiguan;public class mouse public void talk()System.out.println("正在談價(jià)格");package waiguan;public class phone public void call()System.out.println("打電話");package waiguan;public class test public static void main(String args)middle m = new middle(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 家庭教育策略塑造孩子情感發(fā)展的關(guān)鍵
- 當(dāng)代學(xué)生對(duì)于職場(chǎng)與人文教育的認(rèn)識(shí)與行動(dòng)
- 年度互聯(lián)網(wǎng)廣告代理服務(wù)合同
- 家教新視角如何利用游戲化方法促進(jìn)心理健康
- 美團(tuán)商戶入駐服務(wù)合同
- 小學(xué)生語(yǔ)言表達(dá)能力培養(yǎng)方案
- 教育機(jī)構(gòu)中個(gè)性化服務(wù)的實(shí)施與效果
- 單位租賃員工車輛協(xié)議書
- 2024年互聯(lián)網(wǎng)金融平臺(tái)服務(wù)協(xié)議
- 回遷房買賣合同的
- 2025寒假散學(xué)典禮(休業(yè)式)上校長(zhǎng)精彩講話:以董宇輝的創(chuàng)新、羅振宇的堅(jiān)持、馬龍的熱愛啟迪未來
- 安徽省示范高中2024-2025學(xué)年高一(上)期末綜合測(cè)試物理試卷(含答案)
- 安徽省合肥市包河區(qū)2023-2024學(xué)年九年級(jí)上學(xué)期期末化學(xué)試題
- 《酸堿罐區(qū)設(shè)計(jì)規(guī)范》編制說明
- PMC主管年終總結(jié)報(bào)告
- 售樓部保安管理培訓(xùn)
- 倉(cāng)儲(chǔ)培訓(xùn)課件模板
- 2025屆高考地理一輪復(fù)習(xí)第七講水循環(huán)與洋流自主練含解析
- GB/T 44914-2024和田玉分級(jí)
- 2024年度企業(yè)入駐跨境電商孵化基地合作協(xié)議3篇
- 《形勢(shì)與政策》課程標(biāo)準(zhǔn)
評(píng)論
0/150
提交評(píng)論