Question: Modify the code from your original Desk class to create an improved version. NOTE: You will need to comment out your PAssign02 code if it
Modify the code from your original Desk class to create an improved version. NOTE: You will need to comment out your PAssign02 code if it is in the same package as PAssigno2. Otherwise, Java will give a syntax error due to duplicate class names. Update the Desk class so that all data members have proper visibility as well as accessors(getter) and mutator(setter) methods. Modify the rest of the class to use the accessors and mutator methods. Additional requirements should be enforced in mutators: desks can only have 0-8 drawers, otherwise they should be set to 4; surface height should be in the range of 24-45 inches, resetting to 27 inches if not;if the material being used is not at least 3 characters long, the material should reset to Oak; and if the manufacturing state is not at least 4 characters long, the state should reset to lowa. All methods and constructors should be given proper visibility. You may add constructors, but they must update any static members as necessary. Make sure there is a way to retrieve any static member values outside of the class. Draw/sketch the UML diagram for the Desk class and then implement the class in Java. Submit this UML diagram with your project. Write a test program that creates Desk objects with the stated values as specified in the output Collect those 5 Desk instances into an array and call the printDesks() method. The printDesks() method should accept a Desk array as a parameter and prints out the result of each Desk's getInfo() method as shown in the expected output. The printDesks() method should work for any length Desk array. Do not forget to print the total number of desks. For Desks 3, 4, 5, make sure to trigger the error checking for number of drawers, surface height, and material, respectively. HINT: Create the Desk instances first, then use the shortcut initializer to create your array. Do not attempt to use iteration when creating the array, only where appropriate afterwards. Modify the code from your original Desk class to create an improved version. NOTE: You will need to comment out your PAssign02 code if it is in the same package as PAssigno2. Otherwise, Java will give a syntax error due to duplicate class names. Update the Desk class so that all data members have proper visibility as well as accessors(getter) and mutator(setter) methods. Modify the rest of the class to use the accessors and mutator methods. Additional requirements should be enforced in mutators: desks can only have 0-8 drawers, otherwise they should be set to 4; surface height should be in the range of 24-45 inches, resetting to 27 inches if not;if the material being used is not at least 3 characters long, the material should reset to Oak; and if the manufacturing state is not at least 4 characters long, the state should reset to lowa. All methods and constructors should be given proper visibility. You may add constructors, but they must update any static members as necessary. Make sure there is a way to retrieve any static member values outside of the class. Draw/sketch the UML diagram for the Desk class and then implement the class in Java. Submit this UML diagram with your project. Write a test program that creates Desk objects with the stated values as specified in the output Collect those 5 Desk instances into an array and call the printDesks() method. The printDesks() method should accept a Desk array as a parameter and prints out the result of each Desk's getInfo() method as shown in the expected output. The printDesks() method should work for any length Desk array. Do not forget to print the total number of desks. For Desks 3, 4, 5, make sure to trigger the error checking for number of drawers, surface height, and material, respectively. HINT: Create the Desk instances first, then use the shortcut initializer to create your array. Do not attempt to use iteration when creating the array, only where appropriate afterwards
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
