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

第三季第一章-----借书系统!

qq_M丶T_0
关注TA
已关注
手记 2
粉丝 1
获赞 13

借书系统,首先创建了一个父类books:
public class books {
int sequence;//属性,序列号
String name;//属性,名称
public books(int sequence, String name) {
// TODO Auto-generated constructor stub
this.name = name;//赋值,以便后面主函数调用
this.sequence=sequence;
}
}

创建子类SerialNumberQuery:
import java.util.Scanner;
public class SerialNumberQuery {
public void SerialNumberQuery(int sequence,String name,books[] bb){
SerialNumberQuery tet=new SerialNumberQuery();
Scanner Qz=new Scanner(System.in);
try {
System.out.println("请输入要查找的书籍序列号:");
int c=Qz.nextInt();
int x=bb[c-1].sequence;
if(c==x){
System.out.println("您借阅的书籍是:"+bb[c-1].name+"\t欢迎再次借阅!");
}} catch (Exception e){
System.out.println("您输入有误或者不存在,请重新输入!");
tet.SerialNumberQuery(sequence, name, bb);
}

    }

}

创建一个子类NameQuery:
import java.util.InputMismatchException;
import java.util.Scanner;
public class NameQuery {
public void NameQuery(int sequence,String name,books[] bb){

    NameQuery tet1=new NameQuery();
    Scanner Qz=new Scanner(System.in);
    try {
        System.out.println("请输入要查找的书籍的书名:");
        String c=Qz.next();
        int i;
        for( i=0;i<bb.length;i++){  
            //System.out.println(bb[i]);
             if(c.equals(bb[i].name)){
                  break;}
        } 
         System.out.println("您借阅的书籍是:"+bb[i].name+"\t欢迎再次借阅!");
        } catch (Exception e){
                System.out.println("您输入有误或者不存在,请重新输入!");
                tet1.NameQuery(sequence, name, bb);

        }

}
}
主函数function:
import java.util.Scanner;
public class function {
private static int sequence;
private static String name;
static books[] bb={new books(1,"高数"),
new books(2,"论语"),
new books(3,"英语")
};

public static void main(String[] args) {
    Scanner Qz=new Scanner(System.in);
    // TODO Auto-generated method stub
    SerialNumberQuery tet=new SerialNumberQuery();
    NameQuery tet1=new NameQuery();
    System.out.println("*****请问您是否需要查阅书籍?*****");
    System.out.println("是请输入1\t否请输入0");
    int a=Qz.nextInt();
    if(a==1){
    System.out.println("按序列查找请按1:");
    System.out.println("按书名查找请按0:");
    int b=Qz.nextInt();
    switch (b) {
    case 1:
        tet.SerialNumberQuery(sequence, name, bb);

        break;
    case 0:
        tet1.NameQuery(sequence, name, bb);
        break;

    }

        System.out.println("欢迎下次再来!!!");
    }
    else{
        System.out.println("欢迎下次再来!!!");
    }
}

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