九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

Java程序設(shè)計實驗報告實驗報告冊.doc

上傳人:good****022 文檔編號:116422954 上傳時間:2022-07-05 格式:DOC 頁數(shù):62 大?。?31.88KB
收藏 版權(quán)申訴 舉報 下載
Java程序設(shè)計實驗報告實驗報告冊.doc_第1頁
第1頁 / 共62頁
Java程序設(shè)計實驗報告實驗報告冊.doc_第2頁
第2頁 / 共62頁
Java程序設(shè)計實驗報告實驗報告冊.doc_第3頁
第3頁 / 共62頁

下載文檔到電腦,查找使用更方便

13 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《Java程序設(shè)計實驗報告實驗報告冊.doc》由會員分享,可在線閱讀,更多相關(guān)《Java程序設(shè)計實驗報告實驗報告冊.doc(62頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、學 生 實 驗 報 告 冊(理工類)課程名稱: Java程序設(shè)計實驗 專業(yè)班級: 12計算機科學與技術(shù)(1) 學生學號: 學生姓名: 所屬院部: 計算機工程學院 指導(dǎo)教師: 馬青霞 2014 2015學年 第 2 學期 金陵科技學院教務(wù)處制金陵科技學院實驗報告實驗項目名稱: Java編程基礎(chǔ) 實驗學時: 4 同組學生姓名: 無 實驗地點: A101 實驗日期: 4月1日-4月8日 實驗成績: 批改教師: 馬青霞 批改時間: 實驗1 JAVA編程基礎(chǔ)一、 實驗?zāi)康?、 熟練掌握JDK編寫調(diào)試Java應(yīng)用程序及Java小程序的方法;2、 熟練掌握Java應(yīng)用程序的結(jié)構(gòu);3、 了解Java語言的特點

2、,基本語句、運算符及表達式的使用方法;4、 熟練掌握常見數(shù)據(jù)類型的使用;5、熟練掌握if-else、switch、while、do-while、for、continue、break、return語句的使用方法;6、熟練掌握數(shù)組和字符串的使用。二、實驗要求1、編寫程序要規(guī)范、正確,上機調(diào)試過程和結(jié)果要有記錄;2、做完實驗后給出本實驗的實驗報告。三、實驗設(shè)備、環(huán)境安裝有JDK、Eclipse軟件的計算機。四、實驗步驟 采用記事本編寫一個簡單的應(yīng)用程序(1)新建一個記事本文件,重新命名為Hello.java(2)打開記事本,輸入以下內(nèi)容(注意大小寫):public class Hellopublic

3、 static void main(String args)System.out.println(hello hello);(3)請記錄程序編譯和執(zhí)行的步驟,并附上運行結(jié)果圖。 進入文件所在目錄cd classjavajava_ex1 編譯N:classjavajava_ex1javac Hello.java運行java Hello結(jié)果:五、實驗內(nèi)容1、從鍵盤上輸入學號、班級和姓名,并附上運行結(jié)果圖。import java.util.Scanner;public class KeyboardDemo public static void main(String args) Scanner sc

4、an = new Scanner(System.in);System.out.print(請輸入班級:);String cls = scan.nextLine();System.out.print(請輸入姓名:);String name = scan.nextLine();System.out.print(請輸入學號:);String num = scan.nextLine();System.out.println(班級:+cls+ 姓名:+name+ 學號+num);2、編寫一個程序,用來判斷輸入的是大寫字母,小寫字母,數(shù)字還是其他的字符(if)。import java.util.Scann

5、er;public class CharDemo public static void main(String args) / TODO Auto-generated method stubScanner scan = new Scanner(System.in);while(true)System.out.print(請輸入一個字符:);char ch = scan.nextLine().charAt(0);if(Character.isUpperCase(ch)System.out.println(該字符是大寫字母:+ch);else if(Character.isLowerCase(ch

6、)System.out.println(該字符是小寫字母:+ch);else if(Character.isDigit(ch)System.out.println(該字符是數(shù)字:+ch);else System.out.println(該字符是其他字符!); 3、編寫一個程序,實現(xiàn)簡單加、減、乘除的運算,要求從鍵盤上輸入數(shù)據(jù)(switch)。import java.util.Scanner;public class Count public static void main(String args) / TODO Auto-generated method stubint num1;int n

7、um2;char fh;Scanner sc = new Scanner(System.in);while(true)System.out.println(請輸入第一個數(shù):);num1 = sc.nextInt();System.out.println(請輸入您的運算符:);fh = sc.next().charAt(0);System.out.println(請輸入第二個數(shù):);num2 = sc.nextInt();switch(fh)case +:System.out.println(num1+num2=+(num1+num2);break;case -:System.out.print

8、ln(num1-num2=+(num1-num2);break;case *:System.out.println(num1*num2=+(num1*num2);break;case /:if(num2=0)break;elseSystem.out.println(num1/num2=+(num1/num2);break;default:System.out.println(輸入有誤!);break;4、定義一個一維數(shù)組,通過鍵盤輸入10個兩位整數(shù),并求出其中的最大值和平均值,把結(jié)果顯示出來。import java.util.Scanner;public class ArrayDemo pub

9、lic static void main(String args) / TODO Auto-generated method stubScanner scan = new Scanner(System.in);int arr = new int10;int sum = 0;System.out.print(請輸入10個兩位整數(shù):);for(int i=0;i10;i+)arri=scan.nextInt();sum += arri;System.out.println(sum:+String.format(%d, sum);System.out.println(average:+String.

10、format(%.2f, (double)sum/10);5、定義一個5行5列二維數(shù)組,用隨機數(shù)給二維數(shù)組賦值,按照5行5列的格式顯示出二維數(shù)組的內(nèi)容,把最大值顯示出來。public class Array5_5Demo public static void main(String args) / TODO Auto-generated method stubint arr = new int55;for(int i=0;i5;i+)for(int j=0;j5;j+)arrij = (int)(Math.random()*90+10);for(int i=0;i5;i+)for(int j=

11、0;j5;j+)System.out.print(String.format(%4d, arrij);System.out.println();6、實現(xiàn)不規(guī)則二維數(shù)組的輸入和輸出。import java.util.Scanner;public class NoRuleArrDemo public static void main(String args) / TODO Auto-generated method stubint arr = new int3;arr0 = new int3;arr1 = new int2;arr2 = new int4;Scanner scan = new Sc

12、anner(System.in);for(int i=0;iarr.length;i+)for(int j=0;jarri.length;j+)System.out.print(請輸入數(shù)據(jù)(0-10000):);arrij = scan.nextInt();System.out.println(數(shù)組元素為:);for(int i=0;iarr.length;i+)for(int j=0;j10&age50)return true;return false;void show()System.out.println(學號:+num+n姓名:+name+n性別:+sex+n年齡:+age);pub

13、lic class demo1 public static void main(String args) / TODO Auto-generated method stubStudents stu = new Students(1205104006,wjw,f,21);if(stu.judgeAge()&stu.judgeSex()stu.show();elseSystem.out.println(學生初始化信息有誤,請重新輸入!);2、定義一個方法,用數(shù)組作為參數(shù)來傳遞數(shù)據(jù)(請補充下面的代碼)。package test1;import java.util.Arrays;public clas

14、s demo1 public static void main(String args) int a=10,20,15,40,50,35;Myclass myclass=new Myclass();System.out.println(排序前:); myclass.printArr(a);Arrays.sort(a);System.out.println(排序后);myclass.printArr(a);class Myclass/定義一個方法,實現(xiàn)數(shù)組內(nèi)容的輸出void printArr(int arr)for(int i=0;iarr.length;i+)System.out.print(

15、String.format(%4d,arri);System.out.println();3、 定義一個學生類,把學生類當作對象來傳遞或者用對象數(shù)組作為參數(shù)傳遞。package test1;class Studentsprivate String num;private String name;private char sex;private int age;Students(String num,String name,char sex,int age)this.num = num;this.name = name;this.sex = sex;this.age = age;void sho

16、w()System.out.println(學號:+num+n姓名:+name+n性別:+sex+n年齡:+age);public class demo2 public static void main(String args) Students stu= new Students2 ;stu0= new Students(1205104006,wjw,f,21);stu1= new Students(12051040,ys,m,22);print(stu); public static void print(Students stu) for(int i=0;istu.length;i+)S

17、ystem.out.println(第+(i+1)+個學生的信息:);stui.show();4、 利用方法的重載兩個整數(shù)和兩個雙精度類型數(shù)據(jù)求和。package test1;class Addpublic int Add(int num1,int num2)return num1+num2;public double Add(double num1,double num2)return num1+num2;public class demo3 public static void main(String args) int num1 = 10;int num2 = 20;double num

18、3 = 10.23;double num4 = 30.74;Add add = new Add();System.out.println(int和:+num1+num2+=+add.Add(num1, num2);System.out.println(double整數(shù)和:+num3+num4+=+String.format(%.2f, add.Add(num3, num4);5、定義一個Area類,用構(gòu)造函數(shù)重載,實現(xiàn)矩形的面積,圓的面積,梯形的面積,定義一個ShowArea方法,顯示結(jié)果。package test1;class Areaprivate static final double

19、PI = 3.14;private double area;Area(double width,double length)area = width*length;Area(double radius)area = PI*radius*radius;Area(double length1,double length2,double height)area = (length1+length2)*height/2;public void showArea()System.out.println(String.format(%.2f, area);public class AreaDemo pub

20、lic static void main(String args) Area rectangle = new Area(3.0,5.5);Area cycle = new Area(2.4);Area echelon = new Area(3.2,4.5,4);System.out.print(rectangle area:);rectangle.showArea();System.out.print(cycle area:);cycle.showArea();System.out.print(echelon area:);echelon.showArea();6、在該程序中構(gòu)造一個Perso

21、n基類,在Person類的基礎(chǔ)上再構(gòu)造Student類,實現(xiàn)方法的覆蓋。class Personprivate int age;private String name;Person(String name,int age)this.name = name;this.age = age;void show()System.out.println(name:+name+nage:+age);void method()System.out.println(method調(diào)用);class Student extends PersonStudent(String name, int age) super

22、(name, age);void method()System.out.println(method調(diào)用.study.);public class ExtendDemo public static void main(String args) Student stu = new Student(wjw,21);stu.show();stu.method();7、用面向?qū)ο蟮闹R,實現(xiàn)實驗一的計算器程序。package htp;import java.util.Scanner;class Operationprivate int num1;private int num2;char opt ;p

23、ublic int getNum1() return num1;public void setNum1(int num1) this.num1 = num1;public int getNume2() return num2;public void setNume2(int nume2) this.num2 = num2;public char getOpt() return opt;public void setOpt(char opt) this.opt = opt;Operation(int num1,char opt,int num2)this.num1 = num1;this.num

24、2 = num2;this.opt = opt;public void Cal()switch(opt)case +:System.out.println(num1+num2=+(num1+num2);break;case -:System.out.println(num1-num2=+(num1-num2);break;case *:System.out.println(num1*num2=+(num1*num2);break;case /:if(num2=0)break;elseSystem.out.println(num1/num2=+(num1/num2);break;default:

25、System.out.println(輸入有誤!);break;public class Calculate public static void main(String args) / TODO Auto-generated method stubScanner scan = new Scanner(System.in);int num1;int num2;char operator;System.out.println(請輸入第一個數(shù):);num1 = scan.nextInt();System.out.println(請輸入您的運算符:);operator = scan.next().c

26、harAt(0);System.out.println(請輸入第二個數(shù):);num2 = scan.nextInt();Operation op = new Operation(num1,operator,num2);op.Cal();靜態(tài)工廠(以加法為例):/*Test.java*/package cal;import java.util.Scanner;public class Test public static void main(String args) throws Exception Scanner input=new Scanner(System.in);System.out.

27、print(請輸入第一個數(shù)據(jù):);int numA=input.nextInt();System.out.print(請輸入操作符:(+、-、*、/ );String type=input.next();System.out.print(請輸入第二個數(shù)據(jù):);int numB=input.nextInt();Factory factory=FactoryOperation.createFactory(type);Operation operation=factory.createOperation(); operation.setNumA(numA); operation.setNumB(nu

28、mB); System.out.println(計算結(jié)果為:+operation.getResult();/* Operation.java */package cal;public abstract class Operation protected int numA,numB; public int getNumA() return numA;public void setNumA(int numA) this.numA = numA;public int getNumB() return numB;public void setNumB(int numB) this.numB = num

29、B;public abstract double getResult();/* Factory .java*/package cal;public abstract class Factory public abstract Operation createOperation();/* FactoryOperation .java*/package cal;import java.io.File;import java.io.FileInputStream;import java.util.Properties;public class FactoryOperation public stat

30、ic Factory createFactory(String type) throws ExceptionProperties properties=new Properties();File file=new File(config.xml);properties.loadFromXML(new FileInputStream(file);String className= properties.getProperty(type);Class c=Class.forName(className);Factory factory=(Factory) (c.getClassLoader().l

31、oadClass(className).newInstance(); return factory;/*config.xml*/ calc.demo2.FactoryAdd /*OperationAdd .java*/package cal;public class OperationAdd extends OperationOverridepublic double getResult() return numA+numB;8、定義一個Icar和Icarcolor的接口,在接口Icar中定義一個Run方法和一個Stop方法,在接口Icarcolor中定義一個Color的屬性,再定義一個Car

32、類實現(xiàn)接口中的方法和屬性。interface Icarpublic void run();public void stop();interface IcarColor final String color = purple;class Car implements Icar, IcarColorpublic void run()System.out.println(color+ Car running.);public void stop()System.out.println(color+ Car stop.);public class CarInterface public static

33、void main(String args) / TODO Auto-generated method stubCar myCar = new Car();myCar.run();myCar.stop();實驗項目名稱: 圖形用戶界面 實驗學時: 6 同組學生姓名: 無 實驗地點: A101 實驗日期: 5月13日-5月27日 實驗成績: 批改教師: 馬青霞 批改時間: 實驗3 圖形用戶界面一、 實驗?zāi)康?、要?、 掌握Swing組件的使用方法;2、 熟練掌握Swing中常用布局管理器的使用方法;3、 掌握用戶界面動作與事件的處理程序的編寫方法;4、 熟練掌握構(gòu)造用戶界面的方法和常見界面元素的

34、使用;5、熟練掌握Java繪圖的主要方法。二、實驗要求1、編寫程序要規(guī)范、正確,上機調(diào)試過程和結(jié)果要有記錄;2、做完實驗后給出本實驗的實驗報告。三、實驗設(shè)備、環(huán)境安裝有JDK、Eclipse軟件的計算機。四、實驗內(nèi)容1、設(shè)計一個Windows應(yīng)用程序,在該程序中首先構(gòu)造一個學生基本類,再分別構(gòu)造小學生、中學生、大學生派生類,當輸入相關(guān)數(shù)據(jù),單擊不同的按鈕時,將分別創(chuàng)建不同的學生類對象,并輸出當前學生的總?cè)藬?shù),該學生的姓名,學生類型,平均成績。程序要求:(1)每個學生都有的字段為姓名、年齡。(2)小學生的字段還有語文,數(shù)學,用來表示這兩科的成績。(3)中學生在此基礎(chǔ)上增加英語成績。(4)大學生分

35、為必修課和選修課兩項成績。(5)學生類提供方法來統(tǒng)計自己的總成績并輸出。(6)通過靜態(tài)成員自動記錄學生總?cè)藬?shù)。(7)成員初始化通過構(gòu)造函數(shù)完成。/*學生類*/package htp.gui;public abstract class Student private String name;private int age;double average;static int num;public Student(String name,int age)this.name = name;this.age = age;public abstract double getAverage();class

36、StuPri extends Studentprivate double chinese;private double math;public StuPri(String name, int age, double chinese, double math) super(name, age);this.chinese = chinese;this.math = math;Overridepublic double getAverage()average = (chinese + math)/2;return average;class StuSec extends Studentprivate

37、 double chinese;private double math;private double english;public StuSec(String name, int age, double chinese, double math, double english) super(name, age);this.chinese = chinese;this.math = math;this.english = english;Overridepublic double getAverage() average = (chinese + math + english)/3;return

38、 average;class StuColl extends Studentprivate double optional;private double comp;public StuColl(String name, int age, double optional, double comp) super(name, age);this.optional = optional;p = comp;Overridepublic double getAverage()average = (optional + comp)/2;return average;/*界面*/package htp.gui

39、;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class StudentGui extends JFrame implements ActionListenerJPanel jp1,jp2;JPanel jp1_1,jp1_2,jp1_3;JButton jb_pri,jb_sec,jb_col;JLabel jl_name,jl_age,jl_ch_op,jl_math_com,jl_en;JTextFi

40、eld jtf_name,jtf_age;JTextField jtfCh_Opt,jtfMath_Com,jtfEn;JTextArea jta;public static void main(String args) StudentGui stu = new StudentGui();public StudentGui()jp1 = new JPanel();jp2 = new JPanel();jp1_1 = new JPanel();jp1_2 = new JPanel();jp1_3 = new JPanel();jl_name = new JLabel(姓名);jl_age = n

41、ew JLabel(年齡);jl_ch_op = new JLabel(語文/選修);jl_math_com = new JLabel(數(shù)學/必修);jl_en = new JLabel(英語);jtf_name = new JTextField(10);jtf_age = new JTextField(10);jtfCh_Opt = new JTextField(10);jtfMath_Com = new JTextField(10);jtfEn = new JTextField(10);jta = new JTextArea(30,20);jb_pri = new JButton(小學生)

42、;jb_pri.addActionListener(this);jb_sec = new JButton(中學生);jb_sec.addActionListener(this);jb_col = new JButton(大學生);jb_col.addActionListener(this);jp1.setLayout(new GridLayout(3,1);jp1_1.add(jl_name);jp1_1.add(jtf_name);jp1_1.add(jl_ch_op);jp1_1.add(jtfCh_Opt);jp1_1.add(jb_pri);jp1_2.add(jl_age);jp1_

43、2.add(jtf_age);jp1_2.add(jl_math_com);jp1_2.add(jtfMath_Com);jp1_2.add(jb_sec);jp1_3.setLayout(new FlowLayout(FlowLayout.RIGHT);jp1_3.add(jl_en,Right);jp1_3.add(jtfEn,East);jp1_3.add(jb_col,East);jp1.add(jp1_1,North);jp1.add(jp1_2,Center);jp1.add(jp1_3,South);jp2.add(jta);this.add(jp1,North);this.ad

44、d(jp2);this.setVisible(true);this.setTitle(學生信息);this.setSize(430,500);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Overridepublic void actionPerformed(ActionEvent e) String name;int age;double chi_opt,math_comp,en;double average = 0;name = jtf_name.getText();age = Integer.parseInt(jtf_age.ge

45、tText();chi_opt = Double.parseDouble(jtfCh_Opt.getText();math_comp = Double.parseDouble(jtfMath_Com.getText();if(e.getSource()=jb_pri)StuPri stuPri = new StuPri(name, age, chi_opt, math_comp);average = stuPri.getAverage();else if(e.getSource()=jb_sec)en = Double.parseDouble(jtfEn.getText();StuSec st

46、uSec = new StuSec(name, age, chi_opt, math_comp, en);average = stuSec.getAverage();else if(e.getSource()=jb_col)StuColl stuColl = new StuColl(name, age, chi_opt, math_comp);average = stuColl.getAverage();Student.num +;String result = 學生總?cè)藬?shù): + Student.num +;當前學生平均成績:+ String.format(%.2f, average);jta

47、.setText( result );2、在該程序中定義平面圖形抽象類Figure和派生類圓(Circle)、矩形(Rectangle)和三角形(Triangle)。該程序?qū)崿F(xiàn)的功能包括:輸入相應(yīng)圖形的參數(shù),如矩形的長和寬,單擊相應(yīng)的按鈕,根據(jù)輸入?yún)?shù)創(chuàng)建圖形類并輸出該對象的面積。/*圖形類*/package htp.test; abstract class Figurepublic abstract double getArea();class Circle extends Figureprivate static final double PI = 3.1415926;private do

48、uble radius;Circle(double radius)this.radius = radius;Overridepublic double getArea() return radius*radius*PI;class Rectangle extends Figureprivate double width;private double length;Rectangle(double width,double length)this.width = width;this.length = length;Overridepublic double getArea() return w

49、idth*length;class Triangle extends Figureprivate double height;private double length;Triangle(double height,double length)this.height = height;this.length = length;Overridepublic double getArea() return height*length/2;/*圖形界面*/package htp.test;import java.awt.event.*;import javax.swing.*;import java.awt.*;public class Demo extends JFrame implements ActionListenerJLabel jlRadius,jlLength,jlWidth_H

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!