42.1k views
5 votes
Sammy's Seashore Supplies rents beach equipment such as kayaks, canoes, beach chairs, and umbrellas to tourists. Write a program that prompts the user for the number of minutes he rented a piece of sports equipment. Compute the rental cost as $40 per hour plus $1 per additional minute. (You might have surmised already that this rate has a logical flaw, but for now, calculate rates as described here. You can fix the problem after you read the chapter on decision making.) Display Sammy's motto with the border that you created in the SammysMotto2 class in Chapter 1. Then display the hours, minutes, and total price. Save the file as SammysRentalPrice.java.

1 Answer

5 votes

Answer:

// here is code in java.

import java.util.*;

// class definition

class SammysRentalPrice

{

// main method of the class

public static void main(String[] args) {

// scanner object to read input from user

Scanner s=new Scanner(System.in);

// ask user to enter year

System.out.print("Enter the rented minutes:");

// read minutes

int min=s.nextInt();

// find hpurs

int hours=min/60;

// rest of minutes after the hours

min=min%60;

// total cost

int tot_cost=(hours*40)+(min*1);

// print hours,minute and total cost

System.out.println("total hours is: "+hours);

System.out.println("total minutes is: "+min);

System.out.println("total cost is: "+tot_cost);

}

}

Step-by-step explanation:

Read the rented minutes of an equipment from user with the help of scanner object. Calculate the hours and then minutes from the given minutes.Calculate the cost by multiply 40 with hours and minute with 1.Add both of them, this will be the total cost.

Output:

Enter the rented minutes:140

total hours is: 2

total minutes is: 20

total cost is: 100

User Ernist Isabekov
by
6.4k points