Question

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

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

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

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

Add a comment
Know the answer?
Add Answer to:
Objective: The objective of this lab is to get familiar with the syntax of the Java...
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
  • A parking garage has 5 customers daily. The garage charges a $5.00 minimum fee to park...

    A parking garage has 5 customers daily. The garage charges a $5.00 minimum fee to park up to two hours. The garage charges an additional $1.00 per hour for each hour (or part of an hour) over two hours. The maximum charge for any given day is $12.00. All cars are gone by midnight. Write a program to calculate and print a summary of the charges for a day. For input the program will read the hours of usage for...

  • Write a program in C An international airport offers long term parking at the following rates:...

    Write a program in C An international airport offers long term parking at the following rates: First 60 minutes is free; 61-80 minutes $4; Each additional 20 minutes $2; And $18 max. per day (24 hours). Write a program longterm_parking.c that calculates and prints the charges for parking at the long term parking garage. 1. The user enters the number of total hours and minutes; the program prints the charge. 2. If the input is invalid, print a message and...

  • write in java and you must use methods.... Part I     Internet Service Provider An Internet service...

    write in java and you must use methods.... Part I     Internet Service Provider An Internet service provider has three different subscription packages for its customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour. Package B: For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour. Package C: For $19.95 per month unlimited access is provided. Write a program that calculates a customer’s monthly bill....

  • in java PART ONE ================================================== Write a program that will read employee earnings data from an...

    in java PART ONE ================================================== Write a program that will read employee earnings data from an external file and then sort and display that data. Copy and paste the input file data below into an external file, which your program will then read. You will want to use parallel arrays for this program. Modify the select sort algorithm to receive both arrays as parameters as well as the size of the arrays. Use the algorithm to sort your earnings array....

  • Write a Java application that determines whether any of several department store customers has exceeded the...

    Write a Java application that determines whether any of several department store customers has exceeded the credit limit on a charge account. For each customer, the following facts are inputted: -Balance at beginning of month -Total amount of all items charged by the customer this month -Total amount of all credits applied to the customer’s account this month -Allowed credit limit Use the value of -1 as a sentinel value to quit the program. The program should input all these...

  • I need help with this java project and please follow the instruction below. thank Class Project...

    I need help with this java project and please follow the instruction below. thank Class Project - Parking Ticket simulator Design a set of classes that work together to simulate a police officer issuing a parking ticket. Design the following classes: •           The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are as follows: – To know the car’s make, model, color, license number, and the number of minutes that the car has been parked. •          ...

  • ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

    ll this is a java code do it in eclipse please. thank you. Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs...

  • using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...

    using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checking a parked car issuing a parking ticket if there is a parking violation. Here are the classes that need to collaborate: • The ParkedCar class: This class should simulate a parked car. The car has a make, model, color, license number. •The ParkingMeter class: This class should simulate a parking meter. The class has three parameters: − A 5-digit...

  • The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for...

    The electric company charges according to the following rate schedule: 9 cents per kilowatt-hour (kwh) for the first 300 kwh 8 cents per kwh for the next 300 kwh (up to 600 kwh) 6 cents per kwh for the next 400 kwh (up to 1000 kwh) 5 cents per kwh for all electricity used over 1000 kwh Write a program that would repeatedly read in a customer number (an integer) and the usage for that customer in kwh (an integer)....

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