




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、液海工曇浣針算機工程巻院實驗報告書課程名:面向?qū)ο蟪绦蛟O計 a題目:實驗二java面向?qū)ο缶幊坛醪?班 級:軟嵌151學號:2015123352姓名:韓吉_評語:一. 實驗h的(1)通過實驗,進一步掌握類的定義,尤英是類中方法(包含構(gòu)造方法)的定義。掌握對象的創(chuàng)建方法及對 彖成員變量和方法的調(diào)用;(2)通過編寫圖形界而的程序,完成對彖的創(chuàng)建和調(diào)用;(3)能夠通過類圖來描述 程序中類的結(jié)構(gòu)。二. 實驗內(nèi)容及要求(1)定義教師類teacher,包含屬性工號,姓名,性別,所在部門,職稱,職位,專業(yè),學歷;定義若干個 構(gòu)造方法,完成對象的各種初始化需要;定義若干個分別能夠獲取和修改成員變量的方法,如獲
2、取工號/ 修改工號;獲取學歷/修改學歷等;定義tostringo方法,能夠輸出教師的所冇相關信息。"0分)(2)編寫字符界面的程序,能夠創(chuàng)建若干個教師對彖,并輸出教師的相關信息;(20分)(3)要求在報告中能夠畫出類圖來描述類的結(jié)構(gòu)(15分)(4)編寫圖形界面的程序,能夠創(chuàng)建若干個教師對象,并輸出教師的相關信息。(25分)可以參照實驗指導書中第二個實驗的最后一個程序示例。三. 實驗步驟public class teacher string number;/工號string teachername;/姓名int ago;/年齡string sex;/性別string degree;/學
3、位string title;/職稱string position;/職位string depart;/部門string major;/專業(yè)static string collegename ="淮海工學院"tecicher(string number) this.numbcr = numbcr;teacher (string number, string teachername) this(number);this .teacher name = teacherncime;teacher (string number,string teachernan© int
4、age) this(number, teachorname);this age = age;)teacher (string number,string teachernan© int age, string sex) this(number, teachername, age);this sex 二 sex;)teacher (string number,string teachername, int age,string sex,string degree) this (number, teachername, age, sex);this.degree = degree;tea
5、cher (string number, string teachername, intage, string sex, string degree, string title) this (number, teacher name, age, sex, degree);teacher (string number, string teachername, int age, string sex,string degree, string title,string position)this (number, tecichername, age, sex, degree, title);thi
6、s.position = position;)teacher (string number,string teachername, int age,string sex,string degree,string title,string position, string depart)this (number, teachernamc, age, sex, degree, title, posit i on);this.depart = depart;teacher (string number, string teacherruune, int cige, string sex, strin
7、g degree, string title, string position, string depart, string major)this( nu mber, teacher name, age, sex, degree, title, pos i t i on, depart);thismajor = major;)public void setdegree(string newdegree)degree = newdegree:public void settitle(string newtitie)title = newtitlc;public void setposition
8、(string newpos i t i on)position 二 newposition;public void setdepart(string newdepart)depart = n ewdepcirt;public static string getcollegenameo return collegename;)public static voidsetcollegename(string newcollegename)col 1egename=newcol1egename;)public string tostringo return "工號:"+ n um
9、ber + "姓名:"+ tcachername + "年齡:"+ ago + "性別:"+"” + sex + “;學位:"+ degree + 專業(yè):"+ major + ":職稱:"+ title +import java uti1 seanner;public class testteacherpublic static void main(string argsj)int count=0;scanner scanner二new scanner(system, in);teac
10、her teachers 二new teacherl80:/創(chuàng)建teacher對象,表示汪老師teacher wang = new teacher ("1996000021"汪前進",45,"男",“碩士“,"軟件工程","副教授","系主任,"軟件工程系");teacherscount+ = wang;/創(chuàng)建teacher對象,表示張老師teacher zhang = new teecher ("2006000037","張鍵",38
11、,"男","博士","計算機彼件","副教授",“處長",”計算機科學系);teacherscount+ = zhang;/創(chuàng)建teacher對象,表示董老師teeicher dong 二 new teacher ("1981000038","董劍利",58,"男","碩士","數(shù)據(jù)結(jié)構(gòu)","教授”,"班主任,軟件工程系);teacherscount+ = dong;/創(chuàng)建teacher
12、對象,表示戴老師teacher dai = new teacher("2008000053","戴志強",40,"男",”博士","機械自動化","副教授",副院長",機械工程系“);/創(chuàng)建teacher対象,表示樊老師teacher fan = new teacher ("2002000018"/樊玲",35,"女",”碩士","法學","講師","輔導員,&quo
13、t;軟件工程系");letichers count+ = bn;/創(chuàng)建teacher對象,表示李老師teacher li = new teacher("2009000035","李志敏",34,"女","博士","船舶與海洋",”副教授","副院長","海洋工程系");teacherscount+ = li;/輸出所有的教師的信息count;for(ini i=0;i <= count;i+)system out println(
14、teachersij);/以下按姓名查找老師system, out. print in ("請輸入待查找的老師姓名:");while (scanner hasnextline0)boolecin find = fcilse;string teachernamc = scanncr.nextlinc();for(int i=0;i <= count;i+)if (teachersi j teacherntim e. con tains (teacherntime)find二true;system oul. println(jjcjlj,z+teachcrnamc);sy
15、stem out, println(teachersi);)if(find=falsc)system, out. print!n("未找到該教師! !");)public classteacherstringtno;/教師工號stringtname;/教師姓名intage;/年齡stringt sex;性別stringtdegree;學位stringttitle;/職稱stringtdept;所在部門staticstring collegename=u淮海工學院/定義了若干個構(gòu)造函數(shù),相互可以調(diào)用teacher(string tno) this.tno二tno;teache
16、r(string tno,string tname) this(tno);this>tname=tname;teacher(string tno,string tnameint age) this(tno,tname);this.age=age;teacher(string tno,string this(tno,tname,age);this.tsex=tsex;tname,intage,stringt sex)teacher(string tno,string this(tno,tname,age,tsex); t his> tdegrez td egree;age,strin
17、gtsexstringtdegree)teacher(strying tno,string tnameint ttitle)this(tno,tname,agetsexdegree);thisage.stringtsexstringt degrees tringtsexstringt degrees tringteacher(string tno,string tnameint agestring ttitlestring tdept)this(tno,tname,age,tsex,tdegree,ttitle);this.tdept二tdept;public voidsetdegree(st
18、ring newdegree)tdegree=newdegree;ttitle=newtitie;public static string getcollegename()return collegename;public static voidsetcollegename(string newcollegename)collegename=newcollegename;public stringtostring()return “工號:"+tno+h;姓名:,+tname+n;年齡:,+age+h;性別:,'+tsex+,'學位:"+tdegree+&qu
19、ot;n職稱:"+ttitle+"所在部門”+tdept+"所在大學"十collegename; import java.awt*;import javax.swing.*;import javaawtevent*;class myframe extends dframe implements actionlistenerjlabel lbltnolbltname,lbltage?lbltsex?lbltdegree?lblttitle?lbltdept;dtextfieldtxttno,txttnametxttage,txttsextxttdegree
20、txtttitle,txttdept;jbu tton btn crea te,btn searchtn showall;jlabel prompt;3textareajta;buttongroup group = new buttongroup();jradiobutton radiol = new jradiobutton("男”);dradiobutton radio2 = new 3radiobutton(h女”);teacher teachers=new teacher80; int count=0;myframe()settitle(n創(chuàng)建教師對象,并查找“);setla
21、yout(new flowlayout();setdefaultclose0peration(3frame.exi70/_cl05e);lbltno=new j label ("請輸入工號:”);txttno=new 3textfield(10);add(lbltno); add(txttno);lbltname=new 3label("請輸入姓名:”);txttname=new jtextfield(lo);add(lbltname); add(txttname);lbltage=new 3label("請輸入年齡:”);txttage=new 3textfie
22、ld(10);add(lbltage); add(txttage);/lbltsex=new 3label(n請輸入性別:”);/txttsex=new 3textfield(10);/add(lbltsex); add(txttsex);add(new j label (m 性別:”);groupadd(“adiol);group.add(radio2);add(radiol);add(radio2);lbltdegree=new j label ("請輸入學位:”);txttdegree=new 3textfield(10);add(lbltdegree); add(txttde
23、gree);lblttitle=new j label ("請輸入職稱:”);txtttitle=new jtextfield(lo);add(lblttitle); add(txtttitle);lbltdept=new 3label("請輸入部門:txttdept=new jtextfield(lo);add(lbltdept); add(txttdept);btncreate=new dbutton("創(chuàng)建教師");btnsearch=new 3button("按姓名查詢教師”); btnshowall=new j button (”顯示
24、所有教師”);add(b tn create);add(bt nseanchmdckbt nshowall);prompt二new j label(h”);jta=new jtextarea(40>60);add(prompt);add(jta);btncreate.addactionlistener(this);btnsearch.addactionlistener(this);btnshowall.addactionlistener(this);public void actionperformed(actionevent e) if(e.getsource() = btncreat
25、e)string sex = new string();if (radiolisselected()sex = radiol.gettext().tostring();elsesex = radio2.gettext().tostring();teacher teacher = new teacher(txttno.gettext(),txttname.gettext(), integer.parselnt(txttagegettext(), sex, txttdegreegettext(), txtttitlegettext(), txttdept.gettext();teachersfco
26、unt+ = teacher;promp t.settext(h 成功創(chuàng)建,+ ”第,+ count + ”個教師!”);if(e.getsource() = btnshowall && count > 0)jta.settext(n ");for(int i = 0; i < count; i+)jta.append(teachersi + ”n”);if(e.getsouce() = btnsearch)jta.settext(h ”);boolean find = false;string teachername = txttname>gett
27、ext();for(int i = 0; i < count; i+)if(teachersi.tname.equals(teachername)find = true;prompt .settext("扌戈到,+ teachername);jta.append(teachersi + ”n”);if(find = false)prompt.settext(h未找到該教師! !”);public class testteacherpublic static void maiixstting args) myframe mf=new myframe();mf.setsize(80
28、0,600);mfsetvisible(true);四.實驗結(jié)果(請自己補充完整)bb c:wjndowssysxem32cmd.exe x匸號:)996000021:姓名:汪前進;年齡:45;性別:男:學位:碩士;專業(yè):軟件工程系:職稱:軟件工程:職位:副教授所在部門:系主任:所在大 英誰海丁學熒l4:2006000037:tt名:張fit:年齡:38:性別:男:學位:博士:專業(yè):計算機科學系:職稱:計算機便件:職位:jm教授所在郵門:處長:所在大 護:隹海工學安w號1981000038:姓名:釐劍和:年齡:58:性別:男;學位傾士:專業(yè):軟件工程系:職稱:數(shù)擔結(jié)構(gòu);職位:教授所在鄒門:班主
29、任:所在大學 隹海工學院匸號:2008000053名:戴志強:年齡:40:性別:男:學位:博士:專業(yè):機械工程系:職稱:機械自動化:職位:劃教授祈在部門:院長:所在 矢學海海工學皮匸號:2002000018:姓名:樊玲:年齢:35:性別:女;學位:碩士:專業(yè):軟件工程系:職稱:法學:譏位:講師所在郵門:輔導員:所在大學淮海工匸號:2009000035名:李志敏:年齡:34:性別:女:學位:博士:專業(yè):海洋工程系:職禰:船鉅與薄洋:職位:副教授折在部門:剛険長:所在 矢學淮海工學険育輸入待査找的老師姓名:卡找到該教師!!釜志敏戈到李志敏匸號:2009000035:姓名:李志敏:年齡:34:性別:
30、女:學位:博士:專業(yè):海洋工程系:職稱:船鉅與海洋:職位:劇教授所在部門:廐長:所在 尢學浪海工學反回創(chuàng)建教怖對金,并査找-xo禺女褊絡入學位:満松工號:12012|濟希入處名:|錢佳|曲入年: |28派士|漕僥入15稱劃幣| imr入?yún)s門藥學顯示所|放奔成帕權第2個教奔!!!工號10121m名李強年齡45性別男序位t«±.ir怖副披授所衣祁門計算機所在大學滾海工拆 工e 12012雄名妙佳年齡28性別女學位碩士;史稱講師所蠱祁門藥學:所在大學濃海工視創(chuàng)建教師對象.開查找禱笛入工號:)12012性別:c男女請輸入學位:碩士溝林入職稱:講師満絹入部門:藥學創(chuàng)雄教師請輸入姓名:
31、錢佳諂輸入年粘:28顯示所有教脯找工惟佳工號12012姓名錢佳:年齡28性別女學位碩士. 取稱講師所左部門藥學:所蠱大學淮海工視五.實驗的分析體會(請口己補充完整)對于此次試驗,本來要求較簡單,老師也把代碼發(fā)給學生,但我本來想將職稱之類弄成下拉菜單,但做好后發(fā)現(xiàn)無法讀入選中的內(nèi)容,我也不會。如下:回創(chuàng)建敎師對衆(zhòng)開查找一 x般入工號:1011滴輅入處名:林開合濟輸入年話:e2性別:禺c女學位:w±載稱:所盒部門:;商學系按蛀名査洵報師顯示莎有放師成功創(chuàng)建第1個斂壞三 工號名林開會年詁52性別null#位null.史稱null所左祁門null所在大學淮海工祝附上錯誤代碼:import j
32、avaawt*;import javax.swing.*;import javaawtevent*;import javaawtcheckboxgnoup;import javaawtcheckbox;import javaawtcheckboxmenultem;class myframe extends dframe implements actionlistener/ string txttsextxttdegreetxtttitletxttdept;dlabel lbltnojbltname,lbltage;3textfield txttno,txttnametxttage;jbu tt
33、on btn create., btn search, bt nshowall;dlabel prompt;dtextarea jta;jcombobox comboxl,combox2,combox3;/下拉菜單buttongroup group;dradiobutton radioleradio2;teacherteachers=new teacher80;int count=0;myframe()settitle(n創(chuàng)建教師對象,并查找“);setlayout(new flowlayout();setdefaultclose0peration(3frame.fxi70/v-cl0se);
34、lbltno=new 3label(f,請輸入工號:");txttno=new 3textfield(10); add(lbltno); add(txttno);lbltname=new 3label(h請輸入姓名:”);txttname=new 3textfield(10); add(lbltname); add(txttname);lbltage=new 3label("請輸入年齡:”);txttage=new 3textfield(10); add(lbltage); add(txttage);add(new jlabel(n性別:”);group = new but
35、tongroup();radiol = new jradiobutton("男”);radio2 = new 3radiobutton("女”);groupadd(radiol);group.add(radio2);add(radiol);add(radio2);/txttsex = group.getselection()tostring();add(new j label (m 學位:”);comboxl = new jcomboboxq;comboxl.addltemc'本科”);comboxl.addltemc1 碩士 ”);comboxl.addltemc
36、1 博士 ”);add(comboxl);/txttdegree = comboxlegetselectedltem()tostring();add(new j label (n 職稱:");combox2 = new jcomboboxq;combox2.addltemc' 助教 ”);combox2additem(” 講師”);combox2.addltemc' 副教授 ”);combox2additem(” 教授 ”);add(combox2);/ txtttitle = combox2.getselectedltem().tostring();add(new 3label(h所在部門:combox3 = new jcomboboxq;combox3additgm(”計算機工程系”);combox3additem(” 機械工程系 ”);combox3 additem(” 法學系 ”);combox3additem(” 藥學系”);combox3addltem(" 電子系 ”);comboxm.addltemc' 商學系 ”);combox3.addltemc1 藝術系 ”);combox3.addltemc* 文學系 ”);combox3addltem(” 外語系 ”);combox3addlte
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 西交利物浦大學《規(guī)劃作品述評》2023-2024學年第二學期期末試卷
- 2024四川遂寧市射洪市財政局市屬國有企業(yè)招聘考生及筆試參考題庫附帶答案詳解
- 江蘇理工學院《視覺設計》2023-2024學年第一學期期末試卷
- 沈陽航空職業(yè)技術學院《機器人操作系統(tǒng)及應用》2023-2024學年第二學期期末試卷
- 紅河職業(yè)技術學院《基礎醫(yī)學前沿技術》2023-2024學年第一學期期末試卷
- 2025年河南省新鄉(xiāng)輝縣聯(lián)考全國中考大聯(lián)考信息卷:生物試題試卷(2)含解析
- 浙江理工大學《工程力學Ⅰ》2023-2024學年第二學期期末試卷
- 2024年日照鹽糧集團有限公司公開招聘工作人員考試筆試及人員筆試參考題庫附帶答案詳解
- 2024年中廣核環(huán)保產(chǎn)業(yè)有限公司招聘7人筆試參考題庫附帶答案詳解
- 2025年中考數(shù)學總復習49 微專題 代數(shù)推理試題 學案(含答案)
- 一年級語文雨點兒-教學課件【希沃白板初階培訓結(jié)營大作業(yè)】
- 衛(wèi)生部手術分級目錄(2023年1月份修訂)
- GA/T 1323-2016基于熒光聚合物傳感技術的痕量炸藥探測儀通用技術要求
- 跨太平洋伙伴關系協(xié)議(TPP)
- 鋼棧橋施工監(jiān)理細則
- 優(yōu)秀員工榮譽證書模板
- 金蝶PLM詳細介紹
- 湖南文藝出版社小學六年級下冊音樂全冊教案
- 高中語文《祝福》“誰是兇手”系列之祥林嫂死亡事件《祝?!诽骄渴綄W習(教學課件) 課件
- 中國十大階層的劃分課件
- 中考數(shù)學分式與分式方程計算題(附答案)
評論
0/150
提交評論