Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using java, this Exercise has 3 classes: UseMotelRoom, MotelRoom, and MotelSuite

ID: 3862391 • Letter: U

Question

Using java, this Exercise has 3 classes: UseMotelRoom, MotelRoom, and MotelSuite. The UseMotelRoom class has been created for you.

Finish the Class named MotelRoom that includes an integer field for the room number and a double field for the nightly rental rate. Include get methods for these fields and a constructor that requires an integer argument representing the room number. 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 MotelSuite whose constructor requires a room number and adds a $35 surcharge to the regular hotel room rate, which again is based on the room number.

THE ALREADY CREATED CLASS CODE:

/*
* put header information here
*/

import java.util.*;
public class UseMotelRoom {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the Motel room number:");
int roomNumber = input.nextInt();
  
System.out.println("Please enter the Suite number:");
int suiteNumber = input.nextInt();
  
MotelRoom motelRoom = new MotelRoom(roomNumber);
MotelSuite motelSuite = new MotelSuite(suiteNumber);
  
System.out.printf("The motel room %d has a rate of $%.2f while "
+ "the suite %d has a rate of $%.2f",motelRoom.getRoomNumber(),
motelRoom.getRentalRate(),motelSuite.getRoomNumber(),motelSuite.getRentalRate());

} // end main method

} //end class UseMotelRoom


//*************************************************************
//***** MotelRoom class is below this box **
//*************************************************************
class MotelRoom {

// create the MotelRoom class code

} //end of MotelRoom

//*************************************************************
//**** MotelSuite Class is below this box **
//*************************************************************

class MotelSuite {

// create the MotelSuite class code

} //end of MotelSuite

Explanation / Answer

UseMotelRoom.java

import java.util.*;
public class UseMotelRoom {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the Motel room number:");
int roomNumber = input.nextInt();
  
System.out.println("Please enter the Suite number:");
int suiteNumber = input.nextInt();
  
MotelRoom motelRoom = new MotelRoom(roomNumber);
MotelSuite motelSuite = new MotelSuite(suiteNumber);
  
System.out.printf("The motel room %d has a rate of $%.2f while "
+ "the suite %d has a rate of $%.2f",motelRoom.getRoomNumber(),
motelRoom.getRentalRate(),motelSuite.getRoomNumber(),motelSuite.getRentalRate());
} // end main method
} //end class UseMotelRoom

//*************************************************************
//***** MotelRoom class is below this box **
//*************************************************************
class MotelRoom {
// create the MotelRoom class code
   private int roomNumber;
   private double rentalRate;
   public MotelRoom(int r){
       roomNumber = r;
   }
   public int getRoomNumber() {
       return roomNumber;
   }
   public double getRentalRate() {
       if(roomNumber <=299){
           rentalRate=69.95;
       }
       else{
           rentalRate = 89.95;
       }
       return rentalRate;
   }

  
} //end of MotelRoom

//*************************************************************
//**** MotelSuite Class is below this box **
//*************************************************************
class MotelSuite extends MotelRoom{
// create the MotelSuite class code
   public MotelSuite(int r){
       super(r);
   }
   public double getRentalRate() {
      
       return super.getRentalRate()+35;
   }

} //end of MotelSuite

Output:

Please enter the Motel room number:
289
Please enter the Suite number:
2
The motel room 289 has a rate of $69.95 while the suite 2 has a rate of $104.95

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote