The RoomCarpet class should have a method that return the to

The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting the relationships between the classes. Once you written these classes, use them in an application that asks the user to enter the dimension of a room and the price per square foot of the desired carpeting. The application should display the total cost of the carpet. Parking Ticket Simulator 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: bullet The ParkedCar Class: This class should simulate a parked car. The class\'s responsibilities are: To know the Car\'s make, model, color, license number, and the number of minutes that the car has been parked. bullet The ParkingMeter Class: This class should simulate a parking meter. The class\'s only responsibility is: To know the number of minutes of parking time that has been purchased bullet The ParkingTicket Class: This class should simulate a parking ticket. The class\'s responsibilities are: To report the make, model, color, and license number of the illegally parked car To report the amount of the fine, which is $25 for the first hour or part of an hour that the car is illegally parked, plus $10 for every additional hour or part of an hour that the car is illegally parked To report the name and badge number of the police officer issuing the ticket bullet The PoliceOfficer Class: This class should simulate a police officer inspecting parked cars, The class\'s responsibilities are: To know the police officer\'s name and badge number To examine whether the car, time has expired

Solution

Solution: See the code below. From the problem, it looks like to be developed in Java. So I have written code in Java.

1. ParkedCar class:

--------------------------------------------------

package parkingticket;

/**
* ParkedCar class
*
*/
public class ParkedCar {
   private String make; // make of car
   private String model; // model of car
   private String color; // color of car
   private String licenseNumber; // license no. of car
   private int minutesParked; // no. of minutes a car is parked.

   /**
   * Constructor
   *
   * @param make
   * @param model
   * @param color
   * @param licenseNumber
   * @param minutesParked
   */
   public ParkedCar(String make, String model, String color, String licenseNumber, int minutesParked) {
       super();
       this.make = make;
       this.model = model;
       this.color = color;
       this.licenseNumber = licenseNumber;
       this.minutesParked = minutesParked;
   }

   /**
   * Copy constructor
   */
   public ParkedCar(ParkedCar car) {
       this.make = car.make;
       this.model = car.model;
       this.color = car.color;
       this.licenseNumber = car.licenseNumber;
       this.minutesParked = car.minutesParked;
   }

   /**
   * @return the make
   */
   public String getMake() {
       return make;
   }

   /**
   * @param make
   *            the make to set
   */
   public void setMake(String make) {
       this.make = make;
   }

   /**
   * @return the model
   */
   public String getModel() {
       return model;
   }

   /**
   * @param model
   *            the model to set
   */
   public void setModel(String model) {
       this.model = model;
   }

   /**
   * @return the color
   */
   public String getColor() {
       return color;
   }

   /**
   * @param color
   *            the color to set
   */
   public void setColor(String color) {
       this.color = color;
   }

   /**
   * @return the licenseNumber
   */
   public String getLicenseNumber() {
       return licenseNumber;
   }

   /**
   * @param licenseNumber
   *            the licenseNumber to set
   */
   public void setLicenseNumber(String licenseNumber) {
       this.licenseNumber = licenseNumber;
   }

   /**
   * @return the minutesParked
   */
   public int getMinutesParked() {
       return minutesParked;
   }

   /**
   * @param minutesParked
   *            the minutesParked to set
   */
   public void setMinutesParked(int minutesParked) {
       this.minutesParked = minutesParked;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"ParkedCar [make=\" + make + \", model=\" + model + \", color=\" + color + \", licenseNumber=\" + licenseNumber
               + \", minutesParked=\" + minutesParked + \"]\";
   }

}

-------------------------------------------------------------------

2. ParkingMeter class:

----------------------------------------------------------------

package parkingticket;

/**
* ParkingMeter class
*
*/
public class ParkingMeter {
   private int minutedPurchased; // minutes purchased for parking

   /**
   * Constructor
   *
   * @param minutedPurchased
   */
   public ParkingMeter(int minutedPurchased) {
       super();
       this.minutedPurchased = minutedPurchased;
   }

   /**
   * @return the minutedPurchased
   */
   public int getMinutedPurchased() {
       return minutedPurchased;
   }

   /**
   * @param minutedPurchased
   *            the minutedPurchased to set
   */
   public void setMinutedPurchased(int minutedPurchased) {
       this.minutedPurchased = minutedPurchased;
   }

}

--------------------------------------------------

3. ParkingTicket class:

------------------------------------------------

package parkingticket;

/**
* ParkingTicket class
*
*/
public class ParkingTicket {
   private ParkedCar car; // car parked in parking
   private PoliceOfficer officer; // police officer set to patrol the parking
   private double fine; // fine imposed on car for parking beyond purchased
                           // minutes

   /**
   * Constructor
   *
   * @param car
   * @param officer
   * @param fine
   */
   public ParkingTicket(ParkedCar car, PoliceOfficer officer, double fine) {
       super();
       this.car = car;
       this.officer = officer;
       this.fine = fine;
   }

   /**
   * Copy constructor
   */
   public ParkingTicket(ParkingTicket ticket) {
       this.car = ticket.car;
       this.officer = ticket.officer;
       this.fine = ticket.fine;
   }

   /**
   * @return the car
   */
   public ParkedCar getCar() {
       return car;
   }

   /**
   * @param car
   *            the car to set
   */
   public void setCar(ParkedCar car) {
       this.car = car;
   }

   /**
   * @return the officer
   */
   public PoliceOfficer getOfficer() {
       return officer;
   }

   /**
   * @param officer
   *            the officer to set
   */
   public void setOfficer(PoliceOfficer officer) {
       this.officer = officer;
   }

   /**
   * @return the fine
   */
   public double getFine() {
       return fine;
   }

   /**
   * calculates fine
   */
   public void calculateFine(int extraParkedMinutes) {
       double hours=extraParkedMinutes/60;
       if(hours > 1)
       {
           fine=fine+(hours-1)*10;;
       }      
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"ParkingTicket [car=\" + car + \", officer=\" + officer + \", fine=\" + fine + \"]\";
   }  
}

-------------------------------------------------

4. PoliceOfficer class:

--------------------------------------------------

package parkingticket;

/**
* PoliceOfficer class
*
*/
public class PoliceOfficer {
   private String name; // name of police officer
   private String badgeNumber; // badge number of officer

   /**
   * Constructor
   *
   * @param name
   * @param badgeNumber
   */
   public PoliceOfficer(String name, String badgeNumber) {
       super();
       this.name = name;
       this.badgeNumber = badgeNumber;
   }

   /**
   * Copy constructor
   */
   public PoliceOfficer(PoliceOfficer officer) {
       this.name = officer.name;
       this.badgeNumber = officer.badgeNumber;
   }

   /**
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * @param name
   *            the name to set
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * @return the badgeNumber
   */
   public String getBadgeNumber() {
       return badgeNumber;
   }

   /**
   * @param badgeNumber
   *            the badgeNumber to set
   */
   public void setBadgeNumber(String badgeNumber) {
       this.badgeNumber = badgeNumber;
   }

   /**
   * patrols car
   */
   public int patrol(ParkedCar car, ParkingMeter meter) {
       return (car.getMinutesParked() - meter.getMinutedPurchased());
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return \"PoliceOfficer [name=\" + name + \", badgeNumber=\" + badgeNumber + \"]\";
   }
}

---------------------------------------------

5. ParkingTicketSimulator class containing main() function:

-----------------------------------------------

package parkingticket;

/**
* ParkingTickerSimulator class
*
*/
public class ParkingTicketSimulator {

   /**
   * @param args
   */
   public static void main(String[] args) {

       // parked car
       ParkedCar car = new ParkedCar(\"Buke\", \"1972\", \"Black\", \"128RXVM\", 80);
       // parking meter
       ParkingMeter meter = new ParkingMeter(60);
       // police officer on duty
       PoliceOfficer officer = new PoliceOfficer(\"John Merchant\", \"4566\");

       // car data
       System.out.println(car.toString());

       // officer data
       System.out.println(officer.toString());

       // officer patrols the car for extra parked minutes
       int extraParkedMinutes = officer.patrol(car, meter);

       // check if parking ticket can be issued.
       if (extraParkedMinutes > 0) {
           ParkingTicket ticket = new ParkingTicket(car, officer, 25);
           ticket.calculateFine(extraParkedMinutes);
           System.out.println(\"Illegally parked minutes:\" + extraParkedMinutes);
           System.out.println(\"Fine imposed(in $):\" + ticket.getFine());
       } else {
           System.out.println(\"No crimes committed!\");
       }

   }

}

---------------------------------------------------------

6. Output:

------------------------------------------------------

ParkedCar [make=Buke, model=1972, color=Black, licenseNumber=128RXVM, minutesParked=80]
PoliceOfficer [name=John Merchant, badgeNumber=4566]
Illegally parked minutes:20
Fine imposed(in $):25.0

----------------------------------------

 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th
 The RoomCarpet class should have a method that return the total cost of the carpet. Figure 6-21 is a UML diagram showing possible class design and depicting th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site