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

Advanced Java Programming with Object-Oriented Programming Design VERY IMPORTANT

ID: 3724110 • Letter: A

Question

Advanced Java Programming with Object-Oriented Programming Design

VERY IMPORTANT NOTE!!: This program for the question below MUST USE at least 2 CLASSES, getters/setters, etc and other object-oriented design (OOD) concepts because I'm in a more advanced Java class that requires me to utilize the concepts mentioned above. Also, I need detailed, but brief comments to most, if not all of the code to explain what is being used in the code and what is does so I have a better understanding of the code. I've seen answers to the question below already posted, however they don't utilize object-oriented design (OOD) concepts such as a minumum of two classes, getters/setters, etc which is required for this advanced Java programming class. So please......help and meet the requirements for this. Here's to hoping this works out......thank you!

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 an 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 via screen as user input. The program should display the charge for the current customer and should calculate and display the running total of yesterday’s receipts.

Explanation / Answer

///////////////////////////////////////////////////////////////////////ParkingGarage.java//////////////////////////////////////////////////////////////////////

package com.java.ParkingApp;

import javax.swing.Box;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class ParkingGarage {

private float minCharge = 2.0f; // Charge for 0 to first Three hrs

private float chargePerHr = 0.5f;// Charge to be applicable every hr

private float maxChargePerDay = 10.0f; // Max charge for 24 hrs

/**

*

* @param numberOfHrs

* user has parked the car

* @return total fare for given number of hours

*/

public float calculateTotalCharges(float numberOfHrs) {

float totalCharge = 0.0f;

if (numberOfHrs <= 3) {

totalCharge = minCharge;

} else if (numberOfHrs > 3 && numberOfHrs <= 16) {

// if user enters floating number like 3.5 he will be charged for 4 hrs so

// ceiling is done to do that

float remainingHrsToCharge = (float) Math.ceil(numberOfHrs - 3.0f);

totalCharge = minCharge + remainingHrsToCharge * chargePerHr;

} else if (numberOfHrs > 16 && numberOfHrs <= 24) {

totalCharge = maxChargePerDay;

}

System.out.println("Total Charge for yesterday was:- " + totalCharge);

return totalCharge;

}

public void displayUserCharges(float totalCharge) {

String message = "Total Charge";

JFrame parent = new JFrame();

parent.setTitle(message);

JOptionPane.showMessageDialog(parent, "TOTAL CHARGE IS = " + totalCharge, message,

JOptionPane.INFORMATION_MESSAGE);

}

/**

*

* @return number of hours the user has parked in

*/

public float getUsrInput() {

float hrsEntered = 0;

JTextField hrField = new JTextField(5);

JPanel myPanel = new JPanel();

myPanel.add(new JLabel("Hours:"));

myPanel.add(hrField);

int result = JOptionPane.showConfirmDialog(null, myPanel, "Please Enter Number of Hours ",

JOptionPane.OK_CANCEL_OPTION);

if (result == JOptionPane.OK_OPTION) {

hrsEntered = Float.valueOf(hrField.getText());

System.out.println("Number of hours parked: " + hrsEntered);

} else if (result == JOptionPane.CANCEL_OPTION) {

System.exit(0); // Exit the program

}

return hrsEntered;

}

/**

* Check if user wants to continue

*

* @return true: if user wants to continue, otherwise false

*/

public boolean checkContinuation() {

Boolean toContinue = false;

JDialog.setDefaultLookAndFeelDecorated(true);

int response = JOptionPane.showConfirmDialog(null, "Do you want to continue?", "Confirm",

JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);

if (response == JOptionPane.NO_OPTION) {

System.out.println("No Button Selected");

} else if (response == JOptionPane.YES_OPTION) {

System.out.println("Yes button clicked");

return toContinue = true;

} else if (response == JOptionPane.CLOSED_OPTION) {

System.out.println("JOptionPane closed");

}

return toContinue;

}

}

/////////////////////////////////////////////////////////////////////ParkingApp/////////////////////////////////////////////////////////////////////////////////////

package com.java.ParkingApp;

import javax.swing.JOptionPane;

/**

*

* ParkingApp is the main class that uses other classes to calculate charges for

* parking

*

*/

public class ParkingApp {

public static void main(String args[]) {

ParkingGarage pg = new ParkingGarage(); // Instantiate Parking Garage class

calculateAndDisplayCharges(pg);

}

/**

* Recursively gets user input and display charges

*

* @param pg

* instance of Parking Garage class

* @return

*/

private static Boolean calculateAndDisplayCharges(ParkingGarage pg) {

float hours = pg.getUsrInput(); // Get the input from user

Boolean toContinue = false;

System.out.println("");

if (hours <= 0.0 || hours > 24.0) {

JOptionPane.showMessageDialog(null, "Hours should be Between 1 to 24 !");

calculateAndDisplayCharges(pg);

} else {

float totalCharge = pg.calculateTotalCharges(hours); // get totalCharge from ParkingGarage class

pg.displayUserCharges(totalCharge); // call method to display the total Charge

toContinue = pg.checkContinuation();

if (toContinue) {

toContinue = calculateAndDisplayCharges(pg); // repeat the process

} else {

System.exit(0);// Finish the program

}

}

return toContinue;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote