1 answer

Objective: The objective of this lab is to get familiar with the syntax of the Java...

Question:

Objective: The objective of this lab is to get familiar with the syntax of the Java programming language. This lab is designed to reinforce programming concepts.

Instructions:

Description of the Problem.
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time.

Write a Java application that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer. The program should display the charge for the current customer and should calculate and display the running total of yesterday’s receipts. The program should use the method calculateCharges to determine the charge for each customer.

Sample Output

Enter number of hours (a negative to quit): 2
Current charge: $2.00, Total receipts: $2.00
Enter number of hours (a negative to quit): 10
Current charge: $5.50, Total receipts: $7.50
Enter number of hours (a negative to quit): -1


Answers

// do comment if any problem arises

//code

import java.util.Scanner;

class charge {

    public double get_charge(int hours) {

        // if car is parked for 10 hours

        if (hours == 24)

            return 10.00;

        // initail charge of 2$

        double charge = 2.00;

        // if car has been parked for greater than 3 hours

        if (hours > 3)

            charge += (hours - 3) * 0.5;

        return charge;

    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        double total = 0;

        // create a temporary object

        charge temp = new charge();

        while (true) {

            // read number of hours from user

            System.out.print("Enter number of hours (a negaitve to quit): ");

            int hours = sc.nextInt();

            // if user enters -ve break

            if (hours < 0)

                break;

            // calculate charge for given hours and display

            double current_charge = temp.get_charge(hours);

            total += current_charge;

            System.out.println("Current charge: $" + current_charge + ", Total reciepts: $" + total);

        }

    }

}

Output:

Enter number of hours (a negaitve to quit): 2 Current charge: $2.0, Total reciepts: $2.0 Enter number of hours (a negaitve to

.

Similar Solved Questions

1 answer
3. (Gaddis Exercises 20.4) Tree Height Write a recursive member function for the BinaryTree class that...
3. (Gaddis Exercises 20.4) Tree Height Write a recursive member function for the BinaryTree class that returns the height of the tree. The height of the tree is the number of levels it contains. Demonstrate the function in a driver program. CPP FILE CODE: #include "BinaryTree.h" #include <...
1 answer
3. For the game represented below 1) Modify the game matrix by eliminating dominated strategies 2)...
3. For the game represented below 1) Modify the game matrix by eliminating dominated strategies 2) Find a Nash Equilibrium in pure strategies. 3) Find NE in mixed strategies Y 3; 4 2; 2 3,5 D 2;3 1; 5 Z 5; 2 2;1 3:3 0:4 3; 0...
1 answer
UNFLAG nurse is preparing to administer heparin 15 units/kg/hr by continuous IV infusion to a client...
UNFLAG nurse is preparing to administer heparin 15 units/kg/hr by continuous IV infusion to a client who weighs 72 kg. Available is 25,000 units of heparin in 500 mL 0.9% sodium chloride. The nurse should set the IV pump to deliver how many ml/hr? (Round the answer to the nearest tenth. Use a leadin...
1 answer
What was Australia's budget deficit and national debt as a percent of GDP prior to the...
What was Australia's budget deficit and national debt as a percent of GDP prior to the financial crisis and how has it changed since (due to economic weakness as well as any stimulus)? Does this seem to pose a problem? Please explain thoroughly.  ...
1 answer
1954873726473946058elSBN-97813373869998id-4389320168snapshotld Q Search this course Project Repat is classified as a(n) few people own shares of...
1954873726473946058elSBN-97813373869998id-4389320168snapshotld Q Search this course Project Repat is classified as a(n) few people own shares of its stock. Oa. open corporation Ob. S corporation Oc. closed corporation Od. B corporation because only a Project Repat has a corporate charter. Which of t...
1 answer
Metronidazole is used in the treatment of anaerobic protozoal infections. Although often administered orally, it can...
Metronidazole is used in the treatment of anaerobic protozoal infections. Although often administered orally, it can also be delivered by means of an IV infusion. The loading dose is 15 mg per kilogram of body mass and is infused over one hour. The maintenance dose is 7.5 mg per kilogram of body mas...
1 answer
C) (5 points) Me OzN_NO2 Me xylenes, heat d) (5 points) Ph toluene, heat iPr SMO
c) (5 points) Me OzN_NO2 Me xylenes, heat d) (5 points) Ph toluene, heat iPr SMO...
1 answer
Decision on Accepting Additional Business Down Home Jeans Co. has an annual plant capacity of 63,700...
Decision on Accepting Additional Business Down Home Jeans Co. has an annual plant capacity of 63,700 units, and current production is 43,600 units. Monthly fixed costs are $38,600, and variable costs are $25 per unit. The present selling price is $38 per unit. On November 12 of the current year, the...
1 answer
Write a single 16-bit LC-3 instruction (in binary) that clears all the bits of R6 except...
Write a single 16-bit LC-3 instruction (in binary) that clears all the bits of R6 except the least significant two bits. Write a single 16-bit LC-3 instruction (in binary) that clears all the bits of R6 except the least significant two bits. In other words, after your instruction executes, bits O an...
1 answer
Exercise 3.8. Let A { 1, 3, 5, 7, 9), B-{0.2, 4, 6, 8], C-(1, 2,...
Exercise 3.8. Let A { 1, 3, 5, 7, 9), B-{0.2, 4, 6, 8], C-(1, 2, 4, 5, 7, 8}, and Ω={0.1.2, 3,4,5, 6, 7, 8, 9). Find the following: a An BuC, and An (BUC) (Note that these aren't the same!) b (An B) U (AnC), and An(BUC) c AUB, and AuB. Are these the same?...
1 answer
The Striving for Perfection Urgent Care Center feels that its patients wait time is too long. The staff has noticed that increasing numbers of people are waiting longer in the waiting room. The nation...
The Striving for Perfection Urgent Care Center feels that its patients wait time is too long. The staff has noticed that increasing numbers of people are waiting longer in the waiting room. The national benchmark performance is 90 minutes or less from the time the customer arrives to the time the cu...
1 answer
Would some please explain how to solve this problem and what I did wrong? Also, sorry...
Would some please explain how to solve this problem and what I did wrong? Also, sorry the handwriting is atrocious, I was doing it in a hurry. also could you explain how this could possibly be wrong An unknown compound contains only C. H and O. Combustion of 7.00 g of this compound produc...
1 answer
Please write detailed (with headings) and original answer. We get it, life is about communication and...
Please write detailed (with headings) and original answer. We get it, life is about communication and so is business. To that end, are there systematic steps a company can take to avoid bad press associated with "selling"? Go on to discuss the ethical overtones associated with business promo...
1 answer
7. (4+6=10 pts) State Biot-Savart law and Ampere's law. Now use Ampere's law to answer following:...
7. (4+6=10 pts) State Biot-Savart law and Ampere's law. Now use Ampere's law to answer following: A long, cylindrical wire (radius = 2.0 cm) carries a current of 40 A that is uniformly distributed (uniform current density) over a cross section of the wire. What is the magnitude of the magnet...
1 answer
Torres Company accumulates the following summary data for the year ending December 31, 2020, for its...
Torres Company accumulates the following summary data for the year ending December 31, 2020, for its Water Division, which it operates as a profit center: sales—$1,989,600 budget, $2,183,200 actual; variable costs—$1,001,800 budget, $1,044,600 actual; and controllable fixed costs—$...
1 answer
MSI's educational products are currently sold without any supplemental materials. The company is considering the inclusion...
MSI's educational products are currently sold without any supplemental materials. The company is considering the inclusion of instructional materials such as an overhead slide presentation, potential test questions, and classroom bulletin board materials for teachers. A summary of the expected c...
1 answer
What is the range? f(x)= - 3x if x 50 -2 if x>0 The domain of...
what is the range? f(x)= - 3x if x 50 -2 if x>0 The domain of the piecewise function is (-00,00). a. Graph the function b. Use your graph to determine the function's range, a. Choose the correct graph below. ОА. C B. Ос. AY a AY 10 10 10 10 -10 TO b. The range of f(...
1 answer
P7 continuous random variable X has the probability density function fx(x) = 2/9 if P.5 The...
P7 continuous random variable X has the probability density function fx(x) = 2/9 if P.5 The absolutely continuous random 0<r<3 and 0 elsewhere). Let (1 - if 0<x< 1, g(x) = (- 1)3 if 1<x<3, elsewhere. Calculate the pdf of Y = 9(X). P. 6 The absolutely continuous random variables X ...
1 answer
Which of the following is statements is TRUE? Beta is a measure of unsystematic risk )...
Which of the following is statements is TRUE? Beta is a measure of unsystematic risk ) A beta of 1 implies the asset has the same unsystematic risk as the overall market. A beta > 1 implies the asset has more systematic risk than the overall market. A beta < 1 implies the asset has more system...