Answer to Question #225264 in Java | JSP | JSF for Tariq Sarfaraz

Question #225264

4. Create a class named HotelRoom that includes an integer field for the room number and a double field for the nightly rental rate. The constructor of this class requires an integer argument representing the room number and the constructor sets the room rate based on the room number; rooms numbered 299 and below are $69.95 per night, and others are $89.95 per night. Create an extended class named Suite whose constructor requires a room number and adds a $40 surcharge to the regular hotel room rate, which again is based on the room number. Write an application named UseHotelRoom that creates an object of each class, accept room number from user, demonstrate that all the methods work correctly and display the details. Save the files as UseHotelRoom.java.


1
Expert's answer
2021-08-12T02:36:40-0400
class HotelRoom { 
    final double MIN_RATE = 69.89;
    final double SPECIAL_RATE = 89.95;
    final int ROOM_CRITERIA = 299;


    private int room;
    private double rentalRate;


    HotelRoom ( int intRoom) {
        room = intRoom;
        if (roomNumber <= ROOM_CRITERIA)
          rentalRate = MIN_RATE;
        else
          rentalRate = SPECIAL_RATE;
    } 
    public int getRoom(){ return room; }
    public double getRentalRate(){ return rentalRate; }
    public void setRoom(int intRoom){ room =  intRoom; }
    public void setRentalRate(double intRentalRate){ rentalRate = intRentalRate; }
} 


class Suite extends HotelRoom { 
    final double SURCHARGE = 40.00;
    Suite (int roomNumber){ 
        super(roomNumber);
        setRentalRate(getRentalRate() + SURCHARGE);
    } 
} 


public class Assignment { 
    public static void main(String[] args){ 
      Suite aSuiteRoom = new Suite(300);
      System.out.println("Suite Room Charge ");
      System.out.println("Room Number : " + aSuiteRoom.getRoom());
      System.out.println("Charge      : " + aSuiteRoom.getRentalRate());


      Suite anotherSuiteRoom = new Suite(100);
      System.out.println("Suite Room Charge ");
      System.out.println("Room Number : " + anotherSuiteRoom.getRoom());
      System.out.println("Charge      : " + anotherSuiteRoom.getRentalRate());


      HotelRoom aRoom = new HotelRoom(300);
      System.out.println("Suite Room Charge ");
      System.out.println("Room Number : " + aRoom.getRoom());
      System.out.println("Charge      : " + aRoom.getRentalRate());


      HotelRoom anotherRoom = new HotelRoom(100);
      System.out.println("Hote Room Charge ");
      System.out.println("Room Number : " + anotherRoom.getRoom());
      System.out.println("Charge      : " + anotherRoom.getRentalRate());
    } 
} 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS