Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HotelRoom
- {
- private int roomNumber;
- protected double nightlyRate;
- private final int maxRoomNumber = 999;
- boolean didEnterCorrectRoomNumber = false;
- public HotelRoom(int room)
- {
- if (room > 0 && room <= 299)
- {
- nightlyRate = 69.95;
- didEnterCorrectRoomNumber = true;
- //return didEnterCorrectRoomNumber;
- }
- else if (room > 299 && room <= maxRoomNumber)
- {
- nightlyRate = 89.95;
- didEnterCorrectRoomNumber = true;
- //return didEnterCorrectRoomNumber;
- }
- else
- {
- //return didEnterCorrectRoomNumber;
- }
- }
- public int getRoomNumber ()
- {
- return roomNumber;
- }
- public double getNightlyRate ()
- {
- return nightlyRate;
- }
- public boolean getDidEnterCorrectRoomNumber ()
- {
- return didEnterCorrectRoomNumber;
- }
- public void displayRoom ()
- {
- System.out.println("Room Number: " + roomNumber);
- System.out.format("Cost per Night: $%.2f%n", nightlyRate);
- }
- }
- public class Suite extends HotelRoom
- {
- private final double suiteSurchargeRate = 40.00;
- private double nightlyRateWithSuite;
- public Suite (int room)
- {
- super(room);
- //boolean didEnterCorrectRoomNumber = super.getDidEnterCorrectRoomNumber();
- nightlyRateWithSuite = super.getNightlyRate() + suiteSurchargeRate;
- //return didEnterCorrectRoomNumber;
- }
- public void displayRoom ()
- {
- super.displayRoom();
- System.out.format("Suite Surcharge: $%.2f%n", suiteSurchargeRate);
- System.out.format("Total Cost per Night: $%.2f%n", nightlyRateWithSuite);
- }
- }
- super(room)
- public class Main {
- public static void main(String[] args) {
- Suite suite = new Suite(10);
- suite.displayRoom();
- }
- }
- Room Number: 0
- Cost per Night: $69.95
- Suite Surcharge: $40.00
- Total Cost per Night: $109.95
Add Comment
Please, Sign In to add comment