Lebanese University
Faculty of Sciences – section 5
I2211 – Object Oriented Programming
Exercise 3
Consider the following UML diagram:
1. Implement the interface Alternative.
2. Implement the abstract class Device. Note the following:
• The price is expressed in dollars and its values should be strictly greater than zero.
• The toString method returns a String of the form “Brand: …. Price: …. dollars”.
3. Implement the class Computer. The “type” attribute indicates whether the computer is a desktop,
laptop, workstation, etc. Note that two computers are alternatives if they have the same type and the
same cpu.
4. Implement the class USB. Two USB are alternatives if they have the save storage amount.
5. Implement the class TechShop.
6. Assume having a test class with a main method that creates a TechShop called “Modern Tech”:
public static void main(String[] args) {
TechShop tShop = new TechShop("Modern Tech");
// We added many devices to tShop …..
Computer computer1 = new Computer("laptop", "core i7", "hp", 650);
...
}
Assume that we added many devices to the TechShop (tShop object). Complete the main method in
order to display all the computers in the tShop that could be alternative to computer1 (object already
created in the main method above).
Page 1/1