Save the above file as Rental.java. (5 Marks)
b. Create a RentalDemo class to instantiate two Rental objects.
Save the above file as RentalDemo.java. (5 Marks)
PROGRAM:
Rental.java :
package HomeworkLib.answers;
public class Rental {
// Two public final static fields
public final static int num_min = 60;
public final static int hourly_rent_rate = 40;
// Four private fields
private String contract_number;
private int num_of_hours_for_rental, num_of_minutes_over_an_hour, price;
// default constructor
Rental(){
this("A000", 0);
}
// parameterized constructor
Rental(String contract, int minutes){
setContractNumber(contract);
setHoursAndMinutes(minutes);
}
// setter method for Contract Number
public void setContractNumber(String contract){
contract_number = contract;
}
// setter method for Hours and Minutes
public void setHoursAndMinutes(int minutes){
num_of_hours_for_rental = minutes / 60;
num_of_minutes_over_an_hour = minutes - (num_of_hours_for_rental * 60);
price = (num_of_hours_for_rental * hourly_rent_rate) + num_of_minutes_over_an_hour;
}
// getter method to get Contract Number
public String getContractNumber(){
return contract_number;
}
// getter method to get Number of Hours for Rental
public int getHoursRental(){
return num_of_hours_for_rental;
}
// getter method to get Number of Minutes for Rental
public int getMinutesRental(){
return num_of_minutes_over_an_hour;
}
// getter method to get the price
public int getPrice() {
return price;
}
}
RentalDemo.java :
package HomeworkLib.answers;
// importing Scanner
import java.util.Scanner;
public class RentalDemo {
// creating scanner object
Scanner sc = new Scanner(System.in);
public static void main(String args[]){
// creating RentalDemo Class object
RentalDemo rd = new RentalDemo();
// creating 1st object for Rental Class
Rental obj1 = new Rental();
// calling methods using 1st object and storing the returned values
String obj1_contract = obj1.getContractNumber();
int obj1_hours = obj1.getHoursRental();
int obj1_minutes = obj1.getMinutesRental();
int obj1_price = obj1.getPrice();
// calling this class display method
rd.displayDetails(obj1_contract, obj1_hours, obj1_minutes, obj1_price);
// getting contract and minutes
String contract = rd.setContract();
int minutes = rd.setMinutes();
// creating 2nd object for Rental Class
Rental obj2 = new Rental(contract,minutes);
// calling methods using 2nd object and storing the returned values
String obj2_contract = obj2.getContractNumber();
int obj2_hours = obj2.getHoursRental();
int obj2_minutes = obj2.getMinutesRental();
int obj2_price = obj2.getPrice();
// calling this class display method
rd.displayDetails(obj2_contract, obj2_hours, obj2_minutes, obj2_price);
}
// method to get contract number from user
public String setContract(){
System.out.println("Enter contract number: ");
return sc.nextLine();
}
// method to get number of minutes from user
public int setMinutes(){
System.out.println("Enter the minutes: ");
return sc.nextInt();
}
// method to display values
public void displayDetails(String contract, int hours, int minutes, int price){
System.out.println("Contract Number: " + contract);
System.out.println("Number of hours: " + hours);
System.out.println("Number of minutes: " + minutes);
System.out.println("Total price: " + price);
System.out.println();
}
}
OUTPUT:
Contract Number: A000
Number of hours: 0
Number of minutes: 0
Total price: 0
Enter contract number:
K681
Enter the minutes:
157
Contract Number: K681
Number of hours: 2
Number of minutes: 37
Total price: 117
SCREENSHOTS:
Rental.java :


RentalDemo.java :


Output :

Remove the line "package HomeworkLib.answers;" before executing it yourself.
Hope this helps!
Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists....
In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now modify the Rental and RentalDemo classes as follows: Modify the Rental class to include an integer field that holds an equipment type. Add a final String array that holds names of the types of equipment that Sammy's rents—personal watercraft, 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...
a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...
Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...
C++ Program 1. Create a class named BaseballGame that has fields for two team names and a final score for each team. Include methods to set and get the values for each data field. Your application declares an array of 12 BaseballGame objects. Prompt the user for data for each object, and display all the values. Then pass each object to a method that displays the name of the winning team or “Tie” if the score is a tie. (main.cpp,...
a. Create a FitnessTracker class that includes data fields for a fitness activity, the number of minutes spent participating, and the date. The class includes methods to get each field. In addition, create a default constructor that automatically sets the activity to "running", the minutes to 0, and the date to January 1 of the current year. Create an application that demonstrates each method works correctly. b. Create an additional overloaded constructor for the FitnessTracker class you created in Exercise...
PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...
Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...
Create a class to hold data about a high school sports team. The Team class holds data fields for high school name (such as Roosevelt High), sport (such as Girls’ Basketball), and team name (such as Dolphins). Include a constructor that takes parameters for each field, and include get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship!. Create a class named Game. Include two Team fields...
Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...
I would like help and there are three different classes in the
coding..
14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...