Decision Structures in Java       You are the owner of a company that sells designer desks. Your...

80.2K

Verified Solution

Question

Programming

Decision Structures in Java

      You are the owner of a companythat sells designer desks. Your program will create a user friendlyinterface (company name, labeled prompts, neat output) thatcalculates the cost of constructing desks for customers. After thecustomer enters the appropriate prompted values, the program willcalculate the cost of the desk based on the specifications outlinedbelow. The program should allow the user to order a second desk ifdesired.

  1. Define a java instance class as described below. Save the classdefinition in a file with an appropriate filename.

ClassName:         Desk

Instance Variables: length – float(representing inches)

(Fields)                    width – float (representing inches)

                                type – char (valid values P, O, or M for Pine, Oak, orMahogany)

                                drawers – integer (representing the number of desk drawers)

StaticVariable:        count– tracks the number of desks created

Instance Methods: Aconstructor that accepts no arguments and setsdefault values as follows: the length to 6, width to 12, Oak type,and 1 drawer

                                A constructor that accepts 4 arguments, and setsthe fields appropriately.

                                 getArea() A method to calculate and return the area of thedesk.

                                 getType() A method to return desk type.

                                 getDrawers() A method to return the number of drawers.

                                 toString()Displays the object’s attributes

                                

  1. Create a program class, TestDesk, thatcontains a main() to test and use the above class. This processshould contain methods as follows:

main(): This method should:

  1. Call createDesk() to get the inputs and create a Deskobject.
  2. Call calculatePrice() to determine the cost of constructing adesk.
  3. Display the price of the desk along with the attributevalues.
  4. Ask the user if they want another desk.
  5. If the answer is No, display the total price of the desk
  6. If the answer is Yes, implement steps 1 and 2 again (without aloop), then display:
  • the number of desks created (through a variable)
  • total cost of the desk(s), and
  • average desk cost.
  1. The program should then end.

Classmethods:      createDesk() A function to prompt the user for inputs and accept thefour (4) input values needed to create an instance of a Desk. Itinstantiates a Desk object and returns the object to the callingmethod.

                              CalculatePrice()This function has a Desk object as its formal argument and returnsthe price of the desk to be determined as follows:

  • The basic cost of a frame is $12.50 for P(ine), $26 for O(ak),and $37.75 for M(ahogany).
  • Any desk with an area greater than 75 square inches isconsidered large. Add $18.25 to the cost for a large desk.
  • The basic desk comes with one (1) drawer. There is an extracharge of $9.50 for each additional drawer. Desk’s are charged fora maximum of six (6) drawers. Any desk with more than 6 drawers ischarged for 6 drawers.

Additional Notes:

  • Be sure to efficiently implement all 3 decision structuresdiscussed in class
  • Implement sound program design so as to avoid duplicatedcode
  • An invalid wood type entry should default to Oak
  • Your program should accommodate upper and lower case userinputs
  • Dollar values should be displayed to 2 decimal places andlabeled

Answer & Explanation Solved by verified expert
4.1 Ratings (537 Votes)
Program In this program we implement the Deskclass and TestDesk class TestDesk class is the driver class whichhas a main method createDesk method and CalculatePricemethod We take user inputs for desk specifications and then showthe user with the total price desk properties and also ask if theuser wants to buy another desk or notBelow is the implementationCodepublic class Desk Instance variables private float length private float width private char type private int drawer static int count 0 Default Constructor public Desk length 6 width 12 type O drawer 1 count Parameterised Constructor public Deskfloat length float width    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students