您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 《JAVA程序设计》实验报告.
《JAVA程序设计》实验报告1姓名学号日期实验题目输出自己姓名年龄身高体重,通过控制台和Eclipse运行程序初稿packageschooltext;publicclassMyselfPrint{publicstaticvoidmain(String[]args){System.out.println(ÐÕÃû£ºÑîÊËÇÙ£¬ÄêÁ䣺18£¬Éí¸ß£º160cm£¬ÌåÖØ£º100½ï);}}所遇问题及解决办法调试后的程序代码packageschooltext;publicclassMyselfPrint{publicstaticvoidmain(String[]args){System.out.println(ÐÕÃû£ºÑîÊËÇÙ£¬ÄêÁ䣺18£¬Éí¸ß£º160cm£¬ÌåÖØ£º100½ï);}}输出结果ÐÕÃû£ºÑîÊËÇÙ£¬ÄêÁ䣺18£¬Éí¸ß£º160cm£¬ÌåÖØ£º100½ï《JAVA程序设计》实验报告2姓名杨仕琴学号54121022日期10.13实验题目打印水仙花数程序初稿publicclasstest1{publicstaticvoidmain(String[]args){for(intj1=0;j110;j1++){for(intj2=0;j210;j2++){for(intj3=0;j310;j3++){inti=(j1+j2*10+j3*100);into=(j1*j1*j1+j2*j2*j2+j3*j3*j3);if(i==o){System.out.println(i);}}所遇问题及解决办法第一次输出结果:03701371153407publicstaticvoidmain(String[]args){调试后的程序代码for(intj1=0;j110;j1++){for(intj2=0;j210;j2++){for(intj3=1;j310;j3++){inti=(j1+j2*10+j3*100);into=(j1*j1*j1+j2*j2*j2+j3*j3*j3);if(i==o){System.out.println(i);}}}输出结果370371153407《JAVA程序设计》实验报告3姓名杨仕琴学号54121022日期10.13实验题目编写三个类,按照命名空间规则分别放到不同包中,在代码中调用其它包中的类,并查看类文件在系统中的组织方式packageunit3_1;程序初稿publicclassFish{publicFish(){System.out.println(iamfishfrompackage1);}}packageunit3_2;publicclassBird{publicBird(){System.out.println(iambirdfrompackage2);}}packageunit3_3;publicclassPig{publicPig(){System.out.println(iampigfrompackage3);}}packageunit3_3;importunit3_1.Fish;importunit3_2.Bird;publicclassUnit3Demo{publicstaticvoidmain(String[]args){Fishf=newFish();Birdb=newBird();Pigp=newPig();System.out.println(f.getClass().getResource(/).getPath());System.out.println(b.getClass().getResource(/).getPath());System.out.println(p.getClass().getResource(/).getPath());}}所遇问题及解决办法调试后的程序代码输出结果iamfishfrompackage1iambirdfrompackage2iampigfrompackage3/C:/Users/Administrator/Desktop/jsoft/jd1210.yangshi/bin//C:/Users/Administrator/Desktop/jsoft/jd1210.yangshi/bin//C:/Users/Administrator/Desktop/jsoft/jd1210.yangshi/bin/《JAVA程序设计》实验报告4姓名杨仕琴学号54121022日期10.13实验题目编写三个类ComputerTime,Plane,Car007和一个接口程序Common.要求在未来如果增加第三种交通工具,不必修改之前任何程序,只要编写新的交通工具代码.从命令行输入ComputerTime的四个参数,第一个是交通工具的类型,二到三是整数A,B,C.程序初稿packageunit4;publicabstractclassCommon2implementsCommon{doubleA=0;doubleB=0;doubleC=0;publicvoidsetA(doublea){A=a;}publicvoidsetB(doubleb){B=b;}publicvoidsetC(doublec){C=c;}publicabstractvoidTestV();}packageunit4;publicclassPlane2extendsCommon2{publicvoidTestV(){doublev=A+B+C;System.out.println(PlaneµÄËÙ¶ÈÊÇ£º+v);}}packageunit4;publicclassCar0072extendsCommon2{publicvoidTestV(){doublev;v=A*B/C;System.out.println(car007µÄËÙ¶ÈÊÇ£º+v);}}packageunit4;publicclassComputerTime2{publicstaticvoidmain(String[]args){}}所遇问题及解决办法主函数传参问题,询问同学和网友获得解答调试后的程序代码packageunit4;publicinterfaceCommon{publicvoidTestV();}packageunit4;importjava.util.Scanner;publicclassCar007implementsCommon{doubleA=0;doubleB=0;doubleC=0;publicvoidsetA(doublea){A=a;}publicvoidsetB(doubleb){B=b;}publicvoidsetC(doublec){C=c;}publicvoidTestV(){doublev;v=A*B/C;System.out.println(car007µÄËÙ¶ÈÊÇ£º+v);}}packageunit4;importjava.util.Set;publicclassPlaneimplementsCommon{doubleA=0;doubleB=0;doubleC=0;publicvoidsetA(doublea){A=a;}publicvoidsetB(doubleb){B=b;}publicvoidsetC(doublec){C=c;}publicvoidTestV(){doublev=A+B+C;System.out.println(PlaneµÄËÙ¶ÈÊÇ£º+v);}}packageunit4;publicclassComputerTime{publicstaticvoidmain(String[]args)throwsInstantiationException,IllegalAccessException,ClassNotFoundException{Planecom=(Plane)Class.forName(unit4.Plane).newInstance();doubleA=Double.parseDouble(args[1]);doubleB=Double.parseDouble(args[2]);doubleC=Double.parseDouble(args[3]);com.setA(A);com.setB(B);com.setC(C);com.TestV();}}输出结果《JAVA程序设计》实验报告5姓名杨仕琴学号54121022日期10.13实验题目编写Calculater.java,实现一个简单计算器,要求布局,可以完成加减乘除。程序初稿packageunit5;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.io.*;importjava.math.*;importjava.util.*;/***pTitle:用户应用界面计算器/p*pDescription:包含简易计算与功能更加强大的科学计算/p*pCopyright:Copyright(c)2008/p*pCompany:四……学/p*@authorchwencong@sina.com*@version1.0*/publicclassCalculat{staticJTextFieldshow;//设置输入区,显示区staticdoubleopNum=0;//存放操作数staticStringopChar==;//存放操作符staticbooleanflag=true;//设置标志publicstaticvoidmain(String[]args){newEasyFrame();//产生首界面——简易计算器}}所遇问题及解决办法流布局方面。解决办法:看书加上问老师调试后的程序代码packageunit5;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassCalculaterextendsJFrameimplementsActionListener{privateJPaneljPanel1,jPanel2;privateJTextFieldresultField;privateJButtons1,s2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,f1,f2;privatebooleanend,add,sub,mul,div;privateStringstr;privatedoublenum1,num2;publicCalculater(){super(Calculater);setSize(300,240);Containercon=getContentPane();con.setLayout(newBorderLayout());jPanel1=newJPanel();jPanel1.setLayout(newGridLayout(1,1));jPanel2=newJPanel();jPanel2.setLayout(newGridLayout(4,4));resultField=newJTextField(0);jPanel1.add(resultField);con.add(jPanel1,BorderLayout.NORTH);s1=newJButton(1);s1.addActionListener(this);s2=newJButton(2);s2.addActionListener(this);s3=newJButton(3);s3.addActionListener(this);s4=newJButton(4);s4.addActionListener(this);s5=newJButton(5);s5.addActionListene
本文标题:《JAVA程序设计》实验报告.
链接地址:https://www.777doc.com/doc-8525027 .html