Home Page > > Details

954246 ProgrammingDebug ,Help With Programming Programming,C++ Programming R Programming| Web

Practice 954246 01/2563 Lab 12 Object-Oriented Programming 2
1/5
Lab 12 Object-Oriented Programming 2
Note: The underlined text is an input data.
1. Create class Bus stored in file Bus.php that extends class Car from full example of lecture.
Class Bus can load the passengers intoit byusing method load($number_of_passenger)
and unload the passengers by using method unload($number_of_passenger) then the
fuel used can be calculated per passenger run from the following formula. Moreover, each
Bus has its own capacity (maximum number of passengers) setting by constructor.
𝑓𝑒𝑒𝑙 𝑒𝑠𝑒𝑑 π‘π‘’π‘Ÿ π‘π‘Žπ‘ π‘ π‘’π‘›π‘”π‘’π‘Ÿ π‘Ÿπ‘’π‘› (𝐿) =
π‘π‘Žπ‘ π‘ π‘’π‘›π‘”π‘’π‘Ÿ π‘‘π‘–π‘ π‘‘π‘Žπ‘›π‘π‘’ (π‘˜π‘š)
120
Γ—
π‘π‘–π‘ π‘‘π‘œπ‘› π‘£π‘œπ‘™π‘’π‘šπ‘’ (𝑐𝑐)
1000
+
70 Γ— π‘›π‘’π‘šπ‘π‘’π‘Ÿ π‘œπ‘“ π‘π‘Žπ‘ π‘ π‘’π‘›π‘”π‘’π‘Ÿπ‘  Γ— π‘π‘Žπ‘ π‘ π‘’π‘›π‘”π‘’π‘Ÿ π‘‘π‘–π‘ π‘‘π‘Žπ‘›π‘π‘’ (π‘˜π‘š)
10000
Remark: Beware, the number of passengers can be changed over time so you must have
property to keep fuel used, calculating fuel used on showing is not correct.
The method showLongInfo() will print out the following format, same as Car but extends
with number of current passenger.
Owner: owner
Running distance: dist km
Fuel used: fuel L
Current passenger: number_of_passengers
Then write the program that waits for inputting owner name,piston volume and capacity then
wait for the following command.
0 stop engine
1 start engine
r run for the given km
+ load the given number of passengers into bus
- unload the given number of passengers out of bus
i show information (engine is off only)
e exit
h print this help
Practice 954246 01/2563 Lab 12 Object-Oriented Programming 2
2/5
If the number of passengers greater than capacity it will print out the following message to
STDERR then return false, in method load().
Number of passengers greater than capacity!!!
If the number of passengers lessthan 0 it will print out the following message to STDERR then
return false, in method unload().
Number of passengers less than 0!!!
Example 01: php ass-01.php
Input (owner cc capacity): Stieve 30000 40
command (h for help): h
0 stop engine
1 start engine
r run for the given km
+ load the given number of passengers into bus
- unload the given number of passengers out of bus
i show information (engine is off only)
e exit
h print this help
command (h for help): r 50
Cannot run, engine is off!!!
command (h for help): 1
command (h for help): r 200
command (h for help): - 20
Number of passengers less than 0!!!
command (h for help): + 30
command (h for help): r 1000
command (h for help): + 20
Number of passengers greater than capacity!!!
command (h for help): r 500
command (h for help): - 10
command (h for help): r 500
command (h for help): + 20
command (h for help): r 1000
command (h for help): - 30
command (h for help): i
Cannot show, engine is on!!!
command (h for help): 0
command (h for help): i
Owner: Stieve
Running distance: 3,200 km
Fuel used: 1,465.00 L
Current passengers: 10
command (h for help): e
Practice 954246 01/2563 Lab 12 Object-Oriented Programming 2
3/5
2. Create class Pet stored in file Pet.php that implements interface Runnable and ShowInfo
and class PetLover stored in file PetLover.php that extends class Person and implements
interface ShowInfo from full example of lecture.
Class Pet consist of the following members.
β€’ $name: assigned by constructor.
β€’ $distance: accumulateddistance from method runFor().
β€’ getName():get the pet name.
β€’ showInfo(): print out the following format.
Name: pet_name
β€’ showLongInfo(): print out the following format.
Name: pet_name
Running distance: dist km
Class PetLover consist of the following members (extends from parentclass).
β€’ takePet(Pet $pet): take an instance of Pet with his/her.
β€’ releasePet(Pet $pet): will releasethe given instance of Pet from takenpets.
β€’ showInfo(): print out the following format, same as .
Name: pet_lover_name
β€’ showLongInfo(): print out the following format.
Name: pet_lover_name
Running distance: dist km
Current taken pets: pet1_name, pet2_name, ...
Remark: PetLover can take more than one pet on the same time.
If PetLover do runFor() all taken pets will runFor() together so you must
override method runFor() in class PetLover.
All pets always have the difference name.
You can use === to check for the same object.
Practice 954246 01/2563 Lab 12 Object-Oriented Programming 2
4/5
Write the program that reads the input file with the followingformat.
pet_lover_name
number_of_pets
pet1_name
pet2_name
...
number_of_command
command1 value1
command2 value2
...
The commands consist of:
t take the given pet name
re release the given pat name
r pet lover run for the given km
Example Input: ass-02-input.txt
Beware that command can take pet that already taken or can release non-taken pet and those
command is no effect. After all commands have been executed then show information from
showLongInfo() for pet lover and all pets.

Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Β© 2021 www.asgnhelp.com
Programming Assignment Help!