復習實驗報告_第1頁
復習實驗報告_第2頁
復習實驗報告_第3頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、中北大學軟件學院實 驗報告專業(yè) 軟件工程 JAVA 面向?qū)ο蟪绦蛟O(shè)計課程名稱 1314010934學號 周鑫姓名輔導教師何志英成績 實驗日期2015 年 4 月 8實驗時間下午 4:005:301 實驗名稱 :實驗二 Java 語言基礎(chǔ)訓練2、實驗目的1、學習基本數(shù)據(jù)類型的定義與使用、數(shù)組的定義及使用。2、熟悉 Java 基本語法,練習使用 Java 的數(shù)據(jù)類型、運算符、表達式和結(jié)構(gòu)。3、實驗內(nèi)容(學生成績管理系統(tǒng)之一)編寫 Java 程序,定義一個學生類,并編寫主類測試該類的功能。基本要求如下: 學生類中包含屬性有:學號、姓名、(枚舉類型)、一個存放上學期成績的數(shù)組(float)學生類包含的

2、方法有:信息的錄入、信息的輸出、輸出學生上學期的總分和均分、查找哪門課考了多少分,對成績排序,輸出最高分和最低分等;4、實驗原理或流程圖StudentStuNum int Number int Name Sex String score,Sum=0,A ve float+getInfor():void+printInfor():v oid5、實驗過程或源代碼import java.util.Scanner; import java.util.Arrays;enum Gender /定義一個Gender的枚舉類型數(shù)據(jù)MainClass_StudentInformation+ static mai

3、n(String args):void男,女public class StudentInfor /SudentInfor類的和定義public static void main(String args)Student stu = new Student();/用Student創(chuàng)建一個stu對象boolean x = true;while(x) /菜單需要不斷提示,因此需要一個循環(huán),又因為while適用于不確定循環(huán)次數(shù)的循環(huán),而for循環(huán)有固定的循環(huán)次數(shù),所以不用for循環(huán)而適用while循環(huán)Scanner sc = new Scanner(System.in); System.out.prin

4、tln(nn);System.out.println(tt 請輸入你的想要的程序(輸入序號) ); System.out.println(tt提示); System.out.println(tt 輸入學生信息 請輸入 0: ); System.out.println(tt 輸出學生信息 請輸入 1: ); System.out.println(tt 排序?qū)W生成績(升序) 請輸入 2: ); System.out.println(tt查找 想搜素的科目分數(shù) 請輸入 3:); System.out.println(tt 搜素對應(yīng)科目的分數(shù) 請輸入 4: ); System.out.println(

5、tt 結(jié)束程序 請輸入 5: ); System.out.println(n);int choose = sc.nextInt(); /從鍵盤輸入“菜單”中你選擇的數(shù)字switch(choose)case 0 :stu.inputInfor();break; /switch-case語句中每一個case都在用相同的對象不同的消息case 1 :stu.outputInfor();break;case 2 :stu.sortScore();break;case 3 :stu.searchScore();break;case 4 :stu.searchSub();break;case 5 :stu

6、.overProgram();x = false;break; default:System.out.println(tt你輸入的消息有誤,本程序結(jié)束!-);x = false;class Studentint studentclass; /Student類中的成員變量(屬性) int studentNO;String name; float score; int scor; float sco; float sum; float average; Gender gender;String subject; String sub;long phoneMu;void inputInfor() /

7、Student類中的成員方法(行為)System.out.println(ttt-請先輸入你的基本信息);Scanner sc = new Scanner(System.in); System.out.println(請輸入你的班級:);studentclass = sc.nextInt();/ 從鍵盤接受 Int 類型數(shù)據(jù)賦值給studentclass變量System.out.println(請輸入你的學號:); studentNO = sc.nextInt(); System.out.println(請輸入你的姓名:); name = sc.next();System.out.printl

8、n(請輸入你的(男請輸入1,女請輸入2,輸入其他數(shù)字時系統(tǒng)會自動!):);int genderNO = sc.nextInt(); /因為枚舉類型數(shù)據(jù)無法從鍵盤接受 所以使用if-alse語句來間接錄入變量if(genderNO = 1)gender = Gender.男;else if(genderNO = 2)gender = Gender.女;elseSystem.out.printf(n你的輸入有錯,本程序自動,請你重新進入本程序!nnn);System.exit(-1);/結(jié)束本本程序的語句System.out.println(請輸入你的方式:); phoneMu = sc.next

9、Long();System.out.println(請輸入四組你的成績:);score = new float4; /給score在堆中分配4個單精度浮點型數(shù)據(jù)的內(nèi)存sco = new float4;/給sco在堆中分配4個單精度浮點型數(shù)據(jù)的內(nèi)存subject = new String4; /給subject在堆中分配4個字符串類型數(shù)據(jù)的內(nèi)存for(int i = 0; i+ subjecti +-對應(yīng)的成績:);scorei = sc.nextFloat();scoi = scorei; /因為score數(shù)組在數(shù)組排序時順序會被打亂 所以多創(chuàng)建一個sco數(shù)組以便與subject數(shù)組一一對應(yīng)v

10、oid outputInfor()System.out.println(tt-基本信息);System.out.printf(tt你的班級是:%dn,studentclass); System.out.printf(tt你的學號是:%dn,studentNO); System.out.printf(tt你的姓名是:%sn,name); System.out.printf(tt你的是:%sn,gender); System.out.printf(tt你的方式是:%dn,phoneMu); Scanner sc = new Scanner(System.in);for(int i = 0; i=3

11、;i+)System.out.println(tt你的+ subjecti +對應(yīng)的成績?yōu)椋? scorei);System.out.printf(tt你的總成績是:%fn,sum(); System.out.printf(tt你的平均成績是:%fn,averageScores();float sum()/計算總成績的方法for(int i = 0;i= 0)System.out.println(number + 和數(shù)組中索引為 + index + 的元素值相同);elseSystem.out.println(number + 不與數(shù)組中的任何元素值相同);void searchSub() /查找科目對應(yīng)分數(shù)的方法Scanner sc = new Scanner(System.in); String sub;int index;System.out.println(請輸入你想要查找的科目的分數(shù):); sub = sc.next();for(int i=0;i= 0)System.out.println(你的+ sub +成績?yōu)椋? scoreindex);elseSystem.out.pr

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論