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

please help with this java program, and include details: -extend the rental clas

ID: 658912 • Letter: P

Question

please help with this java program, and include details:

-extend the rental class to create a LessonWithRental class.
-In the extended class create a boolean field that indicates whether a lesson is required or optional for the type of equipment rented.
-Also include a final array that contains strings representing the names of the instructors for each of the eight equipment types(store any eight names you choose).
-create a constructor that requires arguments of the contract number, minutes for the rental, and an integer equipment type.
-pass the first two parameters to the parent, and assign the last parameter to the equipment type.
-for the 1st two equipment types(jet Ski and pontoon boat), set the boolean lesson field to true. otherwise set it to false.
-also include a getInstructor() method that builds and returns a string including the string for equipment type, a message indicating whether the lesson is required, and the instrutors name.

//_______________________________________ the rental class is below_____________

public class Rental
{
public static final int MINUTES_IN_HOUR = 60;
public static final int HOUR_RATE = 40;
public static final int CONTRACT_NUM_LENGTH = 4;
public static final String[] EQUIP_TYPES =
{"jet ski", "pontoon boat", "rowboat", "canoe", "kayak",
"beach chair", "umbrella", "other"};
private String contractNumber;
private int hours;
private int extraMinutes;
private double price;
private String contactPhone;
private int equipType;
public Rental(String num, int minutes)
{
setContractNumber(num);
setHoursAndMinutes(minutes);
}
public Rental()
{
this("A000", 0);
}
public void setContractNumber(String num)
{
boolean numOk = true;
if(num.length() != CONTRACT_NUM_LENGTH ||
!Character.isLetter(num.charAt(0)) ||
!Character.isDigit(num.charAt(1)) ||
!Character.isDigit(num.charAt(2)) ||
!Character.isDigit(num.charAt(3)))
contractNumber = "A000";
else
contractNumber = num.toUpperCase();
}
public void setHoursAndMinutes(int minutes)
{
hours = minutes / MINUTES_IN_HOUR;
extraMinutes = minutes % MINUTES_IN_HOUR;
if(extraMinutes <= HOUR_RATE)
price = hours * HOUR_RATE + extraMinutes;
else
price = hours * HOUR_RATE + HOUR_RATE;
}
public String getContractNumber()
{
return contractNumber;
}
public int getHours()
{
return hours;
}
public int getExtraMinutes()
{
return extraMinutes;
}
public double getPrice()
{
return price;
}
public String getContactPhone()
{
String phone;
phone = "(" + contactPhone.substring(0, 3) + ") " +
contactPhone.substring(3, 6) + "-" +
contactPhone.substring(6, 10);
return phone;
}
public void setContactPhone(String phone)
{
final int VALID_LEN = 10;
final String INVALID_PHONE = "0000000000";
contactPhone = "";
int len = phone.length();
for(int x = 0; x < len; ++x)
{
if(Character.isDigit(phone.charAt(x)))
contactPhone += phone.charAt(x);
}
if(contactPhone.length() != VALID_LEN)
contactPhone = INVALID_PHONE;
}
public void setEquipType(int eType)
{
if(eType < EQUIP_TYPES.length)
equipType = eType;
else
equipType = EQUIP_TYPES.length - 1;
}
public int getEquipType()
{
return equipType;
}
public String getEquipTypeString()
{
return EQUIP_TYPES[equipType];
}
}

Explanation / Answer

Program code:

//LessonsWithRental.java

//LessonsWithRental that inherits the properties of the Rental class

public class LessonsWithRental extends Rental

{

     // declare the required variables

     boolean lesson[];

     String instructNames[];

     String equipmentType;

     Rental rent;

     // constructor

     LessonsWithRental(String contNum, int rentMinut, String equipType)

     {

          super(contNum, rentMinut);

          equipmentType = equipType;

          instructNames = new String[] { "Rosy", "Leander", "Jacob", "Maria",

                    "LeeSung", "Boston", "Yunishi", "Henry" };

          lesson = new boolean[8];

          rent = new Rental();

          for (int i = 0; i < lesson.length; i++)

          {

              if (i < 2)

                   lesson[i] = true;

              else

                   lesson[i] = false;

          }

     }

     // getInstructor() method that takes index values and returns a

     // string for required format

     String getInstructor(int index)

     {

          String str = "";

          rent.setEquipType(index);

          str += "Equipment type: " + rent.getEquipTypeString() + " ";

          str += "Required Lessons: " + lesson[index] + " ";

          str += "Instructor: " + instructNames[index] + " ";

          return str;

     }

}

public class Rental

{

     public static final int MINUTES_IN_HOUR = 60;

     public static final int HOUR_RATE = 40;

     public static final int CONTRACT_NUM_LENGTH = 4;

     public static final String[] EQUIP_TYPES = { "jet ski", "pontoon boat",

               "rowboat", "canoe", "kayak", "beach chair", "umbrella", "other" };

     private String contractNumber;

     private int hours;

     private int extraMinutes;

     private double price;

     private String contactPhone;

     private int equipType;

     public Rental(String num, int minutes)

     {

          setContractNumber(num);

          setHoursAndMinutes(minutes);

     }

     public Rental()

     {

          this("A000", 0);

     }

     public void setContractNumber(String num)

     {

          boolean numOk = true;

          if (num.length() != CONTRACT_NUM_LENGTH

                    || !Character.isLetter(num.charAt(0))

                    || !Character.isDigit(num.charAt(1))

                    || !Character.isDigit(num.charAt(2))

                    || !Character.isDigit(num.charAt(3)))

              contractNumber = "A000";

          else

              contractNumber = num.toUpperCase();

     }

     public void setHoursAndMinutes(int minutes)

     {

          hours = minutes / MINUTES_IN_HOUR;

          extraMinutes = minutes % MINUTES_IN_HOUR;

          if (extraMinutes <= HOUR_RATE)

              price = hours * HOUR_RATE + extraMinutes;

          else

              price = hours * HOUR_RATE + HOUR_RATE;

     }

     public String getContractNumber()

     {

          return contractNumber;

     }

     public int getHours()

     {

          return hours;

     }

     public int getExtraMinutes()

     {

          return extraMinutes;

     }

     public double getPrice()

     {

          return price;

     }

     public String getContactPhone()

     {

          String phone;

          phone = "(" + contactPhone.substring(0, 3) + ") "

                    + contactPhone.substring(3, 6) + "-"

                    + contactPhone.substring(6, 10);

          return phone;

     }

     public void setContactPhone(String phone)

     {

          final int VALID_LEN = 10;

          final String INVALID_PHONE = "0000000000";

          contactPhone = "";

          int len = phone.length();

          for (int x = 0; x < len; ++x)

          {

              if (Character.isDigit(phone.charAt(x)))

                   contactPhone += phone.charAt(x);

          }

          if (contactPhone.length() != VALID_LEN)

              contactPhone = INVALID_PHONE;

     }

     public void setEquipType(int eType)

     {

          if (eType < EQUIP_TYPES.length)

              equipType = eType;

          else

              equipType = EQUIP_TYPES.length - 1;

     }

     public int getEquipType()

     {

          return equipType;

     }

     public String getEquipTypeString()

     {

          return EQUIP_TYPES[equipType];

     }

}

Note: The required code is designed as per the given details and it is highlighted in bold letters.