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

Modify the Rental class to include n integer field that holds an equipment type.

ID: 3678894 • Letter: M

Question

Modify the Rental class to include n integer field that holds an equipment type. Add a final String array that holds names of the types of equipment that Sammy’s rents-jet ski, pontoon boat, rowboat, canoe, kayak, beach chair, umbrella, and other. Include get and set methods for the integer equipment type field. If the argument passed to the method that sets the equipment type is larger than the size of the array of String equipment types, then set the integer to the element number occupied by “other”. Include a get method that returns a rental’s String equipment type based on the numeric equipment type.

To keep the RentalDemo class simple, remove all of the statements that compare rental times and then display the coupon Strings.

Modify the RentalDemo class so that instead of creating three simple Rental objects,   it uses an array of three Rental objects. Get data for each of the objects, and then display all details for each object.

Here are the classes

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package rental;

/**

*

* @author akosuri22498

*/

public final class Rental

{

    /**

     * @param args the command line arguments

     */

    final int MINUTES_PER_HOUR = 60;

    final int HOURLY_RATE = 40;

  

    private String contractNumber;

    private int hours;

    private int minutes;

    private int totalCost;

    private String phoneNumber;

       public Rental()

    {

    }

    public Rental(String idInput, int minInput)

    {

        this.setContractNumber(idInput);

        this.setHoursAndMinutes(minInput);

    }

  

  

    public void setHoursAndMinutes(int minInput)

    {

        this.hours = minInput / 60;

        this.minutes = minInput - (60 * this.hours);

        this.totalCost = (40 * this.hours) + this.minutes;

        //System.out.println("For the rental of " + this.hours + " hours " +

               // this.minutes + " minutes, the price is $" + this.totalCost + ".");

    }

  

    public void setContractNumber(String idInput){

         String firstletter = idInput.substring(0, 1).toUpperCase();

         String newID = firstletter.concat(idInput.substring(1));

         this.contractNumber = idInput;

    }

  

    public void setPhoneNumber(String phoneInput)

    {

        int inputLength = phoneInput.length();

        String cleanInput = "";

        for (int val = 0; val < inputLength; ++val)

        {

            char inChar = phoneInput.charAt(val);

            //System.out.println(inChar);

          

          if (Character.isDigit(inChar))

          {

              cleanInput = cleanInput.concat(Character.toString(inChar));

              //System.out.println(Character.toString(inChar));

              //System.out.println(cleanInput);

          }

    

        }

        this.phoneNumber = cleanInput;

    }

    public String getcontractNumber()

    {

        return contractNumber;

    }      

    public int getHours()

    {

        return hours;

    }

    public int getMinutes()

    {

        return minutes;

    }

    public int getTotalCost()

    {

        return totalCost;

    }      

     public String getPhoneNumber()

    {

        return phoneNumber;

    }  

}

And

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package rental;

import java.util.Scanner;

/**

*

* @author akosuri22498

*/

public class RentalDemo

{

     public static void main(String[] args)

    {

        int userMinInput = 200;

        String userIdInput = "a364";

      

        Scanner inputDevice = new Scanner(System.in);

        //userMinInput = getUserMinInput(inputDevice);

        while(userMinInput <60 || userMinInput > 7200 )

        {

           userMinInput = getUserMinInput(inputDevice);

        }

        //userIdInput = getUserIdInput(inputDevice);

        Rental contract = new Rental();

      

        contract.setContractNumber(userIdInput);

        contract.setHoursAndMinutes(userMinInput);

        contract.setPhoneNumber("(240)-583-9274");

      

        System.out.println("Contract Number: " + contract.getcontractNumber());

        System.out.println("Hours: " + contract.getHours());

        System.out.println("Minutes: " + contract.getMinutes());

        System.out.println("totalCost: " + contract.getTotalCost());

        Rental contract2 = new Rental("A001", 125);

        contract2.setPhoneNumber("2405839274");

        System.out.println("Phone Number: " + contract.getPhoneNumber());

        System.out.println(" ");

        System.out.println("Contract Number: " + contract2.getcontractNumber());

        System.out.println("Hours: " + contract2.getHours());

        System.out.println("Minutes: " + contract2.getMinutes());

        System.out.println("totalCost: " + contract2.getTotalCost());

        System.out.println("Phone Number: " + contract2.getPhoneNumber());

        System.out.println("For the rental of " + contract2.getHours() + " hours " +

        contract2.getMinutes() + " minutes, the price is $" + contract2.getTotalCost() + ".");

        for(int i = 1; i<= contract2.getHours() ; i++)

        {

           System.out.println("Coupon good for 10 percent off next rental" );

        }

    }

    public static int getUserMinInput(Scanner inputDevice)

    {

        int userInput;

       

        System.out.print("How many minutes: (Must be between 60 and 7200) ");

        userInput = inputDevice.nextInt();

        return userInput;

    }

    public static String getUserIdInput(Scanner inputDevice){

        String userInput;

        System.out.print ("What is the contract number? ");

        userInput = inputDevice.next();

        return userInput;

    }

  

} // end class RentalDemo

Explanation / Answer

Rental.java

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package rental;

/**

*

* @author akosuri22498

*/

public final class Rental

{

/**

   * @param args the command line arguments

   */

final int MINUTES_PER_HOUR = 60;

final int HOURLY_RATE = 40;

final String equipments[]={"jet ski","pontoon boat","rowboat","canoe","kayak","beach chair","umbrella","other"};

  

private String contractNumber;

private int hours;

private int minutes;

private int totalCost;

private String phoneNumber;

private int equipmentType;

public Rental()

{

}

public Rental(String idInput, int minInput)

{

this.setContractNumber(idInput);

this.setHoursAndMinutes(minInput);

}

  

  

public void setHoursAndMinutes(int minInput)

{

this.hours = minInput / 60;

this.minutes = minInput - (60 * this.hours);

this.totalCost = (40 * this.hours) + this.minutes;

//System.out.println("For the rental of " + this.hours + " hours " +

   // this.minutes + " minutes, the price is $" + this.totalCost + ".");

}

  

public void setContractNumber(String idInput){

   String firstletter = idInput.substring(0, 1).toUpperCase();

   String newID = firstletter.concat(idInput.substring(1));

   this.contractNumber = idInput;

}

  

public void setPhoneNumber(String phoneInput)

{

int inputLength = phoneInput.length();

String cleanInput = "";

for (int val = 0; val < inputLength; ++val)

{

char inChar = phoneInput.charAt(val);

//System.out.println(inChar);

  

if (Character.isDigit(inChar))

{

cleanInput = cleanInput.concat(Character.toString(inChar));

//System.out.println(Character.toString(inChar));

//System.out.println(cleanInput);

}

  

}

this.phoneNumber = cleanInput;

}

public void setEquipmentType(int type)

{

if(type>=equipments.length)

{

equipmentType=equipments.length-1;

}

else

{

equipmentType=type;

}

}

public String getcontractNumber()

{

return contractNumber;

}

public int getHours()

{

return hours;

}

public int getMinutes()

{

return minutes;

}

public int getTotalCost()

{

return totalCost;

}

   public String getPhoneNumber()

{

return phoneNumber;

}

public String getEquipmentType()

{

return equipments[equipmentType];

}

}

RentalDemo.java

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package rental;

import java.util.Scanner;

/**

*

* @author akosuri22498

*/

public class RentalDemo

{

   public static void main(String[] args)

{

Rental rentals[]=new Rental[3];

Rental contract1 = new Rental();

  

contract1.setContractNumber("a364");

contract1.setHoursAndMinutes(200);

contract1.setPhoneNumber("(240)-583-9274");

contract1.setEquipmentType(9);

Rental contract2 = new Rental();

  

contract2.setContractNumber("a365");

contract2.setHoursAndMinutes(300);

contract2.setPhoneNumber("(240)-583-9275");

contract2.setEquipmentType(2);

Rental contract3 = new Rental();

  

contract3.setContractNumber("A001");

contract3.setHoursAndMinutes(125);

contract3.setPhoneNumber("2405839274");

contract3.setEquipmentType(3);

rentals[0]=contract1;

rentals[1]=contract2;

rentals[2]=contract3;

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

{

System.out.println("Contract Number: " + rentals[i].getcontractNumber());

System.out.println("Hours: " + rentals[i].getHours());

System.out.println("Minutes: " + rentals[i].getMinutes());

System.out.println("totalCost: " + rentals[i].getTotalCost());

System.out.println("equipment type: " + rentals[i].getEquipmentType());

System.out.println();

}

}

  

} // end class RentalDemo

output:

Contract Number: a364

Hours: 3

Minutes: 20

totalCost: 140

equipment type: other

Contract Number: a365

Hours: 5

Minutes: 0

totalCost: 200

equipment type: rowboat

Contract Number: A001

Hours: 2

Minutes: 5

totalCost: 85

equipment type: canoe

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