Question: ***UPDATE: I previously posted wrong Rental.java and RentalDemo.java code, check below for correct code *** In the last chapter, you modified the RentalDemo program for

***UPDATE: I previously posted wrong Rental.java and RentalDemo.java code, check below for correct code ***

In the last chapter, you modified the RentalDemo program for Sammy's Seashore Supplies to accept and display data for an array of three Rental objects. Now, modify the program to use an array of eight Rental objects. Prompt the user to choose an option to sort Rentals in ascending order by contract number, price, or equipment type. Display the sorted list, and continue to prompt the user for sorting options until the user enters a sentinel value. Save the file as RentalDemo.java.

Java Programming 8th Edition

Chapter 9 Case Problem 2

Not sure if you need it, but I've included my Rental.java file

*** Rental.java ***

import java.util.Scanner; class Rental

{

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 ***

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("(240)-583-9274");

contract3.setEquipmentType(3);

rentals[0]=contract1;

rentals[1]=contract2;

rentals[2]=contract3;

for(int i=0;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();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!