2016级 JavaSE(智能设备1班)

2018-3-4 09:32
请先登录。

创建了 #2016级 JavaSE(智能设备1班)# 任务:

10 流和文件
1. 使用字节输入流和字节输出流读取并拷贝本地磁盘上的一张图片2. 使用BufferedReader和BufferedWriter读取本地文本文件,并以追加的方式拷贝文件3. 使用Scanner对象读取用户输入的学生信息,根据输入信息创建学生对象,并实现学生信息的...

作业交晚了 发在这里吧

package firearm;

public class Gun {
private int serialnum;
private String modelnum;
private int clip;
private int reloadnum;
public Gun() {
	this.serialnum=1;
	this.modelnum="M54";
	this.reloadnum=6;
	this.clip=12;
}
public Gun(int snum,String mnum,int rnum) {
	this.serialnum=snum;
	this.modelnum=mnum;
	this.reloadnum=rnum;
	this.clip=12;
}
public int getSerialnum() {
	return serialnum;
}
public String getModelnum() {
	return modelnum;
}
public int getClip() {
	return clip;
}
public int getReloadnum() {
	return reloadnum;
}
public void reload() throws FullOfException{
	if(this.reloadnum==12) {
		throw new FullOfException();
	}
	reloadnum++;
}
public int shoot() throws EmptyOfException{
	if(this.reloadnum==0) {
		throw new EmptyOfException();
	}
	reloadnum--;
	return reloadnum;
}
public void watch() {
	System.out.println(this.getSerialnum()+'-'+this.getModelnum());
	
}
public int Clipnum() {
	return reloadnum;
}
}
package firearm;

public class Ball {
private int Queuenum;
private String Versionnum;
public Ball() {
	Queuenum=1;
	Versionnum="M54";
}
public Ball(int Qnum,String Vnum) {
	this.Queuenum=Qnum;
	this.Versionnum=Vnum;
}
public int getQueuenum() {
	return this.Queuenum;
}
public String getVersionnum() {
	return this.Versionnum;
}
public void getQVnum() {
	System.out.println(this.getQueuenum()+'-'+this.getVersionnum());
}
}

package firearm;

@SuppressWarnings("serial")
public class EmptyOfException extends Exception{
public String getMessage() {
	return "the clip is empty";
}
}

package firearm;

public class FullOfException extends Throwable {
public String getMessage() {
	return "the clip is full";
}
}

package firearm;

public class Test {
public static void main(String[] args) {
	Gun gun=new Gun();
	while(true)
	{
		System.out.println(gun.Clipnum());
		try {
			gun.reload();
		}catch(FullOfException e) {
			System.out.println(e.getMessage());
			break;
		}
	}
	while(true)
	{
		try {
			System.out.println(gun.shoot());
			
		}catch(EmptyOfException e) {
			System.out.println(e.getMessage());
			break;
		}
	}
}
}