Question: Create PHP classes ParkingInvoice and Car, which are used in a paid parking lot. Class Car contains one private property: licensePlate. It also has a
Create PHP classes ParkingInvoice and Car, which are used in a paid parking lot. Class Car contains one private property: licensePlate. It also has a parameterized constructor that initializes the license plate, as well as a getter method for this property.
Class ParkingInvoice contains a private Car reference and private properties hours and hourlyCharge. It has a parameterized constructor that initializes the Car and the two other properties. For hours and hourlyCharge, it checks for non-negative values, else they are initialised to zero. It also has getters for car and the two properties, as well as a setter for hourlyCharge. Also, ParkingInvoice contains method findCharge(), which returns the total parking charge.
Test both classes in a PHP script that creates an array of several ParkingInvoices with different Cars. Then, in a loop it displays all invoices in the array in an unordered list, where for each invoice is displayed the string Charge for (licence plate) is (charge).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
