




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Java 实验报告实验日期:2011年10月17日 实验机房与机号: 实验班级: 组员姓名学号: 指导教师:刘寿强 第三单元实验目的:掌握陈述面向对象的思想,通过创建类的实力来体现实验内容:第三单元;实验步骤:3-2class DogString color;int weight;public Dog(String color,int weight)this.color=color;this.weight=weight;public void showd()System.out.println(这是体重为+weight+斤,+颜色为+color+的狗);class CatString color;int weight;public Cat(String color,int weight)this.color=color;this.weight=weight;public void showc()System.out.println(这是体重为+weight+斤,+颜色为+color+的猫);public class Apublic static void main(String args)Dog d1= new Dog(黄色,100);Cat c1= new Cat(白色,200);d1.showd();c1.showc(); 3-3class CarString ping;double price;String date;public Car(String ping,double price,String date)this.ping=ping;this.price=price;this.date=date;public void show()System.out.println(ping+轿车,价格为+price+date);public void qd()System.out.println(汽车正在启动);public void sc()System.out.println(汽车正在刹车);public void js()System.out.println(汽车正在加速);public class Apublic static void main(String args)Car car=new Car(奇瑞,3000,保修终生!);car.show();car.js();3-4public class ConsoleParamspublic static void main(String args)if (args.length20)System.out.println(数值较大);elseSystem.out.println(数值较小或等于);3-6class SExamstatic int num=0;public SExam() num+;public class StaticExampublic static void main(String args)SExam se1=new SExam();SExam se2=new SExam();SExam se3=new SExam();System.out.println(SExam.num+次);第四单元目的:掌握格式化转换异常,实验内容:第四单元步骤如下:public class NumberFormatExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubint iArray=0,0; try iArray0=Integer.parseInt(args0); iArray1=Integer.parseInt(args1);catch(ArrayIndexOutOfBoundsException e) System.out.println(用户输入的数据不完整,程序使用默认值代替:); catch(NumberFormatException e) System.out.println(用户输入的不全是数值型的数据,程序使用默认值替代:); System.out.println(iArray0+iArray1+=+(iArray0+iArray1);public class ArithmeticExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubtryint a=args.length;int b=42/a;catch(ArithmeticException e)System.out.println(除数不能够为零啊!);import java.util.Random;public class NegativeIndexExceptionDemo public int getNumberOfRandomIndex(int iArray)throws NegativeIndexExceptionRandom random=new Random();int index=random.nextInt();if(index0) throw new NegativeIndexException(this.getClass().getName()+.getNumberOfRandomIndex(int)方法不能够处理自己所抛出的异常:索引值+index+产出异常); index=index%iArray.length;return iArrayindex;public static void main(String args) int iArray=0,1,3,4,5,6,7,8,9;int randomNumber=0;tryrandomNumber=new NegativeIndexExceptionDemo().getNumberOfRandomIndex(iArray);catch(NegativeIndexException e)System.out.println(e+nmian方法有能力处理该异常t);randomNumber=Math.round(float)(Math.random()*10);System.out.println(产生随机结果为+randomNumber);public class NegativeIndexException extends Exceptionpublic NegativeIndexException()super();public NegativeIndexException(String message)super(message);第五单元一、实验目的:熟悉掌握输入输出流二、实验内容:第五单元三、实验步骤 练习5-1 校验用户密码格式(1) 程序代码import java.util.Scanner;public class CheckPWpublic static void main(String args)System.out.println(请输入密码:);Scanner scanner=new Scanner(System.in);String inputString=scanner.nextLine();String regular=a-zA-Z$_a-zA-Z$_0-97,19;if(inputString.matches(regular)System.out.println(密码符合组合规律。);elseSystem.out.println(密码不符合组合规律。);(2) 运行结果图5-1练习5-2 转换中文格式日期(1) 程序代码import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Locale;public class ChineseDatepublic static void main(String args)Date date=new Date(10,9,2011);String dateFormatStr=北京时间:ntH:mm:ssntEntyyyy-M-dd;SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr);System.out.println(simpleFormat.format(date);(2) 运行结果图5-2练习5-3 万年历(3) 程序代码import java.text.SimpleDateFormat;import java.util.*;public class CalendarAutopublic static void main(String args)System.out.println(请输入年月(格式:年 月):);Scanner scanner=new Scanner(System.in);int params=new int2;for(int i=0;i12)params1=params1%13;if(params10)params1=12+params1%13;Calendar calendar=Calendar.getInstance();calendar.set(params0,params1-1,1);int firstIndex=calendar.get(Calendar.DAY_OF_WEEK)-1;char title=日,一,二,三,四,五,六;int daysArray=new int67;int day=1;for(int i=firstIndex;i7;i+)daysArray0i=day+;for(int i=1;i6;i+)for(int j=0;jdaysOfMonth(params0,params1)i=6;break;daysArrayij=day+;for(int i=0;i7;i+)System.out.print(titlei+t);System.out.println();for(int i=0;i6;i+)for(int j=0;j7;j+)if(daysArrayij!=0)System.out.print(daysArrayij+t);else System.out.print( t);System.out.println();private static int daysOfMonth(int year,int month)switch(month
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年公共急救知识题库及答案
- 2025藤县事业单位试题及答案
- 2025辽宁铁岭市本级1家单位补充招聘公益性岗位人员1人考试模拟试题及答案解析
- 2025下半年内江市部分事业单位公开考试招聘工作人员的(240人)考试模拟试题及答案解析
- 2025年洛阳市文学艺术界联合会下属事业单位招才引智引进工作人员4名考试模拟试题及答案解析
- 定南县2025年公开补招基层就业公共服务岗位工作人员备考考试题库附答案解析
- 2025浙江嘉兴市海宁市海洲街道办事处招聘1人备考考试题库附答案解析
- 2025年护理管理的题库及答案
- 2025年填海工程考试试题及答案
- 2025年淄博中考语文真题及答案
- 无痛分娩试题及答案
- 帮忙找工作协议书
- 转让账户协议书
- 锯床操作规程
- 服刑人员出监适应性教育
- 一故事一音标课件
- 2025年煤矿安全规程试题及答案
- 六年级数学口算与解决问题
- 住宅厨房卫生间排烟气系统建筑构造L18J905
- FZ∕T 61002-2019 化纤仿毛毛毯
- 乡村医生年度个人述职报告(2篇)
评论
0/150
提交评论