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("请根据提示输入命令");
}
}
}
}
点击查看更多内容
2人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦