The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Can you help me? I want to know how to write the two programs' code?
Â
|
  |
 |
               Â
For this task, you'll practice writing more classes, and you will apply the concept of class aggregation.
This programming task is very similar to what you did for Lab 2, so review it for hints and pointers. The motivation of this programming task is to simulate a police officer issuing a parking ticket. Create four classes, ParkedCar, ParkingMeter, ParkingTicket, and PoliceOfficer.
Â
The ParkedCarclass is meant to hold information about a car's make, model, color, license number, and the number of minutes that the car has been parked. It has two constructors; the first is a constructor that takes five arguments, and the second a copy constructor. Look on page 518 and 519 of the textbook, to review copy constructors.
Â
|
ParkedCar |
|
-Â make : String -Â model : String -Â color : String -Â licenseNumber : String -Â minutesParked : int |
|
+ ParkedCar(mk : String, mdel : String, col : String, lic : String, minParked : int) + ParkedCar(car2 : ParkedCar) Â setter and getter methods, and the toString method, not shown |
Â
Â
Â
Â
Â
Â
The ParkingMeterclass is meant to hold information about the number of minutes of parking time that have been purchased.
Â
|
ParkingMeter |
|
- minutesPurchased : int |
|
+ ParkingMeter(numMinPurchased : int) Â setter and getter methods, and the toString method, not shown |
Â
The PoliceOfficerclass holds data about the name and badge number of an officer. It has two constructors; the first is a constructor that takes as input two arguments, and a second that is a copy constructor. The class method patrol looks at the number of minutes a car has been parked and the number of minutes purchased. If the minutes parked are greater than the minutes purchased, a ParkingTicketobject is created and returned; otherwise patrol returns null.
Â
|
PoliceOfficer |
|
-Â name : String -Â badgeNumber : String |
|
+ PoliceOfficer(officeName : String, badgeNumber : String) + PoliceOfficer(officer : PoliceOfficer) + patrol(car : ParkedCar, meter : ParkingMeter) : ParkingTicket  setter and getter methods, and the toString method, not shown |
Â
The ParkingTicketclass is an aggregate class; it contains instance fields that are reference variables to ParkedCarand PoliceOfficerobjects. The first constructor takes three arguments, and the second is a copy constructor. The method calculateFinecalculates the amount of a parking fine, which is $25 for the first hour or part of an hour that the car is parked illegally, plus $10 for every additional hour or part of an hour that the car is illegally parked. The toStringmethod should invoke the toStringmethods of the car and officer fields, and output the fine’s details.
Â
|
ParkingTicket |
|
-Â car : ParkedCar -Â officer : PoliceOfficer -Â fine : double -Â minutes : int + BASE_FINE : double = 25.0 + HOURLY_FINE : double = 10.0 |
|
+ ParkingTicket(aCar : ParkedCar, anOfficer : PoliceOfficer, meterMins : int) + ParkingTicket(ticket : ParkingTicket) + calculateFine() : void  setter and getter methods, and the toString method, not shown |
Â
In addition to writing the four classes, write a single class, PatrolSimulation, with a main routine that demonstrates the use of the four classes. The pseudocode for the main routine is shown in the below box.
Â
|
// Create an array of 2 Car objects, with various minutesParked // values // Create an array of 2 ParkingMeter objects, with minutes so that // the first Car object is in violation, while the second is not  // Create an array of 2 ParkingTicket objects // Create a PoliceOfficer object. Give the officer a name and badge // number // Have the officer patrol each of the Car and ParkingMeter object // combinations (index i for the array of Car objects should be // matched with index i for the array of ParkingMeter objects, which // should be matched with index i of the array of ParkingTicket // objects) // After the PoliceOfficer has patrolled the cars and parking // meters, walk over the array of ParkingTickets and invoke the // toString method if a ticket has been issued, otherwise indicate // that a ticket has not been issued |
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Refer to the rubric posted on the course website for details about point accrual. A sample invocation of the program is shown below.
Â
|
Car/Parking Meter 1: Car Data Make: Volkswagen Model: 1972 Color: Red License Number: 147RHZM Minutes Parked: 121 Â Officer Data: Name: Joe Friday BadgeNumber: 4788 Â Ticket Data Minutes Illegally Parked: 61 Fine: $35.00 Â Car/Parking Meter 2: No violation |
Â
Â
Programming Task 2
               Â
Complete the fifth programming challenge, Password Verifier, on page 615 of the textbook. The UML diagram of the class is shown below.
Â
|
PasswordVerifier |
|
- MIN_PASSWORD_LENGTH : int = 6 |
|
+ isValid (str : String) : boolean -Â Â Â hasUpperCase(str : String) : boolean -Â Â Â hasLowerCase(srr : String) : boolean -Â Â Â hasDigit(str : String) : boolean |
Â
Write a class, PasswordVerifier, per the UML diagram above, and create a second class,
PasswordDemo, with a main routine to demonstrate the use of the PasswordVerifierclass.
The method isValidshould be static. Do NOT instantiate an object of type PasswordVerifier. You can have your program interact with the user via the command-line input, or by using dialogue boxes. The below two images show a (successful) invocation of the program PasswordDemo.
Â
Â
Â
Â
Â
A sample invocation of the program is shown below.
Â

Â

----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly