Question: 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
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 Iowa.
Draw/sketch the UML diagram for the Desk class and then implement the class in Java.
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 Desks 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.

public class Projecti { public static void main(String[] args) { // TODO Auto-generated method stub Desk di = new Desk(5,43.50, true,"Birch", "Tennessee" ); d.getInfo(); System.out.println(); System.out.println("Total number of desks: " + Desk.numofDesks); Desk d2 = new Desk(8,29.20,"Mahogany","California"); System.out.println(); d2.getInfo(); System.out.println(); System.out.println("Total number of desks: " + Desk.numOfDesks); System.out.println(); Desk d3 = new Desk(3); d3.getInfo(); System.out.println(); System.out.println("Total number of desks: " + Desk.numOfDesks); } } class Desk int numOfDrawers = 4; double surfaceHeight = 27.00; boolean standing - false; String Manufacture = "North Carolina"; String Material - "Pine"; static int numOfDesks - ; // This is mandatory according to the project document public Desk) { numofDesks++; } // This is mandatory according to the project document public Desk(int numOf Drawers) { this.numOfDrawers = numOf Drawers; numofDesks++; } // This constructor is optional public Desk(int numOfDrawers, double surfaceHeight, boolean standing, String material, String manufacture ) this.numOfDrawers - numOfDrawers; this.surfaceHeight = surfaceHeight; this.standing standing; this.Material = material; this.Manufacture = manufacture; numOfDesks++; } // This constructor is optional public Desk(int numOf Drawers, double surfaceHeight, String material, String manufacture ) { this.numofDrawers - numOfDrawers; this.surfaceHeight = surfaceHeight; this.Material = material; this.Manufacture = manufacture; numofDesks++; } public void getInfo() { System.out.println("Desk Information"); System.out.println("Number Drawers:\t"+numofDrawers); System.out.println(String.format("%s\t%.2f %s", "Surface Height:",surfaceHeight, "inches")); System.out.println("Standing: "+"\t\t"+standing); System.out.println("Material:"+"\t\t"+Material); System.out.println("Manufactured:"+"\t\t"+Manufacture)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
