Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Coding ! From the Refined Algorithm Lecture, write the code from the refined algorithm that will calculate and display in minutes and hours

In Java Coding !

From the Refined Algorithm Lecture, write the code from the refined algorithm that will calculate and display in minutes and hours how long a car has been parked. Include the computed parking fees where the charges are $1.00 per hour and $1.00 for a partial hour. Print out an error message if the input is invalid.

You must include the following:

1. IF the User enters 0 minutes, print a message letting them know they did not enter a valid parking time.

2. ELSE the User entered minutes greater than 0 then do the following:

a. Keep the hours and minutes as integers. Do not use double or single for these values. b. Print out the hours and minutes as follows:

Your car has been parked for x hours and x minutes.

c. Calculate the parking fee as a double. d. Format as currency and print out the parking fees as follows:

You owe $xx.xx in parking fees.

3. Test your program thoroughly with the following data:

1. 65 minutes 2. 345 minutes 3. 120 minutes 4. 35 minutes 5. 0 minutes

NOTES:

1. Invalid input would be a zero or less. 2. Do not compute any fees if the input is invalid. 3. Do not print out any parking fees if the input is invalid. 4. Declare all variables within the data declaration section. 5. Do not get input on the same line as a variable declaration. 6. Do not place an equation for computation on the same line as declaring a variable.

------------------------------------------------------------------------------------------------------------------------------------- Refined algorithm

Create a Refined Algorithm:

We start with the Initial Algorithm and fill in the details of HOW each step will be executed to create our Refined Algorithm.

1. Get the total number of minutes parked:

o Input totalMinutes.

2. IF the totalMinutes is equal to zero THEN

o Output an error message stating that the number of minutes is invalid.

3. ELSE.

o Compute the total hours parked:

hoursParked = totalMinutes / 60

o Compute the left over minutes parked:

minutesParked = totalMinutes % 60

o Compute the parking fee for the number of hours parked:

parkingFee = hoursParked * 1.00

o IF minutesParked is greater than zero THEN

parkingFee = parkingFee + 1.00

o END IF

Display the parkingFee

4. END IF

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions