Question

Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists....

  1. Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists.

  1. Create a Rental class for the company. The class contains:

  • Two public final static fields that hold the number of minutes in an hour and the hourly rental rate ($40)
  • Four private fields that hold a contract number, number of hours for the rental, number of minutes over an hour, and the price. The contract number is stored as a String because Sammy plans to assign contract numbers such as K681.
  • Two public set methods. One sets the contract number (setContractNumber()). The other is named (setHoursAndMinutes()) and it accepts the number of minutes for the rental and then sets the hours, extra minutes over an hour, and the total price. The price is $40 an hour and plus $1 for every extra minute.
  • Four public get methods that return the values in four nonstatic fields.
  • Two overloaded constructors
    • One constructor accepts a contract number and number of minutes as parameters. Pass these values to the setContractNumber() and setHoursAndMinutes() methods, respectively. The setHoursAndMinutes() method will automatically calculate the rent.
    • The other constructor is a default constructor that passes “A000” and 0 to the two-parameter constructor. (use this() reference)

Save the above file as Rental.java.                                                  (5 Marks)

b.         Create a RentalDemo class to instantiate two Rental objects.

  • Instantiate one object to retain the constructor default values.
  • Accept user data for the contract number and minutes fields, and use this data set to instantiate the second object. (Hint: Create two static methods which prompt user to enter contract number and number of minutes, respectively (use Scanner class) and return these values to main() method in two local variables and then pass these variables to two-parameter constructor.
  • Display all the details for both objects (use a static displayDetails() method)

Save the above file as RentalDemo.java.                                        (5 Marks)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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!

Add a comment
Know the answer?
Add Answer to:
Sammy’s Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now...

    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,...

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

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

  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

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

    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 Circle with one instance variable of type double called radius. Then define an...

    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)...

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

  • Anyone helps me in a Java Languageif it it is possible thanks. Write a class called...

    Anyone helps me in a Java Languageif it it is possible thanks. Write a class called Player that holds the following information: Team Name (e.g., Ravens) . Player Name (e.g., Flacco) . Position's Name (e.g. Wide reciver) . Playing hours per week (e.g. 30 hours per week). Payment Rate (e.g., 46 per hour) . Number of Players in the Team (e.g. 80 players) . This information represents the class member variables. Declare all variables of Payer class as private except...

  • (JAVA) Programming Assignment 3 There are a number of zoos available to tourists. 1. Create a...

    (JAVA) Programming Assignment 3 There are a number of zoos available to tourists. 1. Create a Zoo class. Include data fields such as name of zoo, location, size, fee for the past 12 months, number of visitors recorded for the past 12 months, admission rates per visitor and annual budget. (20 points) 2. Include at least two mutators and two accessors. (15 points) 3. Include one default constructor and one more constructor. (15 points) 4. Write separate instance methods that...

  • JAVA programing Question 1 (Date Class):                                   &nbsp

    JAVA programing Question 1 (Date Class):                                                                                                     5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT