CIS247A Week 7 Lab The Abstract Racer Inheritance Hierarchy Program

$ 15

CIS247A Week 7 Lab The Abstract Racer Inheritance Hierarchy Program

Scenario and Summary
This week, you will be implementing inheritance by creating a generic Racer base class along with two derived classes called StreetTuner and HotRod. You will make the Racer class abstract and include the abstract method IsDead() in the Racer class.

STEP 1: Understand the UML Diagram
The UML diagram four classes defined (1) Racer, (2) Engine, (3) Hot Rod, and (4) StreetTuner classes.

The Racer class is the base parent abstract class of the Hot Rod and Street Tuner classes, which is represented by a directed line from the Hot Rod and Street Tuner classes to the Racer class and the end of the line touching the Racer class is a broad, unfilled arrow head. The racer class contains a engine object, which is represented by a directed line from the engine class to the Racer class, with a filled diamond touching the racer class, this line is labeled as a 1 to 1 relationship meaning that each racer object will contain one engine object and each engine is related to a single racer object.

The class’s attributes and methods are defined in separate class diagrams, and each class diagram is represented by a rectangular box subdivided into three vertically separated rectangular sub-sections. The top section contains the class name, the middle section contains the class attributes, and the bottom section contains the class methods.

STEP 2: Build the Inheritance Hierarchy
1. Create a project called “CIS247_WK7_Lab_LASTNAME”.
2. Build the class structure shown in the UML diagram. Remember to include properties for each class attribute.

STEP 3: Implement the Logic for the HotRod Class
1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
2. For the IsDead() method in HotRod, use the logic to implement the base class abstract IsDead method.
Hint: To generate a random number, use the following code, which returns a random number from 0 to 1:
Random rnd = new Random();
rnd.NextDouble();

Pseudocode for the IsDead method of HotRod
Random rnd = new Random();
boolean dead

if (speed > 50 && rnd.NextDouble() > 0.6)
if (engineHorsePower < 300 && blower=true)
dead = false
else
dead = true
end if
else if (speed > 100 && rnd.NextDouble() > 0.4)
if (engineHorsePower >= 300 && blower = true)
dead = true
else
dead = false
end if
else
dead = false
end if

STEP 4: Implement the logic for the StreetTurner class
1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
2. For the IsDead method in StreetTurner, use the logic below to implement the inherited abstract base class method called IsDead.

Pseudocode for the IsDead method of StreetTuner
Random rnd = new Random();
boolean dead
if (speed > 50 && rnd.NextDouble() > 0.6)
if (engineHorsePower < 300 && nitrous=true)
dead = false
else
dead = true
end if
else if (speed > 100 && rnd.NextDouble() > 0.4)
if (engineHorsePower >= 300 && nitrous = true)
dead = true
else
dead = false
end if
else
dead = false
end if

STEP5: Construct the Main Program
1. Create an array of Racer objects that will hold two Racer objects.
2. Write a method called CollectRacerInformation that accepts as an argument a Racer object, and then prompts the user to provide the following information for each racer:
a. Racer name;
b. Racer Speed;
c. Number of cylinders in the racer’s engine;
d. Horsepower of the racer’s engine; and
e. Nitrus or blower option, depending on the type of Racer object.
[Hint: In order to be able to collect all information for the derived classes as well, consider creating a base class method called ReadRacerData in the Racer class, which you will then override in the derived classes to capture the required info per class. Call the ReadRacerData method within the CollectRacerInformation method.]
3. Write a method called “DisplayRacerInformation” that accepts as an argument a Racer object, and then displays all of the information for the specific racer type.
4. Create a racer object of each type, and invoke the CollectRacerInformation passing in the Racer object. Then, store each object in the array.
5. Iterate through the Racer array list and, for each Racer, display all of the Racer’s attribute information (call the DisplayRacerInformation method for each object). Don’t forget to indicate whether or not the Racer is dead!

STEP 6: Compile and Test
When done, compile and run your program.
Then, debug any errors until your code is error-free.
Check your output to ensure that you have the desired output and modify your code as necessary and rebuild. Your code may resemble the following:

Welcome the Abstract RAcer Inheritance Hierarchy Program
CIS247, Week 7 Lab
Name: Solution
This Program test an Anstract Racer Inheritance hierarchy
**************** Collecting Racer’s Basic Data ****************
Enter racer’s name: Fast One
Enter racer’s speed: 345
Enter number of cylinders in racer’s engine: 20
Enter horsepower of racer’s engine: 250
Enter nitrus option (Y/N): Y
**************** Collecting Racer’s Basic Data ****************
Enter racer’s name: Lightning
Enter racer’s speed: 380
Enter number of cylinders in racer’s engine: 16
Enter horsepower or racer’s engine: 275
Enter blower option (Y/N): Y
**************** Display Racer’s Data ****************
Racer’s Name : Fast One
Racer’s Speed : 345
Engine Cylinders : 20
Engine Horsepower : 250
Racer’s Type : STREET TUNER
With Nitrus Option : Yes
Still Working? : Yes!
**************** Display Racer’s Data ****************
Racer’s Name : Lightning
Racer’s Speed : 380
Engine Cylinders : 16
Engine Horsepower : 275
Racer’s Type : HOT ROD
With Nitrus Option : Yes
Still Working? : Yes!
Thank you for using the Abstract Racer Inheritance Hierarchy

68 in stock

SKU: CIS247AILAB7 Category:

Description

CIS247A Week 7 Lab The Abstract Racer Inheritance Hierarchy Program

Scenario and Summary
This week, you will be implementing inheritance by creating a generic Racer base class along with two derived classes called StreetTuner and HotRod. You will make the Racer class abstract and include the abstract method IsDead() in the Racer class.

STEP 1: Understand the UML Diagram
The UML diagram four classes defined (1) Racer, (2) Engine, (3) Hot Rod, and (4) StreetTuner classes.

The Racer class is the base parent abstract class of the Hot Rod and Street Tuner classes, which is represented by a directed line from the Hot Rod and Street Tuner classes to the Racer class and the end of the line touching the Racer class is a broad, unfilled arrow head. The racer class contains a engine object, which is represented by a directed line from the engine class to the Racer class, with a filled diamond touching the racer class, this line is labeled as a 1 to 1 relationship meaning that each racer object will contain one engine object and each engine is related to a single racer object.

The class’s attributes and methods are defined in separate class diagrams, and each class diagram is represented by a rectangular box subdivided into three vertically separated rectangular sub-sections. The top section contains the class name, the middle section contains the class attributes, and the bottom section contains the class methods.

STEP 2: Build the Inheritance Hierarchy
1. Create a project called “CIS247_WK7_Lab_LASTNAME”.
2. Build the class structure shown in the UML diagram. Remember to include properties for each class attribute.

STEP 3: Implement the Logic for the HotRod Class
1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
2. For the IsDead() method in HotRod, use the logic to implement the base class abstract IsDead method.
Hint: To generate a random number, use the following code, which returns a random number from 0 to 1:
Random rnd = new Random();
rnd.NextDouble();

Pseudocode for the IsDead method of HotRod
Random rnd = new Random();
boolean dead

if (speed > 50 && rnd.NextDouble() > 0.6)
if (engineHorsePower < 300 && blower=true)
dead = false
else
dead = true
end if
else if (speed > 100 && rnd.NextDouble() > 0.4)
if (engineHorsePower >= 300 && blower = true)
dead = true
else
dead = false
end if
else
dead = false
end if

STEP 4: Implement the logic for the StreetTurner class
1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
2. For the IsDead method in StreetTurner, use the logic below to implement the inherited abstract base class method called IsDead.

Pseudocode for the IsDead method of StreetTuner
Random rnd = new Random();
boolean dead
if (speed > 50 && rnd.NextDouble() > 0.6)
if (engineHorsePower < 300 && nitrous=true)
dead = false
else
dead = true
end if
else if (speed > 100 && rnd.NextDouble() > 0.4)
if (engineHorsePower >= 300 && nitrous = true)
dead = true
else
dead = false
end if
else
dead = false
end if

STEP5: Construct the Main Program
1. Create an array of Racer objects that will hold two Racer objects.
2. Write a method called CollectRacerInformation that accepts as an argument a Racer object, and then prompts the user to provide the following information for each racer:
a. Racer name;
b. Racer Speed;
c. Number of cylinders in the racer’s engine;
d. Horsepower of the racer’s engine; and
e. Nitrus or blower option, depending on the type of Racer object.
[Hint: In order to be able to collect all information for the derived classes as well, consider creating a base class method called ReadRacerData in the Racer class, which you will then override in the derived classes to capture the required info per class. Call the ReadRacerData method within the CollectRacerInformation method.]
3. Write a method called “DisplayRacerInformation” that accepts as an argument a Racer object, and then displays all of the information for the specific racer type.
4. Create a racer object of each type, and invoke the CollectRacerInformation passing in the Racer object. Then, store each object in the array.
5. Iterate through the Racer array list and, for each Racer, display all of the Racer’s attribute information (call the DisplayRacerInformation method for each object). Don’t forget to indicate whether or not the Racer is dead!

STEP 6: Compile and Test
When done, compile and run your program.
Then, debug any errors until your code is error-free.
Check your output to ensure that you have the desired output and modify your code as necessary and rebuild. Your code may resemble the following:

Welcome the Abstract RAcer Inheritance Hierarchy Program
CIS247, Week 7 Lab
Name: Solution
This Program test an Anstract Racer Inheritance hierarchy
**************** Collecting Racer’s Basic Data ****************
Enter racer’s name: Fast One
Enter racer’s speed: 345
Enter number of cylinders in racer’s engine: 20
Enter horsepower of racer’s engine: 250
Enter nitrus option (Y/N): Y
**************** Collecting Racer’s Basic Data ****************
Enter racer’s name: Lightning
Enter racer’s speed: 380
Enter number of cylinders in racer’s engine: 16
Enter horsepower or racer’s engine: 275
Enter blower option (Y/N): Y
**************** Display Racer’s Data ****************
Racer’s Name : Fast One
Racer’s Speed : 345
Engine Cylinders : 20
Engine Horsepower : 250
Racer’s Type : STREET TUNER
With Nitrus Option : Yes
Still Working? : Yes!
**************** Display Racer’s Data ****************
Racer’s Name : Lightning
Racer’s Speed : 380
Engine Cylinders : 16
Engine Horsepower : 275
Racer’s Type : HOT ROD
With Nitrus Option : Yes
Still Working? : Yes!
Thank you for using the Abstract Racer Inheritance Hierarchy

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.