java大作业附运行截图及代码.docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《java大作业附运行截图及代码.docx》由会员分享,可在线阅读,更多相关《java大作业附运行截图及代码.docx(80页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Java程序设计上机报告 学 院 通信工程学院 专 业 通信工程 学生姓名 梁芷馨 学生学号 第一次上机报告必做题 题目1:课本P53 12;题目1的运行结果截图:题目1的源程序:package ch1;public class Car public static void main(String args)Carinf obj1=new Carinf(本田,黑色,1500,5);System.out.println(obj1.show();class CarinfString name;String color;double weight;int passenger;Carinf(Strin
2、g s,String b,double d,int i) name=s;color=b;weight=d;passenger=i;String show()return品牌: +name+ 颜色: +color+ 自重:+weight+公斤 搭载的人数: +passenger;题目2:课本P53 15;题目2的运行结果截图:题目2的源程序:package ch1;public class Reverse public static void main(String args)System.out.println(逆序输出);for(int i=args0.length()-1;i=0;i-)S
3、ystem.out.println(args0.charAt(i);选作题 题目3:参考下列要求,修改Snowman.java:(1)在图片的右上角添加文本;(2)给雪人增加更多的装饰;(3)给画面添加更多内容,比如云朵,圣诞树,房屋等。题目3的运行结果截图:题目3的源程序:package ch1;import java.awt.*;import java.applet.Applet;public class Snowman extends Applet public void init() setBackground(Color.cyan); /设置背景色 / 绘制雪人public void
4、 paint(Graphics g) final int MID=150; final int TOP=50; g.setColor(Color.blue); / 设置前景色 g.fillRect(0,175,300,50); /ground g.setColor(Color.yellow); g.fillOval(-40,-40,80,80); /sun g.setColor(Color.white); g.fillOval(MID-20,TOP,40,40); /head g.fillOval(MID-35,TOP+35,70,50); /upper torso g.fillOval(MI
5、D-50,TOP+80,100,60); /lower torso g.fillOval(MID-40,TOP+10,5,5); /雪花 g.fillOval(MID-80,TOP+20,5,5); g.fillOval(MID+35,TOP+15,5,5); g.fillOval(MID-120,TOP+50,5,5); g.fillOval(MID-100,TOP+90,5,5); g.setColor(Color.black); g.fillOval(MID-10,TOP+10,5,5); / left eye g.fillOval(MID+5,TOP+10,5,5); / right
6、eye g.setColor(Color.black); g.fillOval(MID-2,TOP+45,8,10); g.setColor(Color.blue); g.fillOval(MID-2,TOP+60,8,10); g.drawArc(MID-10,TOP+20,20,10,190,160); /smile g.drawLine(MID-25,TOP+60,MID-50,TOP+40); / left arm g.drawLine(MID+25,TOP+60,MID+55,TOP+60); / right arm g.drawLine(MID-20,TOP+5,MID+20,TO
7、P+5); / brim of heat g.fillRect(MID-15,TOP-20,30,25); / top of hat g.setColor(Color.red); g.fillOval(MID-2,TOP+18,5,5); / 鼻子 g.setColor(Color.black); g.drawString(有点冷啊!, MID+10, TOP-30); g.setColor(Color.gray); g.fillRect(MID-120,TOP+35,20,90); g.setColor(Color.green); g.fillOval(MID-150,TOP+10,75,6
8、0); 题目4:编写一个Applet程序,在上面展示自己设计的名片,包括文字和图形。(注:下图名片中的背景图案仅为参考样式。)题目4的运行结果截图:题目4的源程序:package ch1;import java.awt.*;import java.applet.Applet;public class Design extends Appletpublic void init() setBackground(Color.lightGray); /设置背景色 public void paint(Graphics g) final int MID=150; final int TOP=50; g.s
9、etColor(Color.white); g.drawString(西安电子科技大学, MID+10, TOP+130); g.drawString(Xidian University, MID+10, TOP+150); g.setColor(Color.magenta); g.drawOval(MID-90,TOP-40,60,60); g.drawOval(MID-100,TOP+80,40,40); g.setColor(Color.yellow); g.drawOval(MID+10,TOP-20,50,50); g.drawOval(MID-130,TOP+50,40,40);
10、g.setColor(Color.cyan); g.drawOval(MID-20,TOP-50,30,30); g.drawOval(MID-40,TOP+20,65,65);第二次上机报告必做题 题目1:课本P92 12;题目1的运行结果截图:题目1的源程序:package ch2;import java.io.IOException;import java.io.BufferedReader;import java.io.InputStreamReader;public class APP1 public static void main(String args)throws IOExc
11、eptionBufferedReader buf;buf=new BufferedReader(new InputStreamReader(System.in);String str;int x;System.out.println(输入一个整数);System.out.println(输入quit,回车后退出);while(true)str=buf.readLine();if(str.equals(quit)break;x=Integer.parseInt(str);System.out.println(x+项:+factorial(x);static long factorial(int
12、k)long fib=new longk;fib0=1;fib1=1;if(k1)for(int i=2;i=k-1;i+)fibi=fibi-1+fibi-2;return fibk-1;题目2:课本P92 21;题目2的运行结果截图:题目2的源程序:package ch2;import java.io.*;public class APP2 public static void main(String args) throws IOExceptionint a,b,c;double r,h;BufferedReader buf;buf=new BufferedReader(new Inpu
13、tStreamReader(System.in);String str;System.out.print(请输入立方体边长:);str=buf.readLine();a=Integer.parseInt(str);System.out.println(立方体的体积: +volume(a);System.out.println();System.out.print(请输入长方体的长:);str=buf.readLine();a=Integer.parseInt(str);System.out.print(请输入长方体的宽:);str=buf.readLine();b=Integer.parseI
14、nt(str);System.out.print(请输入长方体的高:);str=buf.readLine();c=Integer.parseInt(str);System.out.println(长方体的体积: +volume(a,b,c);System.out.println();System.out.print(请输入圆柱体的底面半径:);str=buf.readLine();r=Double.parseDouble(str);System.out.print(请输入圆柱体的高:);str=buf.readLine();h=Double.parseDouble(str);System.ou
15、t.println(圆柱体的体积: +volume(r,h);System.out.println();static int volume(int a)int volume;volume=a*a*a;return volume;static int volume(int a,int b,int c)int volume;volume=a*b*c;return volume;static double volume(double r,double h)double volume;volume=Math.PI*r*r*h;return volume;题目3:课本P145 1;题目3的运行结果截图:
16、题目3的源程序:package ch2;public class APP3 public static void main(String args)MyRectangle obj=new MyRectangle( 1,5,6,2);System.out.println(obj.getW();System.out.println(obj.getH();System.out.println(obj.area();System.out.println(obj.toString();class MyRectangleint xUp;int yUp;int xDown;int yDown;MyRecta
17、ngle(int xUp,int yUp,int xDown, int yDown )this.xUp=xUp;this.yUp=yUp;this.xDown=xDown;this.yDown=yDown;public String getW() return 宽+(yUp-yDown);public String getH() return 长+(xDown-xUp);public String area() return 面积+(yUp-yDown)*(xDown-xUp);public String toString() return 宽+(yUp-yDown)+长+(xDown-xUp
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 作业 运行 截图 代码
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内