Question
Assignment: Inheritance | Polymorphism Create a new Java project called 1410_InheritancePolymorphism and include a package called phones. Implementation of the UML Class Diagram Implement the
Assignment: Inheritance | Polymorphism
Create a new Java project called 1410_InheritancePolymorphism and include a package called phones.
Implementation of the UML Class Diagram
Implement the inheritance hierarchy specified in the following UML class diagram. Important: No public class members should be added, modified, or removed.
Implementation Requirements:
- Class Dimensions:
- The constructor needs to provide input validation. Only positive values are allowed for height, width, and depth. If one or more of the parameter values are zero or negative, an IllegalArgumentException should be thrown. We'll introduce exception handling in one of the upcoming modules. For now, just use the code statement provided. throw new IllegalArgumentException("The height, width, and depth of a dimension needs to be positive.");
- The method toString should return a string of the following format: ({height} x {width} x {depth}) Where {height}, {width}, and {depth} are substituted by the corresponding field values rounded to one digit after the decimal point. E.g., the dimensions 137.81 x 64 x 9.2 return: (137.8 x 64.0 x 9.2)
- Class Phone
- The method toString should return a string of the following format: {model} {dimension} Where {model} and {dimention} are substituted by the corresponding field values E.g.: Samsung Galaxy S9 (147.7 x 68.7 x 8.5)
- Class SmartPhone
- Analogous to class Dimension, the constructor needs to provide input validation. Only positive values are allowed for the field storage. If there is an attempt to create a new smartphone with an invalid storage value, an IllegalArgumentException should be thrown. This time the error message should be "Storage needs to be assigned a positive value."
- The method call should return the following string: Calling {number} by selecting the number Where {number} is substituted by the corresponding parameter value. E.g.: Calling 8015817200 by selecting the number
- The method browse should return the following string: Browsing the web
- The method takePicture should return one of the following two strings: Taking a horizontal picture or Taking a vertical picture Each time the method is called, one of those two strings should be chosen randomly.
- The method toString should return a string of the following format: {model} {dimension} {storage}GB Where {model}, {dimension} and {storage} are substituted by the corresponding field values and GB stands for gigabyte. E.g.: Samsung Galaxy S9 (147.7 x 68.7 x 8.5) 64GB
- Enum Voltage Voltage provides three options: V110, V220, and DUAL Those three options correlate to 110 Volt which is used in the US, 220 Volt like in Europe, and the ability to work with both 110 and 220 Volt
- Class DeskPhone
- The constructor includes two parameters to initialize the superclass Phone and a third parameter to initialize the field voltage. However, there is no parameter to initialize the field connected. That's because a new DeskPhone out of the box is never connected.
- The method plugIn sets the field connected to true
- The method unplug sets the field connected to false
- The method isConnected returns the value of the corresponding field
- The method toString should return a string of the following format: {model} {dimension} {voltage} {connectionInfo} Where {model}, {dimension} and {voltage} are substituted by the corresponding field values and {connectionInfo} is one of the following two strings: connected if the desk phone is connected and not connected if it is not connected. E.g.: Crosley CR62-BK (127.0 x 153.0 x 127.0) DUAL connected E.g.: Opis PushMeFon (228.0 x 217.0 x 130.0) V220 not connected
- Class RotaryPhone
- The method call should return the following string: Rotating the dial to call {number} Where {number} is substituted by the corresponding parameter value. E.g.: Rotating the dial to call 8015817200
- Class PushButtonPhone
- The method call should return the following string: Pushing buttons to call {number} Where {number} is substituted by the corresponding parameter value. E.g.: Pushing buttons to call 8015817200
JUnit Tests:
Here are five files that include JUnit tests to help you test your code. When you run the JUnit tests in the video to demonstrate the functionality of your code, the original (unmodified) test files should be used.
DeskPhoneTest.java, DimensionTest.java, PushButtonPhoneTest.java, RotaryPhoneTest.java, SmartPhoneTest.java
I have uploaded all of the code to the link below:
https://mega.nz/#!WA8znAbT!DBsnu0VponJnaOGkJfKJ5Xo7v2yGjj5D7nA9e_3NV-s
Test Client:
Add one more class to the same package. It is called TestClient and it includes the main method. Write the code described below to test the various classes and their class members.
- Create four variables that store the following objects:
- A RotaryPhone, model Model 500 with dimensions 143 x 208 x 119 and 110 Volt
- A PushButtonPhone, model Cortelco 2500 with dimensions 178 x 228 x 127 and the ability to connect both to 110 Volt and 220 Volt
- A SmartPhone, model Pixel3 with dimensions 145.6 x 68.2 x 7.9 and 128GB storage
- A SmartPhone, model iPhone8 with dimensions 138.4 x 67.3 x 7.3 and 64GB storage
- Print the title Various Phones: Call the toString methods of all four objects and print the results in separate lines. After that, print a single empty line to group related output.
- Plug in both desk phones. Then randomly select one of the desk phones and unplug it. This selection needs to be done dynamically (at runtime).
- Create an array of type Phone. Add the different phones we created above as elements to the array.
- Print the title Array Elements:
- Loop through all the elements in the array. For each of the array elements do the following:
- Call the method toString and print it.
- Make a call to the following number: 8019574111 and print the result
- If it is a SmartPhone, browse and take a picture. Print the results.
Sample Output
This sample output should give you a good idea of what is expected. Note though, that the instructions require some random selections. Because of that, your output might look slightly different. Sample Output
Various Phones: Model 500 (143.0 x 208.0 x 119.0) V110 not connected Cortelco 2500 (178.0 x 228.0 x 127.0) DUAL not connected Pixel3 (145.6 x 68.2 x 7.9) 128GB iPhone8 (138.4 x 67.3 x 7.3) 64GB Array Elements: Model 500 (143.0 x 208.0 x 119.0) V110 connected Rotating the dial to call 8019574111 Cortelco 2500 (178.0 x 228.0 x 127.0) DUAL not connected Pushing buttons to call 8019574111 Pixel3 (145.6 x 68.2 x 7.9) 128GB Calling 8019574111 by selecting the number Browsing the web Taking a vertical picture iPhone8 (138.4 x 67.3 x 7.3) 64GB Calling 8019574111 by selecting the number Browsing the web Taking a horizontal picture
Phone - model : String - dimension # Phone(model : String, dimenstion : Dimension) + call number: long): String + toString(): String Dimension - height: double - width : double - depth : double + Dimension(height : double, width: double, depth : double) + getHeight(): double + getWidth(): double + getDepth(): double + toString(): String SmartPhone - storage : int + SmartPhone(model : String, dimenstion : Dimension, storage: int) + call number: long): String + browse(): String + takePicture(): String + toString(): String DeskPhone Enum>> Voltage V110 V220 DUAL - voltage + connected : boolean # DeskPhone(model : String, dimenstion : Dimension, voltage : Voltage) + plugin() + unplug() + isConnected(): boolean + toString(): String 4. RotaryPhone Push ButtonPhone + RotaryPhone(model : String, dimenstion : Dimension, voltage : Voltage) + call number: long): String | + Push ButtonPhone(model : String, dimenstion : Dimension, voltage : Voltage) + call number: long): String Phone - model : String - dimension # Phone(model : String, dimenstion : Dimension) + call number: long): String + toString(): String Dimension - height: double - width : double - depth : double + Dimension(height : double, width: double, depth : double) + getHeight(): double + getWidth(): double + getDepth(): double + toString(): String SmartPhone - storage : int + SmartPhone(model : String, dimenstion : Dimension, storage: int) + call number: long): String + browse(): String + takePicture(): String + toString(): String DeskPhone Enum>> Voltage V110 V220 DUAL - voltage + connected : boolean # DeskPhone(model : String, dimenstion : Dimension, voltage : Voltage) + plugin() + unplug() + isConnected(): boolean + toString(): String 4. RotaryPhone Push ButtonPhone + RotaryPhone(model : String, dimenstion : Dimension, voltage : Voltage) + call number: long): String | + Push ButtonPhone(model : String, dimenstion : Dimension, voltage : Voltage) + call number: long): StringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started