0% found this document useful (0 votes)
75 views

NeedForSpeed - Exam

The document describes an object-oriented program for managing cars and races. It defines classes for cars, races, and a garage. The main class CarManager handles registration, checking details, opening races, adding participants, starting races, parking/unparking cars, and tuning. Races are won based on performance points calculated from car attributes. The program takes commands and outputs details and results.

Uploaded by

Tấn Phong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

NeedForSpeed - Exam

The document describes an object-oriented program for managing cars and races. It defines classes for cars, races, and a garage. The main class CarManager handles registration, checking details, opening races, adding participants, starting races, parking/unparking cars, and tuning. Races are won based on performance points calculated from car attributes. The program takes commands and outputs details and results.

Uploaded by

Tấn Phong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

C# OOP Basics Exam Preparation I –

Need For Speed


Task I : Structure
The main structure of the program should include the following elements:

Cars
A basic car has the following properties: a brand (string), a model (string), an yearOfProduction (int), horsepower
(int), acceleration (int), suspension (int), and durability (int).
Each different type of car adds to those properties. Here are the types:
 PerformanceCar – a car made for racing. Might be a little ugly, but it is a rocket inside.
o Has addOns (Collection of strings). (by default – empty)
o Increases its given horsepower by 50%.
o Decreases its given suspension by 25%.
 ShowCar – a car made for showing off. Looking cool out there, bro.
o Has stars (int). (by default – 0)

Races
The basic race has the following properties: length (int), route (string), a prizePool (int), and participants (Collection
of Cars),
 CasualRace – just a normal race. Several beasts’ warfare, spreading their roars throughout the roads.
 DragRace – a drag race. An engine fray. The ideal gear shifting will be the winner in this.
 DriftRace – a drift race. Don’t you wish your girlfriend was drifty like me.

Garage
 Garage – The Garage is that place where all the cars stay, when they are not racing. The Garage also
provides the ability to modify parked car
o Has parkedCars (Collection of Cars).

Constructors
Implement all class constructors, with the parameters in the EXACT given order and the EXACT given types.

String Representation
Implement ToString() methods for every Car class. You can see the requirements in the Output Section below.

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 1 of 7


Task II: Business Logic
The Controller Class
The business logic of the program should be concentrated around several commands. Implement a class called
CarManager, which will hold the main functionality, represented by these methods:
 void Register(int id, string type, string brand, string model, int
yearOfProduction, int horsepower, int acceleration, int suspension, int
durability)
 string Check(int id)
 void Open(int id, string type, int length, string route, int prizePool)

 void Participate(int carId, int raceId)


 string Start(int id)

 void Park(int id)


 void Unpark(int id)

 void Tune(int tuneIndex, string addOn)

Commands
The commands in the CarManager class should represent the functionality to the input commands of the user. Here
are the input commands you need to accept from the user input.
 register {id} {type} {brand} {model} {year} {horsepower} {acceleration} {suspension} {durability}
o REGISTERS a car of the given type, with the given id, and the given stats.
o The car type will be either “Performance” or “Show”.
 check {id}
o CHECKS details about the car with the given id.
o RETURNS a string representation of the car.
 open {id} {type} {length} {route} {prizePool}
o OPENS a race of the given type, with the given id, and stats.
o The race type will be either “Casual”, “Drag” or “Drift”.
 participate {carId} {raceId}
o ADDS a car as a participant in the given race.
o Once added, a car CANNOT turn down a race or be REMOVED from it.
 start {raceId}
o INITIATES the race with the given id.
o RETURNS detailed information about the race result.
 park {carId}
o PARKS a car by a given id in the garage.
 unpark {carId}
o UNPARKS the car with the given id from the garage.
 tune {tuneIndex} {tuneAddOn}
o Tunes the currently parked CARS with the given index and the given add-on.
o You should increase a car’s horsepower by the given index, and the suspension, by HALF of the
given index.

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 2 of 7


– 150 tuneIndex = 150 increase in the horsepower and 75 increase in suspension.

o If the car is a ShowCar it should increase its stars by the given tuneIndex.
o Upon tuning, a PerformanceCar adds the given add-on to its collection of add-ons.

Functionality
Cars and Races are the main entities in the program’s functionality. They have no suitable way to be ACCESSED,
which is why, upon registration, they are given an Id. The Id will be a simple integer. There is NO need for Cars and
Races to know their Ids. The CarManager is the one that controls the main logic, which is why it is the only class
which needs to know of every car and race’s id.
When you register a car, you store it in such a way, so that you can access it by id. You can then make the car
participate in a race, or select it in the garage. There are several RULES that you must follow:
1. Once a car has been ADDED as a participant in a race, it CANNOT be PARKED in the garage, UNTIL the race
is OVER.
o IGNORE any attempt to park a racer car.
2. A car, which has been PARKED in the garage, CANNOT participate in a race.
o IGNORE any attempt to include a parked car in a race.
3. IGNORE any attempt to TUNE cars, when there are NO PARKED cars in the garage.
4. SINGLE car CAN participate in MANY races.
5. A race CANNOT start without ANY participants.
6. A race CAN start with LESS than three participants.
Performance points (PP) determine every race’s winners. PP are either Overall Performance, Engine Performance
or Suspension Performance. Here are the different formulas:
 A CasualRace determines its winners based on their Overall Performance (OP) (in DESCENDING order).
Overall Performance, of EACH CAR, is calculated by the following formula:
(horsepower / acceleration) + (suspension + durability)

 A DragRace determines its winners based on their Engine Performance (EP) (in DESCENDING order).
Engine Performance, of EACH CAR, is calculated by the following formula:
(horsepower / acceleration)

 A DriftRace determines its winners based on their Suspension Performance (SP) (in DESCENDING order).
Suspension Performance, of EACH CAR, is calculated by the following formula:
(suspension + durability)
Depending on the different TYPE of RACE, different type of POINTS are calculated for the racers. In the end all
points are presented as Performance Points (in the OUTPUT).
When you OPEN a race, you register it – this provides the functionality to add participants to it.
When you START a race, the winners are calculated immediately, PRINTED as output, and the race becomes CLOSED
(you CANNOT add any more participants in it, and you CANNOT start it again).

If TWO cars have the SAME result, participant registered before the other comes FIRST.
The 1st place winner takes 50 % of the race’s prize pool.
The 2nd place winner takes 30 % of the race’s prize pool.

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 3 of 7


The 3rd place winner takes 20 % of the race’s prize pool.
You need to take in account ONLY the FIRST 3 players, AFTER you’ve ordered them in descending order, by the
corresponding criteria.
In case a race has LESS than 3 participants, you should print only them, as winners. The prizes remain the SAME.
In case a race has NO participants, you should print “Cannot start the race with zero participants.”, and IGNORE the
command.

Task III: I / O (Input / Output)


Input
 The input will come in the form of commands, in the format specified above.
 The input sequence ends when you receive the command “Cops Are Here”.

Output
Two elements generate output in the program’s functionality:
 The “check” command should RETURN a String representation of the CAR with the GIVEN ID:
o “{brand} {model} {yearOfProduction}
o {horsepower} HP, 100 m/h in {acceleration} s
o {suspension} Suspension force, {durability} Durability”

o If the car is a PerformanceCar, you must print “Add-ons: {add-ons}”, on the last line – each
add-on separated by a comma and a space “, “. In case there are NO add-ons, print “None”.
o If the car is a ShowCar, you must print “{stars} *”, on the last line.
 The “start” command should RETURN a String representation the RACE with the GIVEN ID:
o “{route} - {length}
o 1. {brand} {model} {performancePoints}PP - ${moneyWon}
o 2. {brand} {model} {performancePoints}PP - ${moneyWon}
o 3. {brand} {model} {performancePoints}PP - ${moneyWon}”

o 1, 2 and 3 – being the 1st, 2nd and 3rd participants (the winners).
o If there are LESS than 3 participants, print as much as there are.
o In case there are NO participants, print “Cannot start the race with zero participants.”, and IGNORE
the command.

Constrains
 All integers in the input will be in range [0, 100000].
 All strings in the input may consist of any ASCII character, except SPACE
o So that the input is easily processed.
 There will be NO invalid input lines, or invalid (non-existent) Ids.
 Note that throughout the program, you are working ONLY with INTEGERS.
o Each mathematical or logical action performed on numeric data, should be performed between
INTEGERS.
 Note: 50% of X is EQUAL to (X * 50) / 100.
 Note: Decrease means DECREASE… 100 decreased by 25% = 100 – (100 * 25) / 100 = 100 – 25 = 75.

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 4 of 7


Examples
Input Output
register 1 Performance BMV M92 2013 300 4 150 75 Trabant 601 1988
register 2 Show Maserati Levante 2015 400 6 250 100 3000 HP, 100 m/h in 1 s
register 3 Performance Nissan GT-R 2017 550 4 300 100 7500 Suspension force, 1000
register 4 Performance McLaren P1 2016 650 2 400 200 Durability
register 5 Performance Trabant 601 1988 2000 1 10000 1000 Add-ons: None
open 1 Drag 10 BeverlyHills 50000 BeverlyHills - 10
open 3 Casual 20 NewYork 100000 1. Trabant 601 3000PP - $25000
participate 1 1 2. McLaren P1 487PP - $15000
participate 2 1 3. Nissan GT-R 206PP - $10000
participate 3 1 NewYork - 20
participate 4 1 1. Trabant 601 11500PP - $50000
participate 5 1 2. McLaren P1 987PP - $30000
participate 1 3 3. Nissan GT-R 531PP - $20000
participate 2 3
participate 3 3
participate 4 3
participate 5 3
check 5
start 1
start 3
Cops Are Here
register 3 Show Porsche Carrera 2017 550 4 300 100 Washington - 14
register 4 Performance McLaren P1 2016 650 2 400 200 1. Trabant 601 3000PP - $50000
register 5 Performance Trabant 601 1988 2000 1 10000 1000 Porsche Carrera 2017
open 1 Casual 20 Manhattan 100000 850 HP, 100 m/h in 4 s
open 2 Drag 14 Washington 100000 450 Suspension force, 100
participate 5 1 Durability
participate 5 2 300 *
park 3 McLaren P1 2016
park 4 1275 HP, 100 m/h in 2 s
park 5 450 Suspension force, 200
start 2 Durability
tune 150 Turbo Add-ons: Turbo, Nitrous, Tires
tune 100 Nitrous Manhattan - 20
tune 50 Tires 1. Trabant 601 11500PP - $50000
participate 3 1 2. McLaren P1 1287PP - $30000
check 3
check 4
unpark 4
participate 4 1
start 1
Cops Are Here

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 5 of 7


Task IV: Bonus
The modern racers like different types of races. If you are really good at writing software, then your employers
would like to hire you for some more work.
Your task is to implement classes for 2 extra SPECIAL races:
 TimeLimitRace
o Is INITIALIZED with an EXTRA PARAMETER – goldTime (int).

 CircuitRace
o Is INITIALIZED with an EXTRA PARAMETER – laps (int).

Both races, have an extra parameter, aside from the normal races. The parameter is received, from the user input
as last parameter, when OPENING one of these types of races.

Logic
The TimeLimitRace can only have 1 participant. ANY attempt to add more participants to it should be IGNORED.
The participant has a Time Performance (TP), which is calculated by the following formula:
raceLength * ((participantHorsepower / 100) * participantAcceleration)
Depending on the Time Performance, the player earns “Gold”, “Silver” or “Bronze” time:
 TP <= raceGoldTime – Racer has earned Gold Time and earns 100% of the prizePool.
 TP <= raceGoldTime + 15 – Racer has earned Silver Time and earns 50% of the prizePool.
 TP > raceGoldTime + 15 – Racer has earned Bronze Time and earns 30% of the prizePool.
The String representation of the TimeLimitRace is in the following format:
 “{route} – {length}

 {participantBrand} {participantModel} – {participantTimePerformance} s.


 {participantEarnedTime} Time, ${wonPrize}.”

The CircuitRace is almost like a normal race, with the difference that it has laps and 4 winners in total. The
winners are determined by Overall Performance (OP) like in CasualRace.
 1st place earns 40% of the prizePool.
 2nd place earns 30% of the prizePool.
 3rd place earns 20% of the prizePool.
 4th place earns 10% of the prizePool.
The special thing about this race is … That EVERY lap DECREASES the DURABILITY of EACH participant by (length *
length). The String representation of the CircuitRace is in the following format:
 “{route} - {length * laps}
 1. {brand} {model} {performancePoints}PP - ${moneyWon}

 2. {brand} {model} {performancePoints}PP - ${moneyWon}


 3. {brand} {model} {performancePoints}PP - ${moneyWon}

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 6 of 7


 4. {brand} {model} {performancePoints}PP - ${moneyWon}”

Examples
Input Output
register 1 Performance Mitsubishi Lancer-Evo 2010 400 SofiaStreets - 50
5 200 100 1. Lamborghini Aventador 925PP -
register 2 Performance Nissan Z370 2012 500 4 300 200 $40000
register 3 Show BMW i8-Spyder 2016 600 3 400 300 2. Ford Mustang-Shelby 480PP -
register 4 Performance Lamborghini Aventador 2017 1000 $30000
2 500 300 3. BMW i8-Spyder 400PP - $20000
register 5 Show Ford Mustang-Shelby 1970 400 5 700 200 4. Nissan Z370 112PP - $10000
open 1 Circuit 10 SofiaStreets 100000 5 Mitsubishi Lancer-Evo 2010
open 2 Circuit 2 SofiaAirport 10000 2 600 HP, 100 m/h in 5 s
participate 1 1 150 Suspension force, -400
participate 2 1 Durability
participate 3 1 Add-ons: None
participate 4 1 Nissan Z370 2012
participate 5 1 750 HP, 100 m/h in 4 s
start 1 225 Suspension force, -300
check 1 Durability
check 2 Add-ons: None
check 3 BMW i8-Spyder 2016
check 4 600 HP, 100 m/h in 3 s
check 5 400 Suspension force, -200
Cops Are Here Durability
0 *
Lamborghini Aventador 2017
1500 HP, 100 m/h in 2 s
375 Suspension force, -200
Durability
Add-ons: None
Ford Mustang-Shelby 1970
400 HP, 100 m/h in 5 s
700 Suspension force, -300
Durability
0 *
register 1 Performance Mitsubishi Lancer-Evo 2010 400 Cannot start the race with zero
5 200 100 participants.
register 4 Performance Lamborghini Aventador 2017 1000 SofiaAirport - 5
2 500 300 Lamborghini Aventador - 250 s.
park 4 Gold Time, $100000.
tune 1000 Turbo Malibu - 5
unpark 4 Lamborghini Aventador - 250 s.
open 1 TimeLimit 5 SofiaAirport 100000 260 Silver Time, $5000.
open 2 TimeLimit 5 Malibu 10000 240
start 1
participate 4 1
participate 1 1
participate 4 2
start 1
start 2
Cops Are Here

© Software University Foundation (softuni.org). This work is licensed under the CC-BY-NC-SA license.

Follow us: Page 7 of 7

You might also like