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

模拟借书系统 请大神们看看对不对

LTY
关注TA
已关注
手记 1
粉丝 0
获赞 2
public class book {

    private int Id;
    private String Name;
    public int getId() {
        return Id;
    }
    public void setId(int id) {
        Id = id;
    }
    public String getName() {
        return Name;
    }
    public void setName(String name) {
        Name = name;
    }
    public book(int Id,String Name){
        this.Id=Id;
        this.Name=Name;
    }

}
public class LendBook {
    book books [] = {new book (1, "高数"),
                    new book (2, "C语言"),
                    new book (3, "Java")};

    private boolean ifjx=false;
    private static boolean jx=true;
    static Scanner scann=new Scanner(System.in);

    private void one() throws Exception{
        System.out.println("请输入书名");
        String bn=scann.next();
        for(int i=0;i<3;i++){
            if(bn.equals(books[i].getName())){
                System.out.println("book:"+bn);
                ifjx=true;
            }
        }
        if(!ifjx){
            System.out.println("图书不存在");
 throw new Exception("图书不存在");
        }
    }
    private void two() throws Exception{
        System.out.println("请输入序列号");
        int xh=scann.nextInt();
        for(int i=0;i<3;i++){
            if(xh==books[i].getId()){
                System.out.println("book:"+books[i].getName());
                ifjx=true;
            }
        }
        if(!ifjx){
            System.out.println("图书不存在");
throw new Exception("图书不存在");
        }
    }
    private void lend() throws Exception{
        String input=scann.next();
        if(input.equals("1")){
            one();
            jx=false;
        }else if(input.equals("2")){
            two();
            jx=false;
        }else{
            throw new Exception("请根据提示输入命令");
        }
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        LendBook lb=new LendBook();
        while(jx){
            System.out.println("输入命令:"+"1-按书名查找书籍;"+"2-按书名查找书籍");
            try {
                lb.lend();
            } catch (Exception e) {
                // TODO: handle exception
                System.out.println("请根据提示输入命令");
            }
        }
    }

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