People:
package testPackage;
public class People {
private int age;
public String name;
protected String idCard; //身份證號
String sex;
}
Customer:
/**
- 存放客戶個人信息
- @author Administrator
*/
public class Customer {
private String name; //客戶姓名
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Room:
public class Room {
private String roomNo; //存放房間號
private boolean empty; //判斷是否有人住
private Customer customer; //存放客戶信息
public String getRoomNo() {
return roomNo;
}
public void setRoomNo(String roomNo) {
this.roomNo = roomNo;
}
public boolean isEmpty() {
return empty;
}
public void setEmpty(boolean empty) {
this.empty = empty;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Room()
{
}
public Room(String roomNo)
{
this.roomNo = roomNo;
this.empty = true;
}
/**
* 房間入住
* 1 判斷是否有人住
* 2 輸入入住者姓名
* @param customer
*/
public void getInMethod(Customer customer)
{
this.empty = false;
this.customer = customer;
}
/**
* 退房
* 1 房間狀態(tài)為empty
* 2 入住者姓名為空
*/
public void outOfRoomMethod()
{
this.empty = true;
this.customer = null;
}
}
RoomManager:
/**
- 類似首頁
- 第一個展示在用戶面前的界面
- @author Administrator
*/
public class RoomManageSystem {
//引用數據類型
private Hotel hotel;
public RoomManageSystem() {
}
public RoomManageSystem(Hotel hotel) {
this.hotel = hotel;
}
public void start() {
Scanner sc = new Scanner(System.in);
boolean isRunning = true;
while(isRunning)
{
printMenu();
int choice = sc.nextInt();
switch (choice) {
case 1:
hotel.searchStatus();
break;
case 2:
System.out.println("請輸入房間號");
int roomNo = sc.nextInt();
System.out.println("請輸入客戶姓名");
String customerName = sc.next();
hotel.getInRoom(roomNo, customerName);
break;
case 3:
System.out.println("請輸入房間號");
int outRoomNo = sc.nextInt();
hotel.outOfRoom(outRoomNo);
break;
case 4:
System.out.println("再見");
break;
default:
break;
}
}
}
public void printMenu()
{
System.out.println("-----菜單-------");
System.out.println("1-查詢所有房間狀態(tài)");
System.out.println("2-入住");
System.out.println("3-退房");
System.out.println("4-退出系統(tǒng)");
System.out.println("---------------");
}
}
Hotel:
public class Hotel {
private Room rooms[][];
/**
* 酒店房間的初始化
*/
public Hotel()
{
rooms = new Room[10][12];
for(int i = 0; i < rooms.length;i ++)
{
for(int j = 0 ; j < rooms[i].length ; j++ )
{
String roomNo = "";
//層的設置
roomNo += i<9 ? "0"+(i+1):(i+1);
//房間號設置
roomNo += j<9 ? "0"+(j+1):(j+1);
rooms[i][j] = new Room(roomNo);
}
}
}
/**
* 查詢房間狀態(tài)
*/
public void searchStatus()
{
for(int i = 0; i < rooms.length;i ++)
{
for(int j = 0 ; j < rooms[i].length ; j++ )
{
//取其中一個房間
Room r = rooms[i][j];
System.out.print(r.getRoomNo()+","+r.isEmpty());
if(!r.isEmpty())
{
System.out.print(","+r.getCustomer().getName());
}
System.out.print("\t");
}
System.out.println();
}
}
/**
* 房間入住
*/
public void getInRoom(int roomNo, String customer)
{
int i = roomNo/100 -1;
int j = roomNo%100 -1;
Room r = rooms[i][j];
if(r.isEmpty())
{
Customer c = new Customer();
//如果是空 設置用戶姓名
c.setName(customer);
r.getInMethod(c);
}
else
{
System.err.println("入住失敺嫦病葵擎!");
}
}
/**
* 退房
*/
public void outOfRoom(int roomNo)
{
int i = roomNo / 100 -1;
int j = roomNo % 100 -1;
Room r = rooms[i][j];
if(!r.isEmpty())
{
r.outOfRoomMethod();
}
else {
System.out.println("退房失敗");
}
}
}
Person:
public class Person{
public int age;
public String name;
protected String idCard; //身份證號
String sex;
// public Person()
// {
// System.out.println("person的無參構造");
// }
public Person(int age,String name)
{
this.age = age;
this.name = name;
System.out.println("person的有參構造");
}
public void eat()
{
System.out.println("吃飯");
}
public void run()
{
System.out.println("跑步");
}
public void drink()
{
System.out.println("喝水");
}
}
Test01:
public class Test01 extends People{
private final static double PI = 3.14;
// private static int age;
public static void main(String[] args) {
/*
final Test02 test02 = new Test02();
test02.setName("zhangsan");
System.out.println(test02.getName());
test02.setName("lisi");
System.out.println(test02.getName());
Test01 test01 = new Test01();
test01.getMethod();
*/
Person person = new Person(1000, "lisi");
Student student = new Student();
student.eat();
System.out.println(person.name);
System.out.println(person.age);
// student.idCard = "341124....";
// student.name = "zhangsan";
// student.sex = "男";
// student.age = 10;
/*
//不同包且沒有繼承關系
People p = new People();
p.name = "zhangsan";
p.sex = "nan";
p.idCard = "546546";
p.age = 10;
*/
/*
//不同包但有繼承關系
Test01 test01 = new Test01();
test01.name = "zhangsan";
test01.sex = "nan";
test01.idCard = "546546";
test01.age = 10;
*/
}
/**
* 代碼塊
*/
{
//創(chuàng)建對象時執(zhí)行
}
/**
* 靜態(tài)代碼塊
*/
static{
//類加載時執(zhí)行 且只執(zhí)行一次
}
public void getMethod()
{}
public static void someMethod()
{
}
}
Test02:
public class Test02{
private String name;
private int age;
private static String sex;
{
System.out.println("代碼塊");
}
static {
System.out.println("靜態(tài)代碼塊");
}
public Test02()
{
System.out.println("構造函數");
}
public static String getSex() {
return sex;
}
public static void setSex(String sex) {
Test02.sex = sex;
}
public static void main(String[] args) {
Test02.getSth();
}
public static void getSth()
{
System.out.println("something");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}