java写的订房系统(对于加深基础很有帮助)作业题
生活随笔
收集整理的這篇文章主要介紹了
java写的订房系统(对于加深基础很有帮助)作业题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
java寫的訂房系統(對于加深基礎很有幫助)
1.是用數組寫的,拿去運行就行了,注釋詳細,不怕看不懂,適合小白,也是很多學java經常碰見的作業
public class Room extends Object{private int roomId;//房間的標編號private String roomType;//房間的類型private boolean roomStatus; //房間的狀態 true 表示空閑,false表示占用@Overridepublic boolean equals(Object o) {if (this == o) return true;if (!(o instanceof Room)) return false;Room room = (Room) o;return getRoomId() == room.getRoomId() &&getRoomStatus() == room.getRoomStatus() &&Objects.equals(getRoomType(), room.getRoomType());}@Overridepublic String toString() {return "Room{" +"房間編號=" + roomId +", 房間類型='" + roomType + '\'' +", 房間狀態=" + (roomStatus?"空閑":"占用") +'}';}@Overridepublic int hashCode() {return Objects.hash(getRoomId(), getRoomType(), getRoomStatus());}public Room() {}public Room(int roomId, String roomType, boolean roomStatus) {this.roomId = roomId;this.roomType = roomType;this.roomStatus = roomStatus;}public int getRoomId() {return roomId;}public void setRoomId(int roomId) {this.roomId = roomId;}public String getRoomType() {return roomType;}public void setRoomType(String roomType) {this.roomType = roomType;}public boolean getRoomStatus() {return roomStatus;}public void setRoomStatus(boolean roomStatus) {this.roomStatus = roomStatus;} }2.一共兩個public類,另一個請創建新的
public class Hotel {//酒店里面有二維數組,里面有房間private Room[][] rooms;public Room[][] getRooms() {return rooms;}public void setRooms(Room[][] rooms) {this.rooms = rooms;}public Hotel() {rooms=new Room[ 3][10];for (int i = 0; i < rooms.length; i++) {int row=100;String roomtype;if(i==0){roomtype="小房間";}else if (i==1){roomtype="大房間";}else{roomtype="總統套房";}for (int i1 = 0; i1 < rooms[i].length; i1++) {int list=row;rooms[i][i1]=new Room((i+1)*100+i1,roomtype,true);}}}public void printRoomStatus(){for (int i = 0; i < rooms.length; i++) {for (int i1 = 0; i1 < rooms[i].length; i1++) {System.out.print(rooms[i][i1]+" ");if(i1%4==0){System.out.println();}}}}public void order(int roomNumber){int c=roomNumber/100;int d=(roomNumber-c*100)/10;int m=(roomNumber-c*100-d*10);Room room = rooms[c][d+m];if(rooms[c][d+m].getRoomStatus()==false){System.out.println("此房間已滿請選擇其他房間");return;}room.setRoomStatus(false);System.out.println("訂房成功");}public void exit(int roomNumber){int c=roomNumber/100;int d=(roomNumber-c*100)/10;int m=(roomNumber-c*100-d*10);Room room = rooms[c][d+m];room.setRoomStatus(true);System.out.println("退房成功");}public void hotelSystem(){System.out.println("輸入1 表示訂房,輸入2表示查看房間狀態,輸入3推出系統");Scanner scanner=new Scanner(System.in);System.out.println("請輸入編號");int choice=scanner.nextInt();switch (choice){case 1:{System.out.println("下面展示房間的狀態");System.out.println("-------------------------------------------------------------------------------");printRoomStatus();System.out.println("-------------------------------------------------------------------------------");System.out.println("請輸入房間的編號然后開始訂房");Scanner sc=new Scanner(System.in);int roomNumber;roomNumber=sc.nextInt();order( roomNumber);break;}case 2:{printRoomStatus();}case 3:{System.out.println("歡迎下次使用");break;}}}} class Customer{private Hotel hotel;public Hotel getHotel() {return hotel;}public void setHotel(Hotel hotel) {this.hotel = hotel;}public Customer() {hotel=new Hotel();}public static void main(String[] args){Customer xiaoming=new Customer();xiaoming.hotel.hotelSystem();}}3.拿去看看。多理解,對java學習很有幫助,這也是很多學java的朋友經常會碰到的一道作業把
總結
以上是生活随笔為你收集整理的java写的订房系统(对于加深基础很有帮助)作业题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7 linux添加win7,
- 下一篇: STC-B学习板蜂鸣器播放音乐