Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Iterator;
- import java.util.Random;
- public class HotelProject {
- ArrayList<Guest> guestList = new ArrayList();
- ArrayList<Room> roomList = new ArrayList();
- boolean loggedIn = false;
- Guest g;
- public static void main(String[] args) {
- System.out.println("\n========================== WELCOME TO OUR RESERVATION SYSTEM ============================");
- HotelProject hp = new HotelProject();
- hp.readInGuests();
- System.out.println(" Our hotel currently has " + hp.guestList.size() + " members");
- hp.readInRooms();
- System.out.println(" We offer " + hp.roomList.size() + " types of room");
- System.out.println("=========================================================================================");
- hp.processHotelProject();
- }
- public void processHotelProject() {
- while (true) {
- System.out.println("Please Log In To Begin");
- do {
- System.out.println("Username:");
- Scanner scanner = new Scanner(System.in);
- String username = scanner.next();
- System.out.println("Password:");
- String password = scanner.next();
- g = verifyLogin(username, password);
- } while (g == null);
- System.out.println("Successfully Logged in. Thank you.");
- System.out.println("To make sure you are not a robot please re-enter number below");
- Random rand = new Random();
- int randomNum = rand.nextInt((10000 - 1) + 1) + 1;
- System.out.println(randomNum);
- Scanner scanner = new Scanner(System.in);
- String random = scanner.next();
- if (random.equals(randomNum + "")) {
- System.out.println("Thank you " + g.getPrefix() + ". " + g.getLastName() + " Your balance is: $" + g.getBalance());
- System.out.println("HERE ADD ");
- int selection = processSelection();
- if(selection == 1){
- processBooking();
- } else {
- System.out.println("Thank you " + g.getPrefix() + ". " + g.getLastName() + " for using our system and Good Bye.");
- g = null;
- }
- } else {
- System.out.println("You are a robot! Bye Bye.");
- break;
- }
- }
- }
- public void processBooking(){
- System.out.println("Currently we offer rooms for ");
- printAvailableOccupancies();
- }
- public void printAvailableOccupancies(){
- Map<Integer, Integer> map = new HashMap<Integer, Integer>();
- for(int x = 0; x < roomList.size(); x++){
- System.out.println("adding max allowed:" + (roomList.get(x)).getMaxAllowed());
- map.put(new Integer((roomList.get(x)).getMaxAllowed()).intValue(), new Integer((roomList.get(x)).getMaxAllowed()).intValue());
- }
- System.out.println("ended with:" + map.size());
- Collection<Integer> unsorted = map.values();
- System.out.println("as values:" + unsorted.size());
- Object[] intsArr = unsorted.toArray();
- //List<Integer> sorted = Collections.sort(unsorted);
- //Iterator it = unsorted.iterator();
- for(int x = 0; x < intsArr.length; x++){
- System.out.print(((Integer)intsArr[x]).intValue());
- if(x < intsArr.length-2) System.out.print(", ");
- else if( x == intsArr.length-1 )System.out.println(" or ");
- }
- }
- public int processSelection(){
- while ( true ) {
- printOptions();
- Scanner scanner = new Scanner(System.in);
- String selection = scanner.next();
- if (selection.equals("1") || selection.equals("2")) {
- System.out.println("returning " + selection);
- return new Integer(selection).intValue();
- } else {
- System.out.println("We do not recognize this selection please try again");
- }
- }
- }
- public void printOptions(){
- System.out.println("Please choose your selection:");
- System.out.println("Type 1 to book a room");
- System.out.println("Type 2 to exit");
- }
- public void readInGuests() {
- try {
- FileReader fr = new FileReader("./guests.txt");
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ( ( line = br.readLine()) != null) {
- List<String> fields = Arrays.asList(line.split(","));
- Guest g = new Guest();
- g.setFirstName(fields.get(0));
- g.setLastName(fields.get(1));
- g.setUsername(fields.get(2));
- g.setPassword(fields.get(3));
- g.setPrefix(fields.get(4));
- g.setBalance(new Double(fields.get(5)).doubleValue());
- guestList.add(g);
- }
- } catch(Exception e){
- System.out.println("Exception:" + e.toString());
- }
- }
- public void readInRooms() {
- try {
- FileReader fr = new FileReader("./rooms.txt");
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ( ( line = br.readLine()) != null) {
- List<String> fields = Arrays.asList(line.split(","));
- Room r = new Room();
- r.setMaxAllowed(new Integer(fields.get(0)).intValue());
- r.setNumberOfRooms(new Integer(fields.get(1)).intValue());
- r.setViewType(fields.get(2));
- r.setPrice(new Double(fields.get(3)).doubleValue());
- roomList.add(r);
- }
- } catch(Exception e){
- System.out.println("Exception:" + e.toString());
- }
- }
- public Guest verifyLogin(String username, String password) {
- for(int x = 0; x < guestList.size(); x++){
- Guest guest = guestList.get(x);
- if (username.equals(guest.getUsername()) && password.equals(guest.getPassword())) {
- return guest;
- }
- }
- System.out.println("Username/Password incorrect please try again");
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement