//Room类
package TEST04;
public class Room
{
String RoomID;
String RoomArea;
double Price;
String RentType;
public Room(String roomID, String roomArea, double price, String rentType)
{
RoomID = roomID;
RoomArea = roomArea;
Price = price;
RentType = rentType;
}
public String getRoomID()
{
return RoomID;
}
public String getRoomArea()
{
return RoomArea;
}
public double getPrice()
{
return Price;
}
public String getRentType()
{
return RentType;
}
public void setRoomID(String roomID)
{
RoomID = roomID;
}
public void setRoomArea(String roomArea)
{
RoomArea = roomArea;
}
public void setPrice(double price)
{
Price = price;
}
public void setRentType(String rentType)
{
RentType = rentType;
}
@Override
public String toString() {
return "Room{" +
"RoomID='" + RoomID + '\'' +
", RoomArea='" + RoomArea + '\'' +
", Price=" + Price +
", RentType='" + RentType + '\'' +
'}';
}
}
//以出租房屋类
package TEST04;
public class RentRoom extends Room
{
boolean rentState;
public RentRoom(String roomID, String roomArea, double price, String rentType, boolean rentState)
{
super(roomID, roomArea, price, rentType);
this.rentState = rentState;
}
public boolean isRentState() {
return rentState;
}
public void setRentState(boolean rentState) {
this.rentState = rentState;
}
@Override
public String toString()
{
return "RentRoom{" +
"rentState=" + rentState +
", RoomID='" + RoomID + '\'' +
", RoomArea='" + RoomArea + '\'' +
", Price=" + Price +
", RentType='" + RentType + '\'' +
'}';
}
}
//顾客类
package TEST04;
public class Customer
{
long userID;
String pwd;
String userName;
String location;
double balance;
public Customer(long userID, String pwd, String userName, String location, double balance)
{
this.userID = userID;
this.pwd = pwd;
this.userName = userName;
this.location = location;
this.balance = balance;
}
public long getUserID()
{
return userID;
}
public String getPwd()
{
return pwd;
}
public String getUserName()
{
return userName;
}
public String getLocation()
{
return location;
}
public double getBalance()
{
return balance;
}
public void setUserID(long userID) {
this.userID = userID;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public void setUserName(String userName) {
this.userName = userName;
}
public void setLocation(String location) {
this.location = location;
}
public void setBalance(double balance) {
this.balance = balance;
}
@Override
public String toString()
{
return "Customer{" +
"userID=" + userID +
", pwd='" + pwd + '\'' +
", userName='" + userName + '\'' +
", location='" + location + '\'' +
", balance=" + balance +
'}';
}
}
//VIP顾客类
package TEST04;
public class VIPCustomer extends Customer
{
String grade;
double percent;
int bonusPoints;
public VIPCustomer(long userID, long id, String pwd, String userName, String location, double balance, String grade, double percent, int bonusPoints)
{
super(userID, pwd, userName, location, balance);
this.grade = grade;
this.percent = percent;
this.bonusPoints = bonusPoints;
}
public String getGrade() {
return grade;
}
public double getPercent() {
return percent;
}
public int getBonusPoints() {
return bonusPoints;
}
public void setGrade(String grade) {
this.grade = grade;
}
public void setPercent(double percent) {
this.percent = percent;
}
public void setBonusPoints(int bonusPoints) {
this.bonusPoints = bonusPoints;
}
@Override
public String toString() {
return "VIPCustomer{" +
"grade='" + grade + '\'' +
", percent=" + percent +
", bonusPoints=" + bonusPoints +
", userID=" + userID +
", pwd='" + pwd + '\'' +
", userName='" + userName + '\'' +
", location='" + location + '\'' +
", balance=" + balance +
'}';
}
}
//住房管理系统类
package TEST04;
import java.util.HashMap;
import java.util.Scanner;
public class RentRoomManage
{
HashMap<Integer, VIPCustomer> customerHashMap = new HashMap<>();
HashMap<Integer, RentRoom> roomHashMap = new HashMap<>();
static Scanner in = new Scanner(System.in);
public void addRoom(String roomID, String roomArea, double price, String rentType, boolean rentState)
{
System.out.println("输入您租借的房间号");
int roomNum = in.nextInt();
RentRoom add = new RentRoom(roomID, roomArea, price, rentType, rentState);
roomHashMap.put(roomNum, add);
System.out.println("房间创建成功");
}
public void searchRoom()
{
System.out.println("输入您要查找的房间号");
int searchNum = in.nextInt();
System.out.println("房间是否存在" + roomHashMap.containsKey(searchNum));
if (roomHashMap.containsKey(searchNum) == true) {
System.out.println(roomHashMap.get(searchNum).toString());
}
}
public void deleteRoom()
{
System.out.println("输入您要删除的房间号");
int deleteRoom = in.nextInt();
System.out.println("房间是否存在" + roomHashMap.containsKey(deleteRoom));
if (roomHashMap.containsKey(deleteRoom) == true) {
System.out.println(roomHashMap.remove(deleteRoom).toString());
}
System.out.println("删除成功");
}
public void modifyRoom()
{
System.out.println("请输入您要修改的房间号");
int modifyRoom = in.nextInt();
System.out.println("房间是否存在" + roomHashMap.containsKey(modifyRoom));
if (roomHashMap.containsKey(modifyRoom) == true)
{
System.out.println("请输入房间ID");
String roomID = in.nextLine();
System.out.println("请输入房间ID");
String roomArea = in.nextLine();
System.out.println("请输入房间价格");
double price = in.nextDouble();
System.out.println("租住类型");
String rentType = in.nextLine();
System.out.println("请输入是否已被租借,输入Y/N");
boolean rentState = false;
String are = in.nextLine();
if(are.equals("Y"))
{
rentState = true;
}
RentRoom room = new RentRoom(roomID,roomArea,price,rentType,rentState);
roomHashMap.replace(modifyRoom,room);
System.out.println("修改完成");
}
}
public void showRoom()
{
for (Integer key : roomHashMap.keySet())
{
System.out.println("Key = " + key);
}
for (RentRoom value : roomHashMap.values())
{
System.out.println("Value = " + value.toString());
}
}
public void addCustomer(long userID, String pwd, String userName, String location, double balance, String grade, double percent, int bonusPoints)
{
int addCustomer = in.nextInt();
VIPCustomer add = new VIPCustomer(addCustomer,userID,pwd,userName,location,balance,grade,percent,bonusPoints);
customerHashMap.put(addCustomer, add);
System.out.println("客户创建成功");
}
public void showCustomer()
{
for (Integer key : customerHashMap.keySet())
{
System.out.println("Key = " + key);
}
for (VIPCustomer value : customerHashMap.values())
{
System.out.println("Value = " + value.toString());
}
}
public double RentValue()
{
System.out.println("输入房间号");
int RentNum = in.nextInt();
System.out.println("检测到信息"+roomHashMap.containsKey(RentNum));
double RoomPrice = 0;
if(roomHashMap.containsKey(RentNum) == true)
{
double price = roomHashMap.get(RentNum).getPrice();
double percent = customerHashMap.get(RentNum).getPercent();
RoomPrice = price * percent;
}
System.out.println("房屋租金是" + RoomPrice);
return RoomPrice;
}
public void payment()
{
double RoomPrice = RentValue();
System.out.println("输入租客ID");
int num = in.nextInt();
double balance = customerHashMap.get(num).getBalance();
double payment = balance - RoomPrice;
customerHashMap.get(num).setBalance(payment);
System.out.println("支付完成,余额剩余"+payment);
}
public void Rent()
{
System.out.println("请输入要出租的房屋号码");
int num = in.nextInt();
roomHashMap.get(num).setRentState(true);
}
}