Question: Purpose: This assignment explores the use of composition ( HAS - A ) and inheritance as relationships between classes In this assignment you will use
Purpose: This assignment explores the use of composition HASA and inheritance as relationships between classes
In this assignment you will use what you have learned through Chapter to design and implement a simple class hierarchy for computer makeup. The hierarchy will consist of several abstract and concrete classes. At the top of the hierarchy is the abstract base class Computer. It will contain the Manufacturer and CPU for the Computer. This will be done via composition with the CPU class. Each CPU consists of a Manufacturer, a model, a clock speed, socket, and power draw. Each Computer will also support a CalcTDP method that will return the total power draw of all components. Derived from Computer are two classes, Laptop and Desktop. Laptops will have a fixed TDP as specified by the manufacturer as with few exceptions laptop boards are soldered together, and other components are not swappable The Desktop class and others will be developed in the next assignment. Follow the naming, return types, and parameter lists specified below carefully. You may include privateprotected helper methodsproperties but no additional public methods or properties may be added without agreement from your instructor.
CPU public concrete class
Constructor that specifies the manufacturer a string model a string clock speed an int socket a string and power draw an integer in this order.
Overloaded constructor with same parameters as above EXCEPT manufacturer. So model a string clock speed an int socket a string and power draw an integer in this order. Manufacturer should be set to an empty string in this scenario.
Get and set property for each of the data fields. Use the following property names: Manufacturer, Model, ClockSpeed, Socket, and PowerDraw. Ensure that Manufacturer, Model, Socket are not be null or empty even after the value has been trimmed to remove leading and trailing whitespace. String methods IsNullOrEmpty, or better still IsNullOrWhiteSpace, and Trim will be helpful. Ensure that the numeric fields are non negative. If any of the values received are invalid, throw an ArgumentOutOfRangeException with an appropriate error message as shown in the text.
ToString method that will return all the data fields as a formatted String consisting of four lines, in the format below:
Intel ik
Clock Speed: MHz
Socket:
Power Draw: Watt
Computer public abstract class
Constructor that specifies the Manufacturer and CPU as a CPU object
Get and set property for each of the data fields. Use the following names: Manufacturer and CPU. Ensure that neither is set to a null value. If so throw an ArgumentOutOfRangeException with an appropriate error message as shown in the text.
Abstract CalcTDP method no parameters that returns the given total power draw TDP as an integer.
ToString method that will return the all the values of the data fields as a formatted String.
Laptop public concrete class derived from Computer
Constructor that specifies the Manufacturer, the Laptop Model, the CPU, and the fixed TDP nonnegative integer in Watts. The usage will differ laptop to laptop, but will not vary by components as it is standard per laptop model. To be clear, you may create a private or protected property to store and validate the the fixed TDP but there is no such property in the public specifications of this class and, as such, no public property may be added. The value is set via the constructor and may not be modified after a Laptop object has been constructed.
Add a Property for LaptopModel, which will not have been present in parent class Computer.
Override the CalcTDP method to return the fixed TDP specified in constructor. Again, you may create a private or protected property to store and validate the TDP but there is no such property in the public specifications of this class and, as such, no public property may be added.
Override the ToString method as needed to return the all the values of the data fields as a formatted String.
Note, there is no public property for the fixed cost in these specs. If you wish to have a property for this, use a different visibility modifier private or protected, perhaps You can use a public method CalcTDP to return the Fixed TDP
In addition to the classes described above, you will need to create a simple console application to test your Laptops and CPUs. In your application file where the Main method is located construct at least Laptop objects you may hard code your test data using as least CPU objects. Add your Laptop objects to a List of Computer objects List using the List class introduced in Chapter and used previously in CIS Print all the Computers and associated information to the console. Include other statements as necessary to test the properties included in the classes.
Be sure to add appropriate comments in your code for each file,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
