Advertisement
akosiraff

Download CIS247A Week 7 Lab The Abstract Racer Inheritance H

Jun 20th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/cis247a-week-7-lab-the-abstract-racer-inheritance-hierarchy-program/
  3. CIS247A Week 7 Lab The Abstract Racer Inheritance Hierarchy Program
  4. Scenario and Summary
  5. 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.
  6. STEP 1: Understand the UML Diagram
  7. The UML diagram four classes defined (1) Racer, (2) Engine, (3) Hot Rod, and (4) StreetTuner classes.
  8. 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.
  9. 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.
  10. STEP 2: Build the Inheritance Hierarchy
  11. 1. Create a project called “CIS247_WK7_Lab_LASTNAME”.
  12. 2. Build the class structure shown in the UML diagram. Remember to include properties for each class attribute.
  13. STEP 3: Implement the Logic for the HotRod Class
  14. 1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
  15. 2. For the IsDead() method in HotRod, use the logic to implement the base class abstract IsDead method.
  16. Hint: To generate a random number, use the following code, which returns a random number from 0 to 1:
  17. Random rnd = new Random();
  18. rnd.NextDouble();
  19. Pseudocode for the IsDead method of HotRod
  20. Random rnd = new Random();
  21. boolean dead
  22. if (speed > 50 && rnd.NextDouble() > 0.6)
  23. if (engineHorsePower < 300 && blower=true) dead = false else dead = true end if else if (speed > 100 && rnd.NextDouble() > 0.4)
  24. if (engineHorsePower >= 300 && blower = true)
  25. dead = true
  26. else
  27. dead = false
  28. end if
  29. else
  30. dead = false
  31. end if
  32. STEP 4: Implement the logic for the StreetTurner class
  33. 1. Provide suitable logic for the ToString method. As always, the ToString method should reveal the state of an object.
  34. 2. For the IsDead method in StreetTurner, use the logic below to implement the inherited abstract base class method called IsDead.
  35. Pseudocode for the IsDead method of StreetTuner
  36. Random rnd = new Random();
  37. boolean dead
  38. if (speed > 50 && rnd.NextDouble() > 0.6)
  39. if (engineHorsePower < 300 && nitrous=true) dead = false else dead = true end if else if (speed > 100 && rnd.NextDouble() > 0.4)
  40. if (engineHorsePower >= 300 && nitrous = true)
  41. dead = true
  42. else
  43. dead = false
  44. end if
  45. else
  46. dead = false
  47. end if
  48. STEP5: Construct the Main Program
  49. 1. Create an array of Racer objects that will hold two Racer objects.
  50. 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:
  51. a. Racer name;
  52. b. Racer Speed;
  53. c. Number of cylinders in the racer’s engine;
  54. d. Horsepower of the racer’s engine; and
  55. e. Nitrus or blower option, depending on the type of Racer object.
  56. [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.]
  57. 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.
  58. 4. Create a racer object of each type, and invoke the CollectRacerInformation passing in the Racer object. Then, store each object in the array.
  59. 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!
  60. STEP 6: Compile and Test
  61. When done, compile and run your program.
  62. Then, debug any errors until your code is error-free.
  63. 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:
  64. Welcome the Abstract RAcer Inheritance Hierarchy Program
  65. CIS247, Week 7 Lab
  66. Name: Solution
  67. This Program test an Anstract Racer Inheritance hierarchy
  68. **************** Collecting Racer’s Basic Data ****************
  69. Enter racer’s name: Fast One
  70. Enter racer’s speed: 345
  71. Enter number of cylinders in racer’s engine: 20
  72. Enter horsepower of racer’s engine: 250
  73. Enter nitrus option (Y/N): Y
  74. **************** Collecting Racer’s Basic Data ****************
  75. Enter racer’s name: Lightning
  76. Enter racer’s speed: 380
  77. Enter number of cylinders in racer’s engine: 16
  78. Enter horsepower or racer’s engine: 275
  79. Enter blower option (Y/N): Y
  80. **************** Display Racer’s Data ****************
  81. Racer’s Name : Fast One
  82. Racer’s Speed : 345
  83. Engine Cylinders : 20
  84. Engine Horsepower : 250
  85. Racer’s Type : STREET TUNER
  86. With Nitrus Option : Yes
  87. Still Working? : Yes!
  88. **************** Display Racer’s Data ****************
  89. Racer’s Name : Lightning
  90. Racer’s Speed : 380
  91. Engine Cylinders : 16
  92. Engine Horsepower : 275
  93. Racer’s Type : HOT ROD
  94. With Nitrus Option : Yes
  95. Still Working? : Yes!
  96. Thank you for using the Abstract Racer Inheritance Hierarchy
  97.  
  98. Download: http://solutionzip.com/downloads/cis247a-week-7-lab-the-abstract-racer-inheritance-hierarchy-program/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement