继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

java第三季 模拟借书系统

慕函数2777295
关注TA
已关注
手记 1
粉丝 2
获赞 5

package library;
import java.util.Scanner;
public class borrowBook {
public String book[][]= {{"001","高数"},{"002","英语"},{"003","语文"}};
public void Solve() throws CommandException,NotFoundException{
Scanner input=new Scanner(System.in);
int a=1;
while(a==1) {
System.out.println("请选择查询方式:1.按照名称查找图书;2.按照序号查找图书");
int choose=input.nextInt();
boolean falg=false;
switch(choose) {
case 1:
System.out.println("输入图书名称:");
String BookName=input.next();
try{
for(int i=0;i<book.length;i++) {
if(book[i][1].equals(BookName)) {
System.out.println("book:"+book[i][1]);
falg=true;
}
}
if(falg==false)
throw new NotFoundException("图书不存在!");
}catch(NotFoundException e) {
System.out.println("图书不存在!");
}
break;
case 2:
System.out.println("输入图书序号:");
String BookNumber=input.next();
try {
for(int i=0;i<book.length;i++) {
if(book[i][0].equals(BookNumber)) {
System.out.println("book:"+book[i][1]);
falg=true;
}
}
if(falg==false)
throw new NotFoundException("图书不存在!");
}catch(NotFoundException e) {
System.out.println("图书不存在!");
}
break;
default:
try {
throw new CommandException("命令输入错误!请根据提示输入数字命令!");
}catch(CommandException e) {
System.out.println("命令输入错误!请根据提示输入数字命令!");
}
}
}
}
public static void main(String[] args) {
borrowBook main=new borrowBook();
try {
main.Solve();
}
catch(CommandException e) {
e.printStackTrace();
}
catch(NotFoundException e) {
e.printStackTrace();
}
catch(Exception e) {

    }
}

}

package library;

public class CommandException extends Exception{

    public CommandException() {

    }
    public  CommandException(String e) {
        super(e);
    }

}

package library;

public class NotFoundException extends Exception{
public NotFoundException() {

}
public NotFoundException(String e) {
    super(e);
}

}

打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP