package Libary;
public class Book
{
String ISBN;
String bookName;
String author;
String publisher;
double price;
public Book( String isbn ,String name ,String author ,String publisher ,double price)
{
ISBN = isbn;
bookName = name;
author = author;
publisher = publisher;
price = price;
}
public String getISBN()
{
return ISBN;
}
public String getBookName()
{
return bookName;
}
public String getauthor()
{
return author;
}
public String getPublisher()
{
return publisher;
}
public double getPrice()
{
return price;
}
public void setISBN(String ISBN)
{
this.ISBN = ISBN;
}
public void setBookName(String bookName)
{
this.bookName = bookName;
}
public void setAuthor(String author)
{
this.author = author;
}
public void setPublisher(String publisher)
{
this.publisher = publisher;
}
public void setPrice(double price)
{
this.price = price;
}
@Override
public String toString()
{
return "Book{" +
"ISBN='" + ISBN + '\'' +
", bookName='" + bookName + '\'' +
", author='" + author + '\'' +
", publisher='" + publisher + '\'' +
", price=" + price +
'}';
}
}
package Libary;
public class Book
{
String ISBN;
String bookName;
String author;
String publisher;
double price;
public Book( String isbn ,String name ,String author ,String publisher ,double price)
{
ISBN = isbn;
bookName = name;
author = author;
publisher = publisher;
price = price;
}
public String getISBN()
{
return ISBN;
}
public String getBookName()
{
return bookName;
}
public String getauthor()
{
return author;
}
public String getPublisher()
{
return publisher;
}
public double getPrice()
{
return price;
}
public void setISBN(String ISBN)
{
this.ISBN = ISBN;
}
public void setBookName(String bookName)
{
this.bookName = bookName;
}
public void setAuthor(String author)
{
this.author = author;
}
public void setPublisher(String publisher)
{
this.publisher = publisher;
}
public void setPrice(double price)
{
this.price = price;
}
@Override
public String toString()
{
return "Book{" +
"ISBN='" + ISBN + '\'' +
", bookName='" + bookName + '\'' +
", author='" + author + '\'' +
", publisher='" + publisher + '\'' +
", price=" + price +
'}';
}
}
package Libary;
public class Reader
{
private String Password;
private int ID;
private String Name;
double Balance;
private static int nextReaderID;
static
{
nextReaderID = 10000001;
}
public int GetID1()
{
System.out.println("您的账号初始ID为"+ID);
return ID;
}
public int GetID2()
{
System.out.println("您的账号ID为"+ID);
return ID;
}
public void setPassword(String password)
{
this.Password = password;
}
public void setID(int id)
{
this.ID = id;
}
public void setName(String name)
{
this.Name = name;
}
public void setBalance(double balance)
{
Balance = balance + Balance;
System.out.println("充值成功");
}
public void SpentBalance(double balance)
{
Balance = balance - Balance;
System.out.println("消费成功");
}
public String GetPassword()
{
System.out.print("您设置的密码是:");
return Password;
}
public String GetName()
{
System.out.print("您设置的用户名是:");
return Name;
}
public double GetBalance()
{
System.out.print("您当前的余额为:");
return Balance;
}
public Reader()
{
ID = nextReaderID++;
Name = "";
Password = "66666666";
Balance = 0;
}
Reader(String name)
{
this();
this.Name = name;
}
@Override
public String toString()
{
return "Reader{" +
"Password='" + Password + '\'' +
", ID=" + ID +
", Name='" + Name + '\'' +
", Balance=" + Balance +
'}';
}
}
package Libary;
public class Reader
{
private String Password;
private int ID;
private String Name;
double Balance;
private static int nextReaderID;
static
{
nextReaderID = 10000001;
}
public int GetID1()
{
System.out.println("您的账号初始ID为"+ID);
return ID;
}
public int GetID2()
{
System.out.println("您的账号ID为"+ID);
return ID;
}
public void setPassword(String password)
{
this.Password = password;
}
public void setID(int id)
{
this.ID = id;
}
public void setName(String name)
{
this.Name = name;
}
public void setBalance(double balance)
{
Balance = balance + Balance;
System.out.println("充值成功");
}
public void SpentBalance(double balance)
{
Balance = balance - Balance;
System.out.println("消费成功");
}
public String GetPassword()
{
System.out.print("您设置的密码是:");
return Password;
}
public String GetName()
{
System.out.print("您设置的用户名是:");
return Name;
}
public double GetBalance()
{
System.out.print("您当前的余额为:");
return Balance;
}
public Reader()
{
ID = nextReaderID++;
Name = "";
Password = "66666666";
Balance = 0;
}
Reader(String name)
{
this();
this.Name = name;
}
@Override
public String toString()
{
return "Reader{" +
"Password='" + Password + '\'' +
", ID=" + ID +
", Name='" + Name + '\'' +
", Balance=" + Balance +
'}';
}
}
package Libary;
import java.util.Scanner;
public class LibarySystem
{
static int num = 0;
static Scanner in = new Scanner(System.in);
private static void Welcome()
{
System.out.println("欢迎来到图书馆");
System.out.println("1.创建个人账号");
System.out.println("2.我要借书");
}
private static void Done()
{
System.out.println("--------------");
System.out.println("您的设置完成");
System.out.println("--------------");
}
private static void Password()
{
System.out.println("设置您的密码");
}
private static void Hello()
{
System.out.println("由于本馆数据库系统尚未部署完成,目前仅支持内部借书服务");
System.out.println("您现在正以管理员的身份进行操作");
}
private static void Error()
{
System.out.println("您的输入有误");
}
public static void main(String args[])
{
boolean run = true;
while(run == true)
{
Welcome();
int choice = in.nextInt();
switch(choice)
{
case 1:
{
Reader R = new Reader();
R.GetID1();
Password();
String password = in.next();
if(password.length() <= 7)
{
System.out.println("密码长度不得少于8位");
Password();
password = in.next();
}
R.setPassword(password);
Done();
System.out.println("选择一个你喜欢的名字吧");
String name = in.next();
R.setName(name);
Done();
System.out.println(R.GetBalance());
System.out.println(R.GetName());
System.out.println(R.GetPassword());
break;
}
case 2:
{
Hello();
Reader r = new Reader();
r.setName("郭靖");
Book sdyxz = new Book("001","射雕英雄传","金庸","商务印书馆",27.99);
Book sdxl = new Book("002","神雕侠侣","金庸","商务印书馆",27.99);
Book sjecl = new Book("003","书剑恩仇录","金庸","商务印书馆",27.99);
Book tlbb = new Book("004","天龙八部","金庸","商务印书馆",27.99);
Book yttlj = new Book("005","倚天屠龙记","金庸","商务印书馆",27.99);
System.out.println(r.GetBalance());
System.out.println("您是否要充值账户,确认需要充值输入1,否输入2");
int decision = in.nextInt();
switch(decision)
{
case 1:
{
System.out.println("您充值的金额是:");
double Balance = in.nextDouble();
if(Balance < 0)
{
System.out.print("充值金额不能为负数,");
System.out.println("您充值的金额是:");
Balance = in.nextDouble();
}
r.setBalance(Balance);
break;
}
case 2:
{
System.out.println("金额不足将无法借书");
break;
}
default:
{
Error();
break;
}
}
System.out.print("馆内现藏的书有");
System.out.println(sdyxz);
System.out.println(sdxl);
System.out.println(sjecl);
System.out.println(tlbb);
System.out.println(yttlj);
System.out.println("请输入您要借的书的编号");
int num = in.nextInt();
double price = 0.0;
if(num == 001)
{
price = sdyxz.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sdyxz);
}
else if(num == 002)
{
price = sdxl.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sdxl);
}
else if(num == 003)
{
price = sjecl.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sjecl);
}
else if(num == 004)
{
price = tlbb.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(tlbb);
}
else if(num == 005)
{
price = yttlj.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(yttlj);
}
else
{
Error();
}
break;
}
default:
{
Error();
break;
}
}
}
}
}
package Libary;
import java.util.Scanner;
public class LibarySystem
{
static int num = 0;
static Scanner in = new Scanner(System.in);
private static void Welcome()
{
System.out.println("欢迎来到图书馆");
System.out.println("1.创建个人账号");
System.out.println("2.我要借书");
}
private static void Done()
{
System.out.println("--------------");
System.out.println("您的设置完成");
System.out.println("--------------");
}
private static void Password()
{
System.out.println("设置您的密码");
}
private static void Hello()
{
System.out.println("由于本馆数据库系统尚未部署完成,目前仅支持内部借书服务");
System.out.println("您现在正以管理员的身份进行操作");
}
private static void Error()
{
System.out.println("您的输入有误");
}
public static void main(String args[])
{
boolean run = true;
while(run == true)
{
Welcome();
int choice = in.nextInt();
switch(choice)
{
case 1:
{
Reader R = new Reader();
R.GetID1();
Password();
String password = in.next();
if(password.length() <= 7)
{
System.out.println("密码长度不得少于8位");
Password();
password = in.next();
}
R.setPassword(password);
Done();
System.out.println("选择一个你喜欢的名字吧");
String name = in.next();
R.setName(name);
Done();
System.out.println(R.GetBalance());
System.out.println(R.GetName());
System.out.println(R.GetPassword());
break;
}
case 2:
{
Hello();
Reader r = new Reader();
r.setName("郭靖");
Book sdyxz = new Book("001","射雕英雄传","金庸","商务印书馆",27.99);
Book sdxl = new Book("002","神雕侠侣","金庸","商务印书馆",27.99);
Book sjecl = new Book("003","书剑恩仇录","金庸","商务印书馆",27.99);
Book tlbb = new Book("004","天龙八部","金庸","商务印书馆",27.99);
Book yttlj = new Book("005","倚天屠龙记","金庸","商务印书馆",27.99);
System.out.println(r.GetBalance());
System.out.println("您是否要充值账户,确认需要充值输入1,否输入2");
int decision = in.nextInt();
switch(decision)
{
case 1:
{
System.out.println("您充值的金额是:");
double Balance = in.nextDouble();
if(Balance < 0)
{
System.out.print("充值金额不能为负数,");
System.out.println("您充值的金额是:");
Balance = in.nextDouble();
}
r.setBalance(Balance);
break;
}
case 2:
{
System.out.println("金额不足将无法借书");
break;
}
default:
{
Error();
break;
}
}
System.out.print("馆内现藏的书有");
System.out.println(sdyxz);
System.out.println(sdxl);
System.out.println(sjecl);
System.out.println(tlbb);
System.out.println(yttlj);
System.out.println("请输入您要借的书的编号");
int num = in.nextInt();
double price = 0.0;
if(num == 001)
{
price = sdyxz.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sdyxz);
}
else if(num == 002)
{
price = sdxl.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sdxl);
}
else if(num == 003)
{
price = sjecl.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(sjecl);
}
else if(num == 004)
{
price = tlbb.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(tlbb);
}
else if(num == 005)
{
price = yttlj.getPrice();
r.SpentBalance(price);
System.out.print("借阅成功,您借到的书籍信息如下");
System.out.println(yttlj);
}
else
{
Error();
}
break;
}
default:
{
Error();
break;
}
}
}
}
}
package Libary;
public class VIPReader extends Reader
{
private String ReaderGrade;
private double percent;
private int bonusPoints;
public VIPReader(String name,String grade)
{
super(name);
ReaderGrade = grade;
bonusPoints = 0;
SetPercent();
}
public void SetReaderGrade(String grade)
{
ReaderGrade = grade;
SetPercent();
}
public String GetReaderGrade(String garde)
{
return ReaderGrade;
}
public void SetPercent()
{
if(ReaderGrade.equals("VIP"))
{
percent = 0.8;
}
else if (ReaderGrade.equals("普通会员"))
{
percent = 0.9;
}
else
{
percent = 1;
}
}
public double GetPercent()
{
return percent;
}
public void SetBonusPoints(int point)
{
bonusPoints += point;
}
public double GetBonusPoints()
{
return bonusPoints;
}
public boolean PayRent(double rent)
{
if(Balance >= rent)
{
Balance = Balance - rent;
return true;
}
else
{
return false;
}
}
public String toString()
{
return super.toString() + "身份:" + ReaderGrade + "当前积分:" + bonusPoints + "享有折扣率:" + percent;
}
}
package Libary;
public class VIPReader extends Reader
{
private String ReaderGrade;
private double percent;
private int bonusPoints;
public VIPReader(String name,String grade)
{
super(name);
ReaderGrade = grade;
bonusPoints = 0;
SetPercent();
}
public void SetReaderGrade(String grade)
{
ReaderGrade = grade;
SetPercent();
}
public String GetReaderGrade(String garde)
{
return ReaderGrade;
}
public void SetPercent()
{
if(ReaderGrade.equals("VIP"))
{
percent = 0.8;
}
else if (ReaderGrade.equals("普通会员"))
{
percent = 0.9;
}
else
{
percent = 1;
}
}
public double GetPercent()
{
return percent;
}
public void SetBonusPoints(int point)
{
bonusPoints += point;
}
public double GetBonusPoints()
{
return bonusPoints;
}
public boolean PayRent(double rent)
{
if(Balance >= rent)
{
Balance = Balance - rent;
return true;
}
else
{
return false;
}
}
public String toString()
{
return super.toString() + "身份:" + ReaderGrade + "当前积分:" + bonusPoints + "享有折扣率:" + percent;
}
}
package Libary;
public class RentBook extends Book
{
private String BookNo;
private boolean state;
public RentBook(String isbn ,String name ,String author ,String publisher ,double price,String no)
{
super(isbn,name,author,publisher,price);
BookNo = no;
state = true;
}
public void SetBookNo(String no)
{
BookNo = no;
}
public String GetBookNo()
{
return BookNo;
}
public void SetState(boolean state)
{
this.state = state;
}
public boolean GetState()
{
return state;
}
public String toString()
{
return super.toString() + "入库号" + GetBookNo() + "是否可借" + GetState();
}
}
package Libary;
public class RentBook extends Book
{
private String BookNo;
private boolean state;
public RentBook(String isbn ,String name ,String author ,String publisher ,double price,String no)
{
super(isbn,name,author,publisher,price);
BookNo = no;
state = true;
}
public void SetBookNo(String no)
{
BookNo = no;
}
public String GetBookNo()
{
return BookNo;
}
public void SetState(boolean state)
{
this.state = state;
}
public boolean GetState()
{
return state;
}
public String toString()
{
return super.toString() + "入库号" + GetBookNo() + "是否可借" + GetState();
}
}