First, write a hotel management system
1. Direct code on
Package com.bjpowernode.java_learning; public class D69_1_ { // write a program to simulate the hotel management system: booking, check-out ....... public static void main (String [] args) { } } class Room { String NO; String of the type; // "standard", "Double", "Deluxe" boolean isUse; // to true representation occupation, false representation idle } class hotel { // provisions hotel: five, ten rooms on each floor , standard layer 2, 3, 4 Double layer 5 Deluxe Room [] [] rooms; // no parameter Hotel () { the this (5,10 ); } Hotel ( introws, int cols) { Rooms = new new Room [rows] [cols]; / * * Rooms [0] [0] .... * Rooms [. 4] [. 9] .... * / } // provide external method predetermined }
Second, the user accepts keyboard input
1. The following demonstrates how to accept user input
Package com.bjpowernode.java_learning; Import java.util.Scanner; public class D69_2_AcceptUserInput { public static void main (String [] args) { Scanner S = new new Scanner (the System.in); // program runs to here, stop and wait for user input String userInput = s.next (); System.out.println ( "You entered:" + userInput); } }
Third, the use of analog array stack Stack
package com.bjpowernode.java_learning; public class D69_3_ArraysSimulateStack { public static void main(String[] args) { Stack s = new Stack(2); User69 u1 = new User69("jfidsa",12); User69 u2 = new User69("jfiddfsa",12); User69 u3 = new User69("jfidfdsfsa",12); try { s.push(u1); s.push(u2); s.push(u3); }catch(StackOperationException E) { System.out.println (E); } // System.out.println (s.pop ()); } } class Stack { // use arrays to store data, note stack may store a plurality of reference element type Object [] elements; // points to a frame above the top element int index; // stack default initial capacity is 10 stack () { the this (10 ); } stack ( int max) { elements = new new Object [max]; } // stacks should provide a method outside of a push public void Push (Object Element) throws{StackOperationException IF (index == elements.length) { the throw new new StackOperationException ( "the stack is full" ); } Elements [index ++] = Element; } // External provide a method popped public Object POP () throws {StackOperationException IF (index == 0 ) { the throw new new StackOperationException ( "stack is empty" ); } return Elements [- index]; } } class User69 { String name; int Age; User69(String name,int age){ this.name = name; this.age = age; } public String toString() { return "User是我"; } } class StackOperationException extends Exception{ public StackOperationException() {} public StackOperationException(String msg) { super(msg); } }
Fourth, the source code:
D69_1_HotelManageSystem.java
D69_2_AcceptUserInput.java
D69_3_ArraysSimulateStack.java
https://github.com/ruigege66/Java/blob/master/D69_1_HotelManageSystem.java
https://github.com/ruigege66/Java/blob/master/D69_2_AcceptUserInput.java
https://github.com/ruigege66/Java/blob/master/D69_3_ArraysSimulateStack.java
2.CSDN:https://blog.csdn.net/weixin_44630050
3. Park blog: https: //www.cnblogs.com/ruigege0000/
4. Welcomes the focus on micro-channel public number: Fourier transform public personal number, only for learning exchanges, backstage reply "gifts" to get big data learning materials