ImageVerifierCode 换一换
格式:DOCX , 页数:47 ,大小:332.67KB ,
资源ID:8610296      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8610296.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(java大作业附运行截图及代码.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

java大作业附运行截图及代码.docx

1、java大作业附运行截图及代码Java程序设计上机报告 学 院 通信工程学院 专 业 通信工程 学生姓名 梁芷馨 学生学号 150* 第一次上机报告必做题 题目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 Carinf String name; String color; double weight;

2、 int passenger; Carinf(String 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(逆序输出);

3、 for(int i=args0.length()-1;i=0;i-) System.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

4、(Color.cyan); /设置背景色 / 绘制雪人 public void 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,TO

5、P+35,70,50); /upper torso g.fillOval(MID-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

6、 g.fillOval(MID+5,TOP+10,5,5); / right 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); / righ

7、t arm g.drawLine(MID-20,TOP+5,MID+20,TOP+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

8、.green); g.fillOval(MID-150,TOP+10,75,60); 题目4:编写一个Applet程序,在上面展示自己设计的名片,包括文字和图形。(注:下图名片中的背景图案仅为参考样式。)题目4的运行结果截图:题目4的源程序:package ch1;import java.awt.*;import java.applet.Applet;public class Design extends Applet public void init() setBackground(Color.lightGray); /设置背景色 public void paint(Graphics g)

9、final int MID=150; final int TOP=50; g.setColor(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

10、,50); g.drawOval(MID-130,TOP+50,40,40); 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

11、static void main(String args)throws IOException BufferedReader 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

12、.println(x+项:+factorial(x); static long factorial(int 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 IOException int a,b,

13、c; double r,h; BufferedReader buf; buf=new BufferedReader(new InputStreamReader(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.pa

14、rseInt(str); System.out.print(请输入长方体的宽:); str=buf.readLine(); b=Integer.parseInt(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(s

15、tr); System.out.print(请输入圆柱体的高:); str=buf.readLine(); h=Double.parseDouble(str); System.out.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 doubl

16、e volume(double r,double h) double volume; volume=Math.PI*r*r*h; return volume; 题目3:课本P145 1;题目3的运行结果截图:题目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(

17、obj.area();System.out.println(obj.toString(); class MyRectangle int xUp; int yUp; int xDown; int yDown; MyRectangle(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-x

18、Up); public String area() return 面积+(yUp-yDown)*(xDown-xUp); public String toString() return 宽+(yUp-yDown)+长+(xDown-xUp)+面积+(yUp-yDown)*(xDown-xUp); 题目4:课本P145 4题目4的运行结果截图:题目4的源程序:package ch2;public class User String name; private String command; public static int num=0; public User(String name) thi

19、s(); this.name=name; public User(String name, String command) this(name); mand=command; public String toString() return 姓名:+name+ 指令:+command; public User() num+;public String getcommand() return command;public void setcommand(String command) mand=command; package ch2;public class APP4 public static

20、 void main(String args) User obj1=new User(张三,go home); System.out.println(obj1.toString(); obj1.setcommand(come to school); System.out.println(obj1.toString(); System.out.println(指令为:+obj1.getcommand(); System.out.println(用户个数:+obj1.num); 选作题 题目1:设计Circle类,在小程序窗口中绘制多个圆。每个圆的大小、颜色利用构造方法的参数指定。题目1的运行结果

21、截图:题目1的源程序:package ch2;import java.awt.*;import java.applet.Applet;public class APP5 extends Applet Circle c1,c2,c3,c4,c5,c6,c7; public void init() c1=new Circle(10,Color.red,100,100); c2=new Circle(20,Color.yellow,35,35); c3=new Circle(30,Color.green,70,70); c4=new Circle(40,Color.blue,0,0); setBac

22、kground(Color.black); public void drawcircle(Graphics g) c1.draw(g); c2.draw(g); c3.draw(g); c4.draw(g); public class Circle int diameter; int x; int y; Color color; public Circle(int size,Color shade,int x1,int y1) diameter=size; color=shade; x=x1; y=y1; public void draw(Graphics g) g.setColor(colo

23、r); g.fillOval(x, y, diameter,diameter); 题目2:计Building类,在小程序窗口中绘制若干幢大楼。大楼的宽度与高度利用构造方法的参数指定。每幢大楼的颜色均为黑色,上面有一些黄色窗户,窗户的个数为110之间的随机数,窗户的位置在整栋大楼上随机分布。题目2的运行结果截图:题目2的源程序:package ch2;import java.awt.*;import java.applet.Applet;public class Rectangle double m; double n; double x; double y; Color color; Rect

24、angle(double Downx,double Downy,Color shade,double Upx,double Upy) m=Downx; n=Downy; color=shade; x=Upx; y=Upy; public void draw(Graphics g) g.setColor(color); g.fillRect(int)m, (int)n,(int) x,(int) y); java.awt.*;import java.applet.Applet;import java.math.*;import java.util.Random;public class Buil

25、ding extends Applet Rectangle r1,r2,r3,r4,r5,r6,r7,r8; Random rd1=new Random(); int i; public void init() r1=new Rectangle(10,80,Color.black,20,80); r2=new Rectangle(40,60,Color.black,35,100); r3=new Rectangle(80,90,Color.black,30,70); r4=new Rectangle(120,110,Color.black,10,50); public void paint(G

26、raphics g) r1.draw(g); r2.draw(g); r3.draw(g); r4.draw(g); int num1=rd1.nextInt(10); for(i=1;i=num1;i+) r5=new Rectangle(Math.floor(Math.random()*(30-20+1)+20),Math.floor(Math.random()*(160-80+1)+80),Color.yellow,2,2); r5.draw(g); int num2=rd1.nextInt(10); for(i=1;i=num2;i+) r6=new Rectangle(Math.fl

27、oor(Math.random()*(75-40+1)+40),Math.floor(Math.random()*(160-60+1)+60),Color.yellow,2,2); r6.draw(g); int num3=rd1.nextInt(10); for(i=1;i=num3;i+) r7=new Rectangle(Math.floor(Math.random()*(110-80+1)+80),Math.floor(Math.random()*(160-90+1)+90),Color.yellow,2,2); r7.draw(g); int num4=rd1.nextInt(10); for(i=1;i=num4;i+) r8=new Rectangle(Math.floor(Math.random()*(130-120+1)+120),Math.floor(Math.random()*(160-110+1)+110),Color.yellow,2,2); r8.draw(g); 第三次上机报告必做题 题目1:课本P146 5题目1的运行结果截图:题目1的源程序:package mylib.myclasses;/MyCube继承MyRectangle构造一个立方体public class MyCube extends MyRecta

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1