RentalApplication program, modify the program to: Use an arrayof four LessonWithRentalAppt objects. Prompt the user for allvalues for each object. Allow the user to continuously sort theLessonWithRentalAppt descriptions by contract number, equipmenttype, or price.Save the file as LessonWithRentalApplication.javaand run it. Make sure that it runs . Make sure to provide ascreenshot of the correct output and must have comments
public class LessonWithRental extends RentalAppt//inherits {
boolean lesson[];
String instructNames[];
String equipmentType;
RentalAppt rent;
LessonWithRental(String contNum, int rentMinut, String equipType){
super(contNum, rentMinut);
equipmentType = equipType;
instructNames = new String[] { “Roger”, “Liza”, “John”, “Maria”,”Simon”, “Karmen”, “Bob”, “Pierre” };
lesson = new boolean[8]; rent = new RentalAppt(); for (int i = 0; i< lesson.length; i++) { if (i < 2) lesson[i] = true; elselesson[i] = false;
}//end of for loop
}//end of the constructor
String getInstructor(int index) {
String str = “”; rent.setEquipType(index); str +=”Equipment type: ” + rent.getEquipTypeString() + “n”; str +=”Required Lessons: ” + lesson[index] + “n”;
str += “Instructor: ” + instructNames[index] + “n”; return str; }}
import java.util.Scanner;
public class RentalApplication {
public static void main(String[] args)
{
//Declare variables and constants
int option;
String contractNum;
int minutes;
final int QUIT = 9;
//Declare and create an array that can hold 8 values
RentalAppt[] rentals = new RentalAppt[8];
int x;
//create a counter < of the length
for(x = 0; x < rentals.length; ++x)
{
contractNum = getContractNumber();
minutes = getMinutes();
//Arrays using the method
rentals[x] = new RentalAppt(contractNum, minutes);
rentals[x].setContactPhone(getPhone());
rentals[x].setEquipType(getType());
}
//Displaying the rentals
System.out.println(“nnNow display the rentals”);
option = getOption(QUIT);
while(option != QUIT)
{
//check if the options entered between 1 to 3
if(option == 1)
sortByContractNumber(rentals);
else
if(option == 2)
sortByPrice(rentals);
else
if(option == 3)
sortByType(rentals);
//otherwise prompt the user to enter the right #
else
System.out.print(“Invalid entry – please reenter.”);
//quit to quit
option = getOption(QUIT);
}//end of while loop
}//end of main function
public static int getOption(final int QUIT)
{
//Create scanner
Scanner input = new Scanner(System.in);
//Declare variable option
int option;
//prompt the user to enter an option or to quit
System.out.println(“nPlease enter an option”);
System.out.print(” 1 – by contract numbern 2 – by pricen” +
” 3 – by equipment typen ” + QUIT + ” – to quit >> “);
option = input.nextInt();
input.nextLine();
return option;
}//end of mrthod
//Add a method that display the contract number
public static void sortByContractNumber(RentalAppt[] array)
{
//Declare variables
int a,b;
RentalAppt temp;
String stringB, stringBPlus;
int highSubscript = array.length – 1;
//for loop for a and set a counter
for(a = 0; a < highSubscript; ++a)
//for loop for b and set a counter it
for(b = 0; b < highSubscript; ++b)
{
//set up the stringB and stringBP;us
stringB = array[b].getContractNumber();
stringBPlus = array[b + 1].getContractNumber();
//checking and compare
if(stringB.compareTo(stringBPlus) > 0)
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}//end of if
}//end of for
for(a = 0; a < array.length; ++a)
{
//display array a
displayDetails(array[a]);
}//end of for loop
}//end of method
//Add a method that display the price
public static void sortByPrice(RentalAppt[] array)
{
//Declare variables
int a,b;
RentalAppt temp;
int highSubscript = array.length – 1;
//for loop for a and set a counter
for(a = 0; a < highSubscript; ++a)
//for loop for b and set a counter it
for(b = 0; b < highSubscript; ++b)
{
if(array[b].getPrice() > array[b + 1].getPrice())
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}//end of if
}//end of for
//for loop and a counter
for(a = 0; a < array.length; ++a)
{
//display
displayDetails(array[a]);
}
}
//Add a method that display the type
public static void sortByType(RentalAppt[] array)
{
//Declare variables
int a,b;
RentalAppt temp;
int highSubscript = array.length – 1;
//for loop and a counter for a
for(a = 0; a < highSubscript; ++a)
//for loop and a counter for b
for(b = 0; b < highSubscript; ++b)
{
//check and compare
if(array[b].getEquipType() > array[b + 1].getEquipType())
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}//end of if
}//end of for
//for loop to check the length and a counter
for(a = 0; a < array.length; ++a)
{
displayDetails(array[a]);
}
}
//Add a string method that display the contract number
public static String getContractNumber()
{
String num;
//create a scanner
Scanner input = new Scanner(System.in);
//prompt the user to enter the contract number
System.out.print(“nEnter contract number >> “);
num = input.nextLine();
//return of the string method
return num;
}
//method to get minutes
public static int getMinutes()
{
//declare variables and constants
int minutes;
final int LOW_MIN = 60;
final int HIGH_MIN = 7200;
//create the scanner
Scanner input = new Scanner(System.in);
//prompt the user to enter the minutes
System.out.print(“Enter minutes >> “);
minutes = input.nextInt();
//while loop to compare
while(minutes < LOW_MIN || minutes > HIGH_MIN)
{
//display result
System.out.println(“Time must be between ” + LOW_MIN +
” minutes and ” + HIGH_MIN + ” minutes”);
//prompt user if wrong input
System.out.print(“Please reenter minutes >> “);
minutes = input.nextInt();
}
return minutes;
}
//method for to get type
public static int getType()
{
//declare variables
int eType;
//create scanner
Scanner input = new Scanner(System.in);
System.out.println(“Equipment types:”);
//for loop and a counter
for(int x = 0; x < RentalAppt.EQUIP_TYPES.length; ++x)
//display
System.out.println(” ” + x + ” ” +RentalAppt.EQUIP_TYPES[x]);
//prompt the user to enter equipment type
System.out.print(“Enter equipment type >> “);
eType = input.nextInt();
return eType;
}
//Void method to display the details
public static void displayDetails(RentalAppt r)
{
System.out.println(“nContract #” + r.getContractNumber());
System.out.println(“For a rental of ” + r.getHours() +
” hours and ” + r.getExtraMinutes() +
” minutes,n at a rate of $” + r.getHourRate() +
” per hour and $1 per minute,n the price is $” +r.getPrice());
System.out.println(“Contact phone number is: ” +r.getContactPhone());
System.out.println(“Equipment rented is type #” + r.getEquipType()+
” ” + r.getEquipTypeString()); } public static void displayMotto(){
System.out.println(“SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS”);
System.out.println(“S S”);
System.out.println(“S Sammy’s makes it fun in the sun. S”);
System.out.println(“S S”);
System.out.println(“SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS”) } {RentalAppt longer = new RentalAppt(); int minutes1;int minutes2;minutes1 = r1.getHours() * RentalAppt.MINUTES_IN_HOUR +r1.getExtraMinutes();
minutes2 = r2.getHours() * RentalAppt.MINUTES_IN_HOUR +r2.getExtraMinutes();
if(minutes1 >= minutes2) longer = r1; else longer =r2; return longer; } public static String getPhone(){
String phone; Scanner input = new Scanner(System.in);System.out.print(“Enter contact phone number >> “);
phone = input.nextLine(); return phone; } //end of method }
class RentalAppt {
public static final int MINUTES_IN_HOUR = 60;
private static final int HOUR_RATE = 40;
public static final int CONTRACT_NUM_LENGTH = 4;
public static final String[] EQUIP_TYPES =
{“personal watercraft”, “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;
//method with two parameters representing numbers and minutes
public RentalAppt(String num, int minutes)
{
//set method
setContractNumber(num);
setHoursAndMinutes(minutes);
}
public RentalAppt()
{
this(“A000”, 0);
}
//void method to display contract #
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 <= getHourRate())
price = hours * getHourRate() + extraMinutes;
else
price = hours * getHourRate() + getHourRate();
}
//get method
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];
}
public String getContactPhoneNumber() {
return null;
}
public static int getHourRate() {
return HOUR_RATE;
}
}
Expert Answer
Answer to RentalApplication program, modify the program to: Use an array of four LessonWithRentalAppt objects. Prompt the user for…