Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Chapter 8, you created a Rental class for Sammys Seashore Supplies. Now extend the class to create a LessonWithRental class. In the extended class,

In Chapter 8, you created a Rental class for Sammys Seashore Supplies. Now extend the class to create a LessonWithRental class. In the extended class, include a new 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, and store names that you choose in the array. Create a LessonWithRental constructor that requires arguments for an event number, minutes for the rental, and an integer equipment type. Pass the first two parameters to the Rental constructor, and assign the last parameter to the equipment type. For the first two equipment types (jet ski and pontoon boat), set the Boolean lesson required field to true; otherwise, set it to false. Also include a getInstructor() method that builds and returns a String including the String for the equipment type, a message that indicates whether a lesson is required, and the instructors name. Save the file as LessonWithRental.java.

In Chapter 9, you created a RentalDemo program forSammysSeashoreSupplies. The program uses an array of Rental objects and allows the user to sort Rentals in ascending order by contract number, equipment type, or price. Now modify the program to use an array of four LessonWithRental objects. Prompt the user for all values for each object, and then allow the user to continuously sort the LessonWithRental descriptions by contract number, equipment type, or price. Save the file as LessonWithRentalDemo.java.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions

Question

Find dy/dx if x = te, y = 2t2 +1

Answered: 1 week ago