java实验报告mydate_实验报告 5 java常用类(一).docx

实验报告 5 java常用类(一)

西 安 邮 电 大 学(计算机学院)面向对象程序设计JAVA课内实验报告 实验名称: Java类库和常用类(二) 专业名称:班 级:学生姓名:学号(8位):指导教师:实验时间:实验目的及实验环境实验目的: 1理解类库的概念,掌握分析、应用类库中的类的方法。 2熟练掌握Math类的常用方法。熟悉Random类的常用方法。 3理解String类的特性,熟练掌握String类的常用方法。 4能用Date类创建对象,熟练掌握Date类的常用方法。 5熟练掌握SimpleDateFormat解析日期和设置日期输出格式。 6学会查阅Java API在线参考文档和离线文档的方法。实验环境:Eclipse for java实验内容 1 基本内容(实验前请及时熟悉如下相关内容) 1)练习使用Math类的常用方法。 2)应用String类编程练习。 3)编写程序应用Random类生成随机数。 4)练习使用Date类的常用方法。 5)查阅Java API在线参考文档和下载Java API离线文档。 2 综合实验:2.1 (Y. Daniel Liang英文版八版P296:8.3*) (Using the Date class) Write a program that creates a Date object, sets its elapsed time to 10000, 100000, 100000000, 1000000000, 10000000000, 100000000000, and displays the date and time using the toString() method, respectively.2.2(Y. Daniel Liang英文版八版P296:8.4*) (Using the Random class) Write a program that creates a Random object with seed 1000 and displays the first 50 random integers between 0 and 100 using the nextInt(100) method.2.3 (Y. Daniel Liang英文版八版P296:8.5*) (Using the GregorianCalendar class) Java API has the GregorianCalendar class in the java.util package that can be used to obtain the year, month, and day of a date. The no-arg constructor constructs an instance for the current date, and the methods get(GregorianCalendar.YEAR), get(GregorianCalendar.MONTH), and get(GregorianCalendar.DAY_OF_MONTH) return the year, month, and day.Write a program to perform two tasks:■ Display the current year, month, and day.■ The GregorianCalendar class has the setTimeInMillis(long), which can be used to set a specified elapsed time since January 1, 1970. Set the value to 1234567898765L and display the year, month, and day.2.4(Y. Daniel Liang英文版八版P337:9.11**) (Sorting characters in a string) Write a method that returns a sorted string using the following header:public static String sort(String s)For example, sort("acb") returns abc.Write a test program that prompts the user to enter a string and displays the sorted string.2.5(Y. Daniel Liang

实验5 常用(2学时) 一、实验目的 1. 熟悉Java中的String、StringBuffer、Math、包装器的使用方法。 2. 使用常用解决一般性的应用问题。 3. 掌握JavaSE API文档的使用方法。 二、实验内容 1. 编写一个程序,输出一个字符串中的大写英文字母数,小写英文字母数以及非英文字母数。(字符串可以在main方法中指定) 2. 调用java.lang.Math的成员函数“public static double random()”运算下面表达式1000次,(int) (Math.random()*20+0.5),统计其中生成的整数0、1、2、……、20的个数分别是多少,并输出统计结果。 3. 编写一个方法,返回一个double型的二维数组,数组中的元素通过解析字符串参数获得。例如,字符串参数:“1,2;3,4,5;6,7,8”,对应的数组为: d[0,0] = 1.0 d[0,1] = 2.0 d[1,0] = 3.0 d[1,1] = 4.0 d[1,2] = 5.0 d[2,0] = 6.0 d[2,1] = 7.0 d[2,2] = 8.0 三、实验要求 完成程序设计并提交实验报告。 实验6 容器(2学时) 一、实验目的 1. 熟悉容器库中常用的使用方法。 2. 使用常用容器解决一般性的应用问题。 二、实验内容 1. 用HashMap模拟一个网上购物车。要求:从键盘输入5本书的名称、单价、购买数量,将这些信息存入一个HashMap,然后将该HashMap作为参数调用方法getSum(HashMap books),该方法用于计算书的总价并返回。【说明:键盘输入可以使用Scanner】 2. 使用两个Stack(JDK容器库中的Stack)实现一个队列MyQueue,提供队列的入队列和出队列操作:enQueue和deQueue。 3. 写一个彩票程序:30选7。随机(1~30之间)生成7个随机数,注意不能重复。然后从键盘输入7个数,对比7个数是否与随机数有相同的。最后显示“中了几个号”。同时,如果中了7个号,显示一等奖;如果中了6个号,显示二等奖;如果中了5个号,显示三等奖。要求:首先写出程序的实现思想,特别是程序所使用的数据结构,然后写出Java实现代码。【说明:键盘输入可以使用Scanner】 三、实验要求 完成程序设计并提交实验报告。 实验7 流(2学时) 一、实验目的 1. 熟悉流库中各种常用流的使用方法。 2. 能够使用流实现基本的文件读写。 二、实验内容 1. 编写程序,在控制台窗口提示输入两个整数,然后接收这两个整数,并输出它们的和。(要求:键盘输入通过流封装System.in获取,不要使用Scanner) 2. 设计学生Student,属性:编号(整型);姓名(字符串),成绩(整型)。编写一个程序:要求:(1)输入5个学生的姓名和成绩,将其姓名和成绩保存到data.txt中;(2)然后从该文件中读取数据,求得这五个学生的平均成绩。 三、实验要求 完成程序设计并提交实验报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值