LTY
2016-10-10 16:17:31浏览 2240
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("请根据提示输入命令");
}
}
}
}