Create a pricing system for a computer company that sells personal computers over the Internet. There are two kinds of computers, laptops and desktops. Each computer has a processor (1.8. 2.0, 2.5, or 3.0 gigahertz), memory (2, 3 or 4 Gb), hard drive (160, 250, or 500 Gb), and optical drive ("CD-RW", "DVD" or "Blu-ray Combo Drive"). Laptops have 14-, 15- or 17-inch screens. Desktops have 17-, 19-, or 24-inch monitors.
You should have an abstract class Computer and final subclasses LapTop and DeskTop. The 'Computer' class should have set and get methods to modify and retrieve the values of its instance variables (processorSpeed, memorySize, hardDriveSize, and opticalDriveType, and both the 'LapTop' and 'DeskTop' classes should have sets and gets for its only instance variable, the displaySize field. Include validation coding in all the set methods based upon the field values given in the previous paragraph. Since all computers must have all components, establish a default value for each component, i.e. zero (0) or an empty String, meaning that no valid value currently exists for that component. The constructor methods of all three classes should take parameters for initializing all instance variables; additionally the subclass constructors should pass related parameters to the superclass constructor.
Each subclass should have a public method named getComputerPrice(), that calculates and returns a double which is the price of a computer given the base price (different for a laptop or a desktop) plus the cost of the different options (i.e. Price = Base price + Processor price + Memory price + Hard drive price + Optical drive price + Display price). Create an abstract method in the 'Computer' class requiring that this get method be implemented in the two subclasses. Additionally in the 'Computer' class declare abstract prototypes for the setDisplaySize() and getDisplaySize() methods for the display size attribute. (The abstract definitions for the two get methods effectively gives the superclass 'Computer' access to the methods in its subclasses).
Write a single toString() method situated in the 'Computer' class that returns the specifications for each computer object (processor speed, memory size, hard drive size, optical drive type, and display size) with appropriate labeling for readability, plus the computer price which is returned from the getComputerPrice() method of either the LapTop or Desktop subclass (implements late binding).
Declare constants in an interface file named ComputerPricing for the pricing of each of these options as well as the base prices for laptops and desktops Pricing is the same for both laptop and desktop computer components (for example a 1.8 gigahertz processor is the same price whether it is a for laptop or a desktop). The constants for the components may be defined using either of the following:
1. A single constant for every one of the individual component elements, in addition to the base prices for 'Laptop' and 'Desktop' (requires a total of 21 constants), i.e. constants for PROCESSOR_PRICE_1_8, PROCESSOR_PRICE_2_0, and so forth, and including LAPTOP_BASE_PRICE and DESKTOP_BASE_PRICE; using this approach will require a series of If ... Else If statements in the getComputerPrice() method to retrieve the price of each component from the interface and calculate the total computer price.
2. Parallel arrays for each of the components that store all values for the component, i.e. double[] PROCESSOR_SPEED and int[] PROCESSOR_PRICE for the processor; there should be two separate parallel array sets for 'Laptop' and 'Desktop' display prices; this approach will allow for a series of array searches in the getComputerPrice() methods to retrieve the price of each component from the interface and calculate the total computer price; as an additional benefit if you implement this arrays approach, you can use the arrays for the component size and speed values in the set methods thereby eliminating any hardcoded data in the abstract super and final sub classes.
Write a test (driver) class that instantiates objects from the 'LapTop' and 'DeskTop' classes, and which directly or indirectly demonstrates all the set, get and toString() methods of all classes. This test application should instantiate multiple objects of both subclasses, some with valid and some with invalid argument values passed to the constructors. For 10% extra credit, implement downcasting in the driver class by instantiating an array of 'Computer' objects and displaying them as a collection.
This is what i've achieved so far in the Computer abstract class:
public abstract class Computer extends Object
{
private String processorSpeed;
private String memorySize;
private String hardDriveSize;
private String opticalDriveSize;
public Computer(String processorSpeed, String memorySize, String hardDriveSize, String opticalDriveSize)
{
setComputer(processorSpeed, memorySize, hardDriveSize, opticalDriveSize);
}
public void setComputer(String processorSpeed, String memorySize,
String hardDriveSize, String opticalDriveSize)
{
setProcessorSpeed(processorSpeed);
setMemorySize(memorySize);
setHardDriveSize(hardDriveSize);
setOpticalDriveSize(opticalDriveSize);
}
public void setProcessorSpeed(String processorSpeed)
{
String[] validProcessorSpeed = {"1.8", "2.0", "2.5", "3.0"};
int index;
for (index = 0;
index < 4 && ! processorSpeed.equalsIgnoreCase(validProcessorSpeed[index]);
index ++);
if (index < 8)
{
this.processorSpeed = validProcessorSpeed[index];
}
else
{
JOptionPane.showMessageDialog(null, grade + "not a valid processor speed--set to null string");
this.processorSpeed = null;
}
public void setMemorySize(String memorySize)
{
}
public void setHardDriveSize(String hardDriveSize)
{
}
public void setOpticalDriveSize(String opticalDriveSize)
{
}
}
If you guys have any advice for me at all while I'm working on this project, it would be very helpful. I'll keep you guys updated on my code, throughout the day. Because I will be working on this all day.

New Topic/Question
Reply



MultiQuote






|