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

Every summer, Leeland Lakeside resort rents cabins by the week. Create a class n

ID: 3691333 • Letter: E

Question

Every summer, Leeland Lakeside resort rents cabins by the week. Create a class named CabinRental that includes an integer field for the cabin number and a double field for the weekly rental rate. Include get methods for these fields and a constructor that requires an integer argument representing the cabin number. The constructor sets the weekly rate based on the cabin number; cabins numbered 1, 2, and 3 are $950 per week, and others are $1,100 per week. Create an extended class named HolidayCabinRental that is used for rentals during weeks that include summer holiday weekends. The constructor for this class requires a room number and adds a $150 surcharge to the regular rental rate. Write an application named DemoCabinRental that creates an object of each class, and demonstrate that all the methods work correctly.

Explanation / Answer

class CabinRental
   {
       int cabin_num;
       double weekly_rental;
      
       CabinRental(int cabin_num)
           {
               this.cabin_num = cabin_num;           //Assigning passed parameter value to class variable
               if(cabin_num == 1 || cabin_num == 2 || cabin_num == 3)   //assigning of rentals based on condition of room numbers
                   {
                       weekly_rental = 950;
                   }
               else
                   {
                       weekly_rental = 1150;
                   }
           }
      
       // get methodss to get cabinNumber and weekly rental
       public int getCabinNum()
           {
               return cabin_num;
           }
          
       public double getWeeklyRental()
           {
               return weekly_rental;
           }
   }
  
   // sub class extending CabinRental class
class HolidayCabinRental extends CabinRental
   {
       HolidayCabinRental(int room_no)
           {
               super(room_no);       // assigning passed value to the super class variable
               weekly_rental += 150;
           }
   }

public class DemoCabinRental
   {
       public static void main(String args[])
           {
               // Driver code
               CabinRental cab1 = new CabinRental(3);
               CabinRental cab2 = new CabinRental(6);
               HolidayCabinRental hcab1 = new HolidayCabinRental(2);
               HolidayCabinRental hcab2 = new HolidayCabinRental(5);              
              
               System.out.println("RENTAL DETAILS: CABIN NUMBER:" + cab1.getCabinNum() + " TOTAL RENTAL: $" + cab1.getWeeklyRental());
               System.out.println("RENTAL DETAILS: CABIN NUMBER:" + cab2.getCabinNum() + " TOTAL RENTAL: $" + cab2.getWeeklyRental());
               System.out.println("RENTAL DETAILS: CABIN NUMBER:" + hcab1.getCabinNum() + " TOTAL RENTAL: $" + hcab1.getWeeklyRental());
               System.out.println("RENTAL DETAILS: CABIN NUMBER:" + hcab2.getCabinNum() + " TOTAL RENTAL: $" + hcab2.getWeeklyRental());
           }
   }

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