QuestionQuestion

Create the following class:

ParkedCar
This class has the following attributes:
• car make
• car model
• car colour
• license number
• number of minutes parked
• owner name

Provide the following constructors and methods:

• A default constructor that initializes all fields of type String to an empty String (“”), and initializes the rest of the fields to their default values according to their data types.
• A non-default constructor that accepts parameters to initialize all the fields. The constructor validates each passed parameter and uses it if it’s valid. If not, the instance variable will be set to the default value except that the string will be set to an empty string (“”). The number of minutes parked must not be negative.
• An appropriately named accessor method and an appropriately named mutator method for each field. The mutator methods check their parameter to ensure it’s valid. If not valid, the parameter is not used and an error message is displayed on the screen. Note that the number of minutes parked should always have a positive value.
• A method to display the details of the car on the screen.

ParkingMeter
This class has the following attributes:
• The constant MAXIMUM_AMOUNT_OF_PURCHASED_MINUTES = 180
• number of purchased minutes
• meter type for example “single parking”, “multi parking” ...
• meter location
• price of one minute
• is there a camera

Provide the following constructors and methods:
• A default constructor that initializes all the fields of type String to an empty string (“”) instead of null, and initializes the rest of the fields to their default values according to their data types.
• A non-default constructor that accepts parameters to initialize all the fields. The constructor validates each passed parameter and uses it if it’s valid. For the number of minutes purchased, if the passed parameter is greater than MAXIMUM_AMOUNT_OF_PURCHASED_MINUTES, the instance variable is set to that maximum value. If the number of minutes purchased is negative, the instance variable is set to zero. For the other parameters, if invalid the instance variable is set to the default value except that strings will be set to empty strings (“”)
• An appropriately named accessor method and an appropriately named mutator method for each field. The mutator methods check their parameter to ensure it’s valid. For the number of minutes purchased, if the passed parameter is greater than MAXIMUM_AMOUNT_OF_PURCHASED_MINUTES, the instance variable is set to that maximum value and a message to that effect is displayed on the screen. If the number of minutes purchased is negative, the instance variable is not changed and an error message is displayed. For the other mutators, if the passed parameters is invalid it is not used and an error message is displayed. Note that the valid values of number of purchased minutes should be between 0 and 180 inclusive and the price of one minute should never be a negative value.
• A method to display the details of the parking meter on the screen. Use BlueJ to interactively test your methods as you write them. Write them one at a time, and test each immediately to be sure it is correct. Testing requires creating an object and invoking the method. Be sure to test with both valid and invalid data, i.e. test the “set” methods with positive values to be sure the field is changed correctly, and test with negative values to be sure the field is set to the default value.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class ParkedCar {

private String make, model, color, licenseNum, ownerName;
private int minParked;


/**
* Default Constructor
*/
public ParkedCar()
{
make = "";
model = "";
color = "";
licenseNum = "";
ownerName = "";
minParked = 0;
}

/**
* @param make - Car make
* @param model - Car model
* @param color - Car color
* @param licenseNum - License number
* @param ownerName - Car owner name
* @param minParked - Minutes Parked
*/
public ParkedCar(String make, String model, String color, String licenseNum, String ownerName, int minParked) {
this.make = make;
this.model = model;
this.color = color;
this.licenseNum = licenseNum;
this.ownerName = ownerName;
if(minParked < 0)
this.minParked = 0;
else
this.minParked = minParked;
}...

50% discount

Hours
Minutes
Seconds
$30.00 $15.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats