Question
in java 8

Design classes that store the information about various pieces of furniture. The system will support at least these pieces: t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;


// Use of abstract class

public abstract class Furniture {

    String name;

    double price;

    String photo;

    // USE OF ABSTRACT METHODS

    

    abstract void display();

    abstract String getDetails();

}

// USE OF INHERITANCE

class Chair extends Furniture{

   

    static int id_iterator = 1;

     

    int height,diagonal;

    int id;

    

    //USE OF FINAL VARIABLE

    final String details;

    //USE OF CONSTRUCTOR OVERLOADING

    Chair(String photo, double price ,int height,int diagonal){

        this.diagonal =diagonal;

        this.height =height;

        this.photo =photo;

        this.price =price;

        this.name ="Chair";

        this.id = id_iterator;

        id_iterator +=1;

        //details = "";

        details ="Chair ," +"id : "+this.id + ", photo : "+this.photo +", diagonal : " + this.diagonal + ", height : "+this.height;

    }

    

    // USE OF OVERRIDING

    void display(){

        System.out.println("Chair ," +"id : "+this.id + ", photo : "+this.photo + ", price : "+ this.price + ", diagonal : " + this.diagonal + ", height : "+this.height);

    

    }

   

    public String getName(){

        return this.name;

    }

   

    public String getDetails(){

        return this.details;

    }

}

class Table extends Furniture{

   

    static int id_iterator = 1;

    

    int height,width,length;

    int id;

    final String details;

    Table(String photo, double price ,int height,int width,int length){

        this.length =length;

        this.width =width;

        this.height =height;

        this.photo =photo;

        this.price =price;

        this.name ="Table";

        this.id = id_iterator;

        id_iterator +=1;

        details = "Table ," +"id : "+this.id + ", photo : "+this.photo + ", price : "+ this.price + ", width : " + this.width + ", length : "+this.length + " height : "+this.height;

    }

    


    void display(){

        System.out.println("Table ," +"id : "+this.id + ", photo : "+this.photo + ", price : "+ this.price + ", width : " + this.width + ", length : "+this.length + " height : "+this.height);

    

    }

    public String getName(){

        return this.name;

    }

    public String getDetails(){

        return this.details;

    }

}



class Lamp extends Furniture{

   

    static int id_iterator = 1;

    final String details;

    int id,bulbs;

    

    Lamp(String photo, double price ,int bulbs){

        this.bulbs =bulbs;

        this.photo =photo;

        this.price =price;

        this.name ="Lamp";

        this.id = id_iterator;

        id_iterator +=1;

        details ="Lamp ," +"id : "+this.id + ", photo : "+this.photo  + ", bulbs : "+this.bulbs;

    }

    

    public String getName(){

        return this.name;

    }

    void display(){

        System.out.println("Lamp ," +"id : "+this.id + ", photo : "+this.photo + ", price : "+ this.price + ", bulbs : "+this.bulbs);

    

    }

   

    public String getDetails(){

        return this.details;

    }

}

class Sets{

  String name;

  ArrayList<Furniture> mySet ;

  double total=0.0;

  Sets(String name){

      this.name =name;

      mySet = new ArrayList<>();

  }

  

  void addToSet(Furniture myFurniture){

      mySet.add(myFurniture);

  }

   

  void displaySet(){

      System.out.println(this.name + "(Set)");

      for(Furniture f : mySet){

        total += f.price;

    

         System.out.println(f.getDetails());


      }

      System.out.println("price :"+ this.total);

  }

}

class Test_Furniture{

public static void main(String args[]){

  Chair c = new Chair("chair1.png", 11.99, 6, 12);

  Chair c1 = new Chair("chair2.png", 12.34, 7, 13);

  Table t =new Table("table1.png", 12.48, 10, 12, 8);

  Lamp l = new Lamp("lamp1.png", 8.75, 2);

  Sets s = new Sets("Kitchen");

  s.addToSet(c);

  s.addToSet(t);

  s.addToSet(l);

  c1.display();

  c.display();

  t.display();

  l.display();

  s.displaySet();

}

}



NOW HAVE A LOOK AT IDE CODE WITH PROPER INDENTATTION

1 File Edit Selection View Go Run Terminal Help • Furniture.java - loveEditor - Visual Studio Code Х Furniture.java Temperatu

on.java А File Edit Selection View Go Run Terminal Help • Furniture.java - loveEditor - Visual Studio Code makeGoFdictionary.

public String getName(){ return this.name; } 52 53 54 55 56 57 58 59 public String getDetails(){ return this.details; } }

60 61 class Table extends Furniture{ static int id_iterator = 1; 62 63 64 65 66 67 68 69 int height,width, length; int id; fi

91 92 93 public String getDetails({ return this.details; } TC 94 } 95 96 97 98 99 100 class Lamp extends Furniture{ А 101 102

public String getDetails(){ return this.details; } } . class Sets{ String name; ArrayList<Furniture> mySet ; double total=0.0

} System.out.println(price :+ this.total); } go 150 151 152 153 154 155 156 } class Test_Furniture{ B. Run | Debug public s

NOW HAVE A LOOK AT THE OUTPUT SCREEN

class Test_Furniture{ 155 156 Run Debug PROBLEMS 4 OUTPUT DEBUG CONSOLE TERMINAL 4: Java Process Console v + А PS C:\Users\ch

HOPE I HELPED YOU.

Add a comment
Know the answer?
Add Answer to:
in java 8 Design classes that store the information about various pieces of furniture. The system...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL....

    Must be done in Java. PROBLEM 2 INFORMATION AND THE CODE PROVIDED WITH IT AS WELL. PROBLEM 1 INFORMATION IF YOU NEED IT AS WELL: Provide the rest of the code with full comments and explanation and with proper indentation. Use simple methods for better understanding. Must compile. At the end, show the exact Output that's shown in Problem3. CODE PROVIDED FOR PROBLEM 2: import java.util.Scanner; public class Problem2 { public static void main( String [] args ) { //N...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT