Question

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 ID that identifies the meter.

− A reference to the car (ParkedCar object) that is currently parked at the meter. If no car is parked, this parameter should be set to null (in this case, make sure to return “Car: none” in your toString method).

− Whether the meter has expired or not.

− The current time (you may simulate the current time).

• The ParkingTicket class: This class should simulate a parking ticket. The class should report:

− The make, model, color and license number of the illegally parked car.

− Meter ID

− The current time.

− The amount of fine, which is $25 if the meter has expired and the current time is between 9 a.m. and 5 p.m. and $10 if the meter has expired and the current time is between 5.01 p.m. and 8.59 a.m.

− The name and badge number of the police officer issuing the ticket (DO NOT store ParkingOfficer object).

• The ParkingOfficer class: This class should simulate a parking officer inspecting parked cars. The class has − the Officer’s name and badge number

− isExpired method that examines the ParkingMeter object and determines whether the meter has expired.

− A method that examines the given parking meter and returns a parking ticket (generates a ParkingTicket object) if the meter has expired. If it is not expired or no car is parked at the meter, return null value.

You may include instance variables and public interfaces in each class as you may find appropriate. Also add appropriate error checks.

Write a client program that demonstrates how these classes collaborate. In addition, you should create a UML diagram for demonstrating the relationship among the classes and submit that UML as part of your submission.

Here are some examples of your output. They need not be exactly as shown. Feel free to be creative, but you should test your program for all cases.

Parking Meter: 34521 Time: 8.00 p.m. No car parked C Parking Meter: 45673 Time: 4.54 p.m. Car Parked: Lexus ES350, Black, ABC

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

CODE :

import java.util.Random;

public class ParkingTicketSimulater {

public static void main(String[] args) {

ParkedCar parkedCar1 = new ParkedCar("toyota", "camry", "red", 875653, random());
ParkedCar parkedCar2 = new ParkedCar("volkswagon", "jetta", "blue", 45653, random());
ParkedCar parkedCar3 = new ParkedCar("nissan", "altima", "black", 3456343, random());

ParkingMeter parkingMeter1 = new ParkingMeter(random(), 384945);
ParkingMeter parkingMeter2 = new ParkingMeter(random(), 28464);
ParkingMeter parkingMeter3 = new ParkingMeter(random(), 4392502);

PoliceOfficer dave = new PoliceOfficer("dave", 546);

ParkingTicket parking = new ParkingTicket(parkingMeter1, parkedCar1, dave);
ParkingTicket parking1 = new ParkingTicket(parkingMeter2, parkedCar2, dave);
ParkingTicket parking2 = new ParkingTicket(parkingMeter3, parkedCar3, dave);

String parkingTicket = dave.examine(parkedCar1, parkingMeter1);
String parkingTicket1 = dave.examine(parkedCar2, parkingMeter2);
String parkingTicket2 = dave.examine(parkedCar3, parkingMeter3);


if(parkingTicket == null && parkingTicket1 == null && parkingTicket2 == null) {
System.out.println("No parking ticket generated!");
} else {
if(parkingTicket != null) {
System.out.println(parking);
} if(parkingTicket1 != null) {
System.out.println(parking1);
} if(parkingTicket2 != null) {
System.out.println(parking2);
}
}


}

public static int random() {
Random random = new Random();

return random.nextInt(500) + 1;
}
}


public class ParkedCar {
private String make;
private String model;
private String color;
private int licensePlate;
private int minutesParked;

public ParkedCar(String make, String model, String color, int licensePlate, int minutesParked) {

this.make = make;
this.model = model;
this.color = color;
this.licensePlate = licensePlate;
this.minutesParked = minutesParked;
}

public ParkedCar(ParkedCar parkedCar) {
make = parkedCar.make;
model = parkedCar.model;
color = parkedCar.color;
licensePlate = parkedCar.licensePlate;
minutesParked = parkedCar.minutesParked;
}

public void setMake(String make) {
this.make = make;

}

public void setModel(String model) {
this.model = model;
}

public void setColor(String color) {
this.color = color;
}

public void setLicensePlate(int licensePlate) {
this.licensePlate = licensePlate;
}

public void setMinutesParked(int minutesParked) {
this.minutesParked = minutesParked;
}

public String getMake() {
return this.make;
}

public String getModel() {
return this.model;
}

public String getColor() {
return this.color;
}

public int getLicensePlate() {
return this.licensePlate;
}

public int getMinutesParked() {
return minutesParked;
}

public String toString() {
String str = "\nmake: " + make + '\n' +
"model: " + model + '\n' +
"color: " + color + '\n' +
"license plae: " + licensePlate + '\n' +
"minutes parked: " + getMinutesParked() + '\n';
return str;
}
}


public class ParkingMeter {
private int parkingLotNumber;
private int minutesOnMeter;

public ParkingMeter(int minutesOnMeter, int parkingLotNumber) {
this.minutesOnMeter = minutesOnMeter;
this.parkingLotNumber = parkingLotNumber;
}

public ParkingMeter(ParkingMeter parkingMeter) {
minutesOnMeter = parkingMeter.minutesOnMeter;
parkingLotNumber = parkingMeter.parkingLotNumber;
}

private void setParkingLotNumber(int ParkingLotNumber) {
this.parkingLotNumber = parkingLotNumber;
}

public int getParkingLotNumber() {
return this.parkingLotNumber;
}

public void setMinutesOnMeter(int minutesOnMeter) {
minutesOnMeter = minutesOnMeter;
}

public int getMinutesOnMeter() {
return minutesOnMeter;
}

public String toString() {
String str = "minutes on meter: " + minutesOnMeter + "\n parking lot number: " + parkingLotNumber + '\n';
return str;
}

}

public class PoliceOfficer {
private String name;
private int badgeNumber;

public final int FEE_AMOUNT = 1;

public PoliceOfficer(String name, int badgeNumber) {
this.name = name;
this.badgeNumber = badgeNumber;
}

public PoliceOfficer(PoliceOfficer policeOfficer) {
// TODO Auto-generated constructor stub
name = policeOfficer.name;
badgeNumber= policeOfficer.badgeNumber;
}

public String examine(ParkedCar parkedCar, ParkingMeter parkingMeter) {


String fine = null;
int parkingTimeOver = parkingMeter.getMinutesOnMeter() - parkedCar.getMinutesParked();

int feeAmount = FEE_AMOUNT * parkingTimeOver;

if(parkingTimeOver > 0) {

fine = "$"+ feeAmount;

}

return fine;

}

public String toString() {
String str = "\nName: " + name + "\n" + "badge number: " + badgeNumber + '\n' ;
return str;
}
}

public class ParkingTicket {
private ParkingMeter parkingMeter;
private ParkedCar parkedCar;
private PoliceOfficer policeofficer;


public ParkingTicket(ParkingMeter parkingMeter, ParkedCar parkedCar, PoliceOfficer policeOfficer) {
this.parkingMeter = new ParkingMeter(parkingMeter);
this.parkedCar = new ParkedCar(parkedCar);
this.policeofficer = new PoliceOfficer(policeOfficer);

}

public String toString() {
String str = "------------------------------------------------------\n" +
"Parking meter: " + parkingMeter + "\nparked car: " + parkedCar + "\npolice officer:" + policeofficer;
return str;
}
//toString

}

OUTPUT :

Parking eter: miSTUTes on reter: 389 parking lot number: 28464 parked car: make: volkswagon odel: jetta Color: blue license p

Add a comment
Know the answer?
Add Answer to:
using java: For this exercise, you will design a set of classes that work together to simulate a parking officer checkin...
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
  • Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment =====================...

    Please help me with this exercises in JAVA, Thank you ===================== Parking Ticket Simulator Assignment ===================== For this assignment you will create a set of classes from scratch (no provided class files for this assignment) that work together to simulate a police officer issuing a parking ticket. You should design the following classes / functionality within them: ===================== ParkedCar.java: ===================== This class should simulate a parked car. The class's responsibilities are as follows: - To store the car's make, model,...

  • Parking Ticket Simulator C++ HELP PLEASE

    For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should designare:• The ParkedCar Class: This class should simulate a parked car. The class’s responsibilities are:o To know the car’s make, model, color, license number, and the number of minutes that the car has been parked• The ParkingMeter Class: This class should simulate a parking meter. The class’s only responsibility is:o To know the number...

  • 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. •          ...

  • This is assignment and code from this site but it will not compile....can you help? home...

    This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

  • Project: Parking Ticket Simulator Problem Description: For this assignment you will design a set of classes that work...

    Project: Parking Ticket Simulator Problem Description: For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. The classes you should design are:

  • 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....

  • Design a set of classes that work together to simulate the Stock Transaction System. You should...

    Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows:    -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on a stock market. The class's...

  • need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...

    need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...

  • Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need...

    Use the description from Parking Ticket Simulator from Chapter 14 as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example in the PPT) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked beyond their time...

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