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

A. Sammy\'s Seashore Supplies rents beach equipment such as kayaks, canoes, beac

ID: 3862254 • Letter: A

Question

A. Sammy's Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. Develop an application that prompts the user for the number of minutes a piece of sports equipment was rented, displays the company motto with a border, and displays the price for the rental. Now modify the program so that the main() method conatins only three executable statments that each call a method as follows:
- The first executable statement calls a method that prompts the user for the rental time in minutes and returns the value as the main()method
- The first executable statement calls a method that displays the company motto with the border.
- The last executable statement passes the number of minutes to a method that computes the hours, extra minutes, and price for the rental, and then displays all the details.
Save the file as SammyRentalPriceWithMethods.java
B. Create a class to hold the rental data for Sammy's Seashore Supplies. The class contains:
- Two public final static fields that hold the number for minutes in an hour and hourly 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 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 per hour plus $1 for every extra minute.
- Four public get methods that return the values in the four nonstatic fields.
Save the file as Rental.java
C. Use the SammysRentalPriceWithMethods class you created in Step 2a as a starting point for a program that demonstrates the Rental class you created in Step 2b, but make the following changes:
- You already have a method that gets the number of minutes from a user; biw add a method that gets a contract number. The main() method should declare a Rental object, call the two data entry methods, and use their returned values to set the fields in the Rental object.
- From the SammyRentalPriceWithMethods class, call the Rental Demo method that displays that company motto with the border. The method is accessible becuase it is public, but you must fully qualify the name becuase it is in another class.
- Revise the method that displays the rental details so that it accepts the newly created Rental object. The method should display the contract nuber, and it should still display the hours and minutes, the hourly rate, and the total price.
D. Save the program as RentalDemo.java

Explanation / Answer

//SammyRentalPriceWithMethods.java

import java.util.Scanner;

public class SammyRentalPriceWithMethods {

   //Motto method
   public void motto(){
       System.out.println("Motto-Win to Work...");
   }
   public int rentalMins(){
       //Reading number of minutes
       Scanner s = new Scanner(System.in);
       System.out.println("Enter rental in Mins:");
       int mins = s.nextInt();
       return mins; // Returns minutes
   }
  
}

//Rental.java

public class Rental {

   static final int HOUR = 60; // mins for hours
   static final int HOURLY_RATE = 40; // rate for hour
  
   private String contractNumber;
   private int rentalHours;
   private int noOfMins;
   private int price;
  
   //setters and getters
   public void setContractNumber(String contractNumber){
       this.contractNumber=contractNumber;
   }
  
   public void setHoursAndMinutes(int minutes){
       int hours = minutes/HOUR; // Calculating hours
       int extra = minutes%HOUR; //Calculating minutes
      
       //Calculating price
       int totalPrice = hours*HOURLY_RATE+(extra*1);
      
       //Assigning to class attributes
       this.rentalHours = hours;
       this.noOfMins = extra;
       this.price = totalPrice;
   }

   //Getters
   public int getRentalHours() {
       return rentalHours;
   }

   public int getNoOfMins() {
       return noOfMins;
   }

   public int getPrice() {
       return price;
   }

   public String getContractNumber() {
       return contractNumber;
   }
}

//RentalDemo.java

public class RentalDemo {

   public static void main(String[] args) {
      
       //Create SammyRentalPriceWithMethods object
       SammyRentalPriceWithMethods smr = new SammyRentalPriceWithMethods();
      
       //Creating Rental Object
       Rental r1 = new Rental();
      
       //Setting Contract number
       r1.setContractNumber("K681");
  
       // Reading minutes from SammyRentalPriceWithMethods
       int mins = smr.rentalMins();
       r1.setHoursAndMinutes(mins);
      
      
       //Prinint details of Contract, Hours, Extra Mins and Total Price
       System.out.println("*******************************");
       smr.motto();
       System.out.println("Contract Number:"+r1.getContractNumber());
       System.out.println("Hours:"+r1.getRentalHours());
       System.out.println("Extra Minutes:"+r1.getNoOfMins());
       System.out.println("Hourly Rate:$"+r1.HOURLY_RATE);
       System.out.println("Total Price:$"+r1.getPrice());
   }

}

Output:

Enter rental in Mins:
121
*******************************
Motto-Win to Work...
Contract Number:K681
Hours:2
Extra Minutes:1
Hourly Rate:$40
Total Price:$81