Question

In: Computer Science

Java homework problem. This is my hotel reservation system. I'm trying to add a few things...

Java homework problem. This is my hotel reservation system. I'm trying to add a few things to it.

You will be changing your Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects.

  1. For this project you will be modifying the Hotel Reservation system to allow a user to serve more rooms and the rooms will be created as objects.

    1. You will be create a Room object that will allow the user to set the type of room, if they want pets, and if they want Oceanview.

      1. OV is $50 more

      2. Pets $25 more

      3. King, Suite and Queen style rooms and you can set the prices

    2. You will have an array for username and password that hold 3 userNames and 3 passwords. These will be parallel arrays. I am allowed to enter username and password 3 times and then I get kicked out.

    3. Main

      1. The main method will keep track of information for 5 room reservations objects all for 1 night

        1. Be sure to use looping, somewhere in the main java file.

        2. Create a method that will catch the object and create it. Remember you can pass by reference or return the object back to the main.

        3. Create a method to handle printing out each of the objects to the screen and the total for each room. (You can set this total in the Room Class if you wish.)

        4. Finally Create a method that will show out the grand total.

Here is my original code to be modified:

import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class hotelreservation {
  
  
      public static double roomSelection(Scanner scan)
   {

       String roomSelection;
       System.out.print("Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): ");
       roomSelection = scan.nextLine();
    
       if(roomSelection.equalsIgnoreCase("Suite"))
           return 275;
       else if(roomSelection.equalsIgnoreCase("Queen"))
           return 150;
       else if(roomSelection.equalsIgnoreCase("King"))
           return 150;
       else
           return 125;
   }

   public static double roomOceanView(Scanner scan)
   {
       String response;
       System.out.print("Would you like an oceanview room (Yes/No) ? ");
       response = scan.nextLine();
    
       if(response.equalsIgnoreCase("Yes"))
           return 45;
       else
           return 0;
   }

   public static double roomPets(Scanner scan)
   {
       String response;
       System.out.print("Do you have any pets (Yes/No) ? ");
       response = scan.nextLine();
    
       if(response.equalsIgnoreCase("Yes"))
           return 50;
       else
           return 0;
   }

   public static void main(String[] args) {
     
       DecimalFormat decFormat = new DecimalFormat("0.00");
       Scanner scan = new Scanner(System.in);
       double roomReservation[] = new double[3];
       double subTotal = 0;
    
       for(int x=0;x        {
           System.out.println("Welcome to our Hotel Room Reservation Pricing System.");
           System.out.println("Please answer the following questions regarding your reservation of room #"+(x+1)+" : ");
           roomReservation[x] = roomPets(scan);
           roomReservation[x] += roomSelection(scan);
           roomReservation[x] += roomOceanView(scan);
       }
     
       for(int x=0;x        {
           System.out.println("Total cost for room #"+(x+1)+" : $"+decFormat.format(roomReservation[x]));
           subTotal += roomReservation[x];
       }
    
       System.out.println("Subtotal: $"+decFormat.format(subTotal));
       double tax = subTotal*0.05;
       System.out.println("Total Tax (5%): $"+decFormat.format(tax));
       System.out.println("Grand Total: $"+(decFormat.format(subTotal+tax)));
       scan.close();
   }

}

Solutions

Expert Solution

/*
* The java program that prompts user to enter user name and password that
* are stored in parallel arrays. If user name and password matched then
* print login successful . Allow user to enter 3 attempt otherwise terminate the program.
* Then prompts user to enter the room type, yes /no
* for the ocean view and yes/ no for the pets for the Room class objects.
* Then find the the sub total, tax and net price of the total room objects.
* */
//Hotelreservation.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class Hotelreservation
{
   public static void main(String[] args)
   {
       DecimalFormat decFormat = new DecimalFormat("0.00");
       Scanner scan = new Scanner(System.in);
       double subTotal = 0;

       /*Create an array of Room class of size,5*/
       Room[] rooms=new Room[5];

       String roomType;
       String oceanViewChoice;
       String petChoice;

       boolean oceanChoice=false;
       boolean havePets=false;

       final int MAX=3;
       boolean login_status=false;

       String userNames[]= {"john","kumar","samantha"};
       String passwords[]= {"1234","abcd","xyz"};

       int count=0;      
       while(count<MAX && !login_status)
       {
           System.out.println("Enter user name : ");
           String userName=scan.nextLine();
           int userNameLocation=-1;
           for (int i = 0; i <MAX; i++)
           {      
               if(userNames[i].equalsIgnoreCase(userName))
                   userNameLocation=i;  
           }
           if(userNameLocation!=-1)
           {
               System.out.println("Enter password: ");
               String password=scan.nextLine();

               if(password.equalsIgnoreCase(passwords[userNameLocation]))
                   login_status=true;      
           }
           else
               System.out.println("Invalid user name");
          
           count++;
       }

       if(login_status==false && count==MAX)
       {
           System.out.println("Login failed");
           System.exit(0);
       }
       else
           System.out.println("Login successful");

           System.out.println("Welcome to our Hotel Room Reservation Pricing System.");
       //read 5 room choice values
       for(int x=0;x<rooms.length;x++)
       {
           System.out.print("Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): ");
           roomType = scan.nextLine();

           System.out.print("Do you want ocean view(yes /no): ?");
           oceanViewChoice = scan.nextLine();
           //checking if ocean choice is yes then set ocaenChoice is true
           if(oceanViewChoice.equalsIgnoreCase("yes"))
               oceanChoice=true;

           System.out.print("Do you have pet(yes /no): ?");
           petChoice = scan.nextLine();
           //checking if petChoice is yes then set petChoice is true
           if(petChoice.equalsIgnoreCase("yes"))
               havePets=true;
           //create an object of room class with user given values
           rooms[x]=new Room(roomType, oceanChoice, havePets);  
       }

       //find the sub total of rooms
       for(int x=0;x<rooms.length;x++)
       {
           subTotal+=rooms[x].getRoomCost()+rooms[x].getOceanViewCost()+
                   rooms[x].getPetCharge();
       }

       //print the results to console window
       System.out.println("Subtotal: $"+decFormat.format(subTotal));
       double tax = subTotal*0.05;
       System.out.println("Total Tax (5%): $"+decFormat.format(tax));
       System.out.println("Grand Total: $"+(decFormat.format(subTotal+tax)));
       scan.close();
   }
}

-----------------------------------------------------------------------------------------------------------------------

//Room class declaration
//Room.java
public class Room
{
   //private data members
   private double roomCost;
   private double oceanViewCost;
   private double petsCharge;

   /*constructor */
   Room(String roomType , boolean oceanView , boolean havePets)
   {
       setSelection(roomType);
       setOceanView(oceanView);
       setPets(havePets);
   }
   public void setPets(boolean havePets)
   {
       if(havePets)
           petsCharge= 50;
       else
           petsCharge= 0;
   }

   public void setOceanView(boolean oceanView)
   {
       if(oceanView)
           oceanViewCost= 45;
       else
           oceanViewCost= 0;
   }
   public void setSelection(String roomType)
   {
       if(roomType.equalsIgnoreCase("Suite"))
           roomCost= 275;
       else if(roomType.equalsIgnoreCase("Queen"))
           roomCost= 150;
       else if(roomType.equalsIgnoreCase("King"))
           roomCost= 150;
       else
           roomCost= 125;
   }
   public double getRoomCost()
   {
       return roomCost;
   }
   public double getOceanViewCost()
   {
       return oceanViewCost;
   }
   public double getPetCharge()
   {
       return petsCharge;
   }
}

-----------------------------------------------------------------------------------------------------------------------

Sample Output:

Enter user name :
john
Enter password:
sdfsf
Enter user name :
john
Enter password:
sdfsdf
Enter user name :
john
Enter password:
1234
Login successful
Welcome to our Hotel Room Reservation Pricing System.
Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): King
Do you want ocean view(yes /no): ?yes
Do you have pet(yes /no): ?yes
Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): Queen
Do you want ocean view(yes /no): ?yes
Do you have pet(yes /no): ?yes
Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): Suite
Do you want ocean view(yes /no): ?yes
Do you have pet(yes /no): ?yes
Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): King
Do you want ocean view(yes /no): ?yes
Do you have pet(yes /no): ?yes
Please enter the type of room desired for your stay (King/Queen/Suite/Two doubles): King
Do you want ocean view(yes /no): ?yes
Do you have pet(yes /no): ?yes
Subtotal: $1350.00
Total Tax (5%): $67.50
Grand Total: $1417.50


Related Solutions

Java I'm trying to create a program that replicates a theater ticket reservation system. I have...
Java I'm trying to create a program that replicates a theater ticket reservation system. I have a Seat class with members row(integer), seat(character) and ticketType(character). Where a ticket type can be 'A' adult, 'C' child, 'S' senior, or '.' recorded as empty. I have a Node generic class that points to other nodes(members): up, Down. Left, Right. It also has a generic payload. Lastly, I have an Auditorium class which is also generic. its member is a First Node<T>. As...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is...
JAVA JAVA JAVA Hey i need to find a java code for my homework, this is my first java homework so for you i don't think it will be hard for you. (basic stuff) the problem: Write a complete Java program The transport Company in which you are the engineer responsible of operations for the optimization of the autonomous transport of liquid bulk goods, got a design contract for an automated intelligent transport management system that are autonomous trucks which...
using c++ You have been contracted to build a hotel reservation system. This is the system...
using c++ You have been contracted to build a hotel reservation system. This is the system that hotel desk clerks will use to take desk reservations. Assumptions: This is acting as though the only reservations taken are at the desk. All reservations are for one night. The hotel is empty when you start the program. First, this program will give the full inventory of rooms in the hotel. Total rooms: 122 There are four types of rooms with these prices:...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet the following guidelines: User can reserve up to 3 rooms at a time Your program will need to loop through to continue to ask needed questions to determine cost. Room rates (room variants): Suite $250 2 Queens $150 1 King $175 Ocean view add $50 Fridge for Room $25 Pets additional $50 Sales tax rate will be 5.5% Your program will show out the...
Use the code below as the basis for a hotel reservation system (HRS). The customer calls...
Use the code below as the basis for a hotel reservation system (HRS). The customer calls the hotel front desk to book a room. The front desk is running your software on one of its computers. The basic operations available are: book one room, book two adjoining rooms, list all unoccupied rooms, list all occupied rooms, help lists information about available methods, report percent of hotel rooms that are unoccupied, quit the system (shut the system down). The people at...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and the one-to-one or one-to-many relationships between the tables. Also describe in a small paragraph the scope of the back-end database, by explaining the different tables and their relations in your schema.
bus reservation system code using c language in this system we can add seat and remove....
bus reservation system code using c language in this system we can add seat and remove. this code will be in c language using 2 d aray
I'm trying to decide if I want to invest in a refinery to upgrade my bitumen...
I'm trying to decide if I want to invest in a refinery to upgrade my bitumen to oil. Currently it costs me $40, to get my bitumen to market, where I am able to sell it for $50 a barrel. If I decided to upgrade, it will costs me an extra $6 a barrel, these will produce 30 liters of oil, which I can sell for $2 each.   Should I expand my business? Select one: a. Yes - 4 b....
Happy Saturday. I'm working on my accounting homework ch. 11 and would liek to know if...
Happy Saturday. I'm working on my accounting homework ch. 11 and would liek to know if nayone coould possibly help out with this question... Novak Company acquired a plant asset at the beginning of Year 1. The asset has an estimated service life of 5 years. An employee has prepared depreciation schedules for this asset using three different methods to compare the results of using one method with the results of using other methods. You are to assume that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT