题目要求:
学生可以在学校的图书馆里借书。
图书分为五类(BookType:枚举类型)
- SCIENCE(科学)
- MEDICINE(医药)
- LITERATURE(文学
- FOODCOOKING(饮食)
- MAGAZINE(杂志)
图书的出版社也有以下几个(Press:枚举类型)
- 清华大学出版社
- 北京大学出版社
- 电子工业出版社
- 机械工业出版社
- 杂志期刊主办商
读者的性别 (Sex:枚举类型)
- 女
- 男
读者类(Reader)
- 有姓名和性别的属性,可以借阅多本
- 要求能够打印读者借阅书本的信息
图书类(Book)
- 有图书名称、出版社、 图书类型的属性
package experiment1;
public class LibraryDemo {
enum BookType{
SCIENCE,//(科学)
MEDICINE,//(医药)
LITERATURE,//(文学)
FOODCOOKING,//(饮食)
MAGAZINE//(杂志)
}//图书类型枚举
enum Press{
QINGHUA,//清华大学出版社
BEIJING,//北京大学出版社
DIANZI,//电子工业出版社
JIXIE,//机械工业出版社
ZAZHI//杂志期刊主办商
} //出版社类型枚举
enum Sex{
MALE("男"),//男
FEMALE("女");//女
private String sexString;
private Sex(String sex) {
this.sexString = sex;
}
public String getSex() {
return this.sexString;
}
} //性别枚举
class Book{ //图书类
String bookName;
Press press;
BookType bookType;
void printBookType(int i) {
switch (i) {
case 1: {
System.out.print("科学 ");
System.out.println(BookType.SCIENCE);
break;
}
case 2: {
System.out.print("医药 ");
System.out.println(BookType.MEDICINE);
break;
}
case 3: {
System.out.print("文学 ");
System.out.println(BookType.LITERATURE);
break;
}
case 4: {
System.out.print("饮食 ");
System.out.println(BookType.FOODCOOKING);
break;
}
case 5: {
System.out.print("杂志 ");
System.out.println(BookType.MAGAZINE);
break;
}
default:
System.out.print("Wrong!");
break;
}
}
void printPress(int i) {
switch (i) {
case 1: {
System.out.print("清华大学出版社");
break;
}
case 2: {
System.out.print("北京大学出版社");
break;
}
case 3: {
System.out.print("电子工业出版社");
break;
}
case 4: {
System.out.print("机械工业出版社");
break;
}
case 5: {
System.out.print("杂志期刊主办商");
break;
}
default:
System.out.print("Wrong!");
break;
}
}
void printBorrowStatus(int i) {
switch (i) {
case 1: {
System.out.print("办理借阅");
break;
}
case 2: {
System.out.print("不能租借");
break;
}
}
}
void printBookInfo(String bookNameString,int press,int status ,int booktype){
Book book = new Book();
book.bookName = bookNameString;
System.out.print(book.bookName);
System.out.print(" ");
printPress(press);
System.out.print(" ");
printBorrowStatus(status);
System.out.print(" ");
printBookType(booktype);
}//打印图书信息
}
class Reader{ //读者类
String readerName;
Sex sex;
Book[] books;
void printBorrowInfo(String readerNameString,int i){
Reader reader = new Reader();
reader.readerName = readerNameString;
System.out.print("读者姓名:"+readerNameString + " ");
switch (i) {
case 1: {
System.out.print("性别:" +Sex.MALE.sexString+ " ");
break;
}
case 0: {
System.out.print("性别:" +Sex.FEMALE.sexString+ " ");
break;
}
default:
System.out.print("wrong!"+ " ");
}
System.out.println("该读者的借阅信息如下:");
System.out.println("图书名称" + " " +"出版社" + " "+"借阅" + " "+"编号" + " "+"类型描述" + " ");
System.out.println("===================================");
} //打印该读者的借阅信息
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
LibraryDemo libraryDemo = new LibraryDemo();
Reader reader1 = libraryDemo.new Reader();
Book book1 = libraryDemo.new Book();
reader1.printBorrowInfo("李红",0);
book1.printBookInfo("数据库原理",1,1,1);
book1.printBookInfo("医学与美容",2,1,2);
book1.printBookInfo("平凡的世界",3,1,3);
System.out.println();
Reader reader2 = libraryDemo.new Reader();
Book book2 = libraryDemo.new Book();
reader2.printBorrowInfo("肖明",1);
book2.printBookInfo("饮食与健康",4,1,4);
book2.printBookInfo("计算机基础",2,1,1);
book2.printBookInfo("计算机科学",5,2,5);
}
}
运行结果: