收藏 分销(赏)

西农java英语实习题目.doc

上传人:仙人****88 文档编号:12019414 上传时间:2025-08-28 格式:DOC 页数:5 大小:82KB 下载积分:10 金币
下载 相关 举报
西农java英语实习题目.doc_第1页
第1页 / 共5页
西农java英语实习题目.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
Lab 4 In this lab, you will practice how to use the following classes: l BufferedReader and BufferedWriter l BufferedOutputStream and BufferedIutputStream (Similar to BufferedReader and BufferedWriter, I am sure you can handle them.) l FileOutputStream and FileInputStream l DataOutputStream and DataInputStream l RandomAccessFile l ObjectInputStream and ObjectOutputStream Task 1. Create a class MyLog and it implements one interface called Loggable. This class is used to read and write “MyLog.log” which contains: the current time, the log type and the content. The definition of Loggable is as follows: interfaceLoggable { // Three log types: NFORMATION, WARNING, ERROR enum TYPE { INFORMATION, WARNING, ERROR }; // Add one log, including log type and log content. void addLog(Loggable.TYPE type, String logContent); // Show all the logs in the log file. void readLog(); } The requirements are: l When new logs are added using addLog(), they should be appended to the log file. For example: l When using readLog() to show all the logs in the console, convert all the lower case characters into upper case characters for the contents of each log. For example: ****************************** 2010-12-25 14:40:02 INFORMATION THIS IS A CONTENT STRING ****************************** ****************************** 2010-12-25 14:45:02 INFORMATION THIS IS A CONTENT STRING ****************************** Tips: l Use BufferedReader and BufferedWriter to read and write the log file. l To get the enum value, use:type.toString() in the addLog(). l Pay attention to the date format, you may use the class: SimpleDateFormat. Task 2. Use FileOutputStream and BufferedOutputStream separately to write 1,000,000 random numbers (double) into a binary file (Numbers.dat) and compare the time expenses. Write the results and error messages into MyLog.log (it is the same log file as in the Task 1). l The result is as follows: l The content of the log file is as follows: ****************************** 2011-11-28 15:06:57 INFORMATION Done, cost 573 without buffer ****************************** ****************************** 2011-11-28 15:06:57 INFORMATION Done, cost 9 with buffer ****************************** ****************************** 2010-12-05 15:07:04 ERROR Access Deny!!! ****************************** l After changing the Number.dat into “Read only”,run the program again and add the following log. Tips: l To calculate the time using: longstartTime = System.currentTimeMillis(); // do something longendTime = System.currentTimeMillis(); long cost = endTime - startTime; l Use DataOutputStream and writeDouble()to write data. Task 3. Write code to search data from Numbers.dat by inputting the index of the data you are going to search. The result is as follows: Tips:Use class: RandomAccessFile. Task 4 Write an object of Student in to Student.txt, and read the object to show the following information: class Student implements Serializable { private static final long serialVersionUID = 1L; int id; int age; String name; String department; public Student(int id, String name, int age, String department) { this.id = id; this.name = name; this.age = age; this.department = department; } }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服