Question

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 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;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Money Problems in Java
Homework Solution
$20.00
Java
Programming
Codes
Algorithms
Money
Dimes
Nickels
Pennies
Input
Output
Integers
Statements
Variables
Accounting
Recursion Methods
Finance
Java Problems With Stack
Homework Solution
$40.00
Java
Programming
Coding
Computer Science
Stack
Generic Types
Push
Pop
Peek
Size
Linked List
Functions
Strings
Integers
Summation
Negative Values
Input
Output
Multiplication Table in Java
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Rows
Columns
Input
Output
Integers
Strings
Multiplication
Tables
Operations
Conditions
Nested Statements in Java
Homework Solution
$15.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Nested Statements
For Statement
While Statement
Get help from a qualified tutor
Live Chats