Question

Design classes that store the information about various pieces of furniture. The system will support at...

Design classes that store the information about various pieces of furniture. The system will support at least these pieces: table, chair and lamp. For each piece of furniture, the system will store some attributes. For a table, it will be at least width, length, height, photo and price. For a chair, it will be at least price, photo, height and diagonal. For a lamp, it will be at least the number of bulbs, photo and price. Each piece of furniture will provide a method that prints all the information about that piece. For example, a chair will be printed as follows:

Chair, id: 1, photo: chair1.png, price: 11.99, diagonal: 6, height: 12

A table will be printed as follows: Table, id: 2, photo: table1.png, price: 12.48, width: 10, length: 12, height: 8

And a lamp as follows: Lamp, id: 3, photo: lamp1.png, price: 8.75, bulbs: 2

Besides the individual pieces, the system will support sets of pieces. Each set will have a name, any number of pieces of furniture, and a price and will provide a method that prints all the information about that set. For example, a kitchen set will be printed as follows:

Kitchen (set) Table, id: 4, photo: table2.png, width: 11, length: 16, height: 25 Chair, id: 5, photo: chair2.png, diagonal: 5, height: 10 Chair, id: 5, photo: chair2.png, diagonal: 5, height: 10 price: 25.99

Each class will provide suitable constructors and methods. Each piece of furniture will have a unique ID that will be assigned automatically.

java programming

Homework Answers

Answer #1

Short Summary:

  • Implemented the given problem using OOP
  • Provided you the UML diagram which explains class structure
  • The common characterstics should be placed in an abstract class, then child classes should inherit the parent class and implement the abstract methods.
  • set class has list of furnitures and print method
  • Shown you sample test driver and sample test run.

UML Diagram:

Source Code:

furniture.java File:

public abstract class furniture {
   private int ID;
   private static int numberOfObject;
   private String photo;
   private double price;

   /**
   *
   */
   public furniture() {
       numberOfObject++;
       this.ID = numberOfObject;
   }

   /**
   * @return the photo
   */
   protected String getPhoto() {
       return photo;
   }

   /**
   * @param photo the photo to set
   */
   protected void setPhoto(String photo) {
       this.photo = photo;
   }

   /**
   * @return the price
   */
   protected double getPrice() {
       return price;
   }

   /**
   * @param price the price to set
   */
   protected void setPrice(double price) {
       this.price = price;
   }

   /**
   * @return the iD
   */
   protected int getID() {
       return ID;
   }
  
   // abstract method to be overriden in child class
   public abstract void printInfo();
  
}

table.java File:

public class table extends furniture{
   private int width;
   private int length;
   private int height;
   /**
   * @param width
   * @param length
   * @param height
   */
   public table(int width, int length, int height, String photo, double price) {
       super();
       this.width = width;
       this.length = length;
       this.height = height;
       super.setPhoto(photo);
       super.setPrice(price);
   }
  
   // Print table info
   @Override
   public void printInfo() {
       System.out.println("Table, id: " +super.getID() + ", photo: " + super.getPhoto() + ", price: " + super.getPrice()
           + ", width: " + this.width + ", length: " + this.length + ", height: " + this.height);
      
   }
}

chair.java File:

public class chair extends furniture {
   private int height;
   private int diagonal;
  
   /**
   * @param height
   * @param diagonal
   */
   public chair(int height, int diagonal, String photo, double price) {
       super();
       this.height = height;
       this.diagonal = diagonal;
       super.setPhoto(photo);
       super.setPrice(price);
   }

   @Override
   public void printInfo() {
       System.out.println("Chair, id: " + super.getID() + ", photo: " + super.getPhoto() + ", price: " +
               super.getPrice() + ", diagonal: " + this.diagonal + ", height: " + this.height);
      
   }
  
  
}

lamp.java File:
public class lamp extends furniture {
   private int numberOfBulbs;

   /**
   * @param numberOfBulbs
   */
   public lamp(int numberOfBulbs, String photo, double price) {
       super();
       this.numberOfBulbs = numberOfBulbs;
       super.setPhoto(photo);
       super.setPrice(price);
   }

   @Override
   public void printInfo() {
       System.out.println("Lamp, id: " + super.getID() + ", photo: " + super.getPhoto() + ", price: " + super.getPrice() +
               ", bulbs: " + this.numberOfBulbs);
   }
}

set.java File:

import java.util.ArrayList;

public class set {
   private ArrayList<furniture> furnitures;

   /**
   *
   */
   public set() {
       super();
       furnitures = new ArrayList<furniture>();
   }
  
   public void addFurniture(furniture f) {
       furnitures.add(f);
   }
  
   public void printSet() {
       for(furniture f : furnitures) {
           f.printInfo();
       }
   }
}

furnitureTest.java File:
public class furnitureTest {

   public static void main(String[] args) {
       chair c = new chair(12, 6, "chair1.png", 11.99);
       table t = new table(10, 12, 8, "table1.png", 12.48);
       lamp l = new lamp(2, "lamp1.png", 8.75);
      
       set kitchenSet = new set();
       kitchenSet.addFurniture(c);
       kitchenSet.addFurniture(t);
       kitchenSet.addFurniture(l);
       kitchenSet.printSet();

   }

}

Sample Run:

**************************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

**************************************************************************************

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following information is used for questions 28-30: The Hickory Cabinet & Furniture Company produces sofas,...
The following information is used for questions 28-30: The Hickory Cabinet & Furniture Company produces sofas, tables and chairs.  The plant uses three main resources to make furniture:  wood, upholstery and labor.  The unit profits, the resource requirements for each piece of furniture and the total resources available weekly are as follows:   Profit/unit Wood (lb) Upholstery (yd) Labor (hour) Sofa $400 7 12 6 Table 275 5 -- 9 Chair 190 4 7 5 Total available resources: 2250 1750 2000 The furniture is...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most competitive in Thailand. With a large number of players ranging from restaurants in five-star hotels, global fast-food chains to small stalls along the streets and everything in between, the Thais are spoiled for choice. In addition, as the world becomes globalized, consumers are familiar with international dishes and would not hesitate to try new offerings from the other side of the globe. As a...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT