I am new to programming and I have tried to recreate below lines into OOP's code. Please review and provide comments.
House has Rooms.Rooms are drawing room, bed room, bathroom etc.Each room has walls, ceiling,floor. Each room have different objects in it like drawing room has sofa, table , TV etc. , bedroom has TV etc.
//House class
import java.util.List;
public class House{
private List<Room> rooms;
public House(List<Room> rooms){
this.rooms = rooms;
}
public void getHouseDetails(){
System.out.println("The House has "+this.rooms.size()+" room");
System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
for(Room room:rooms){
room.getRoomDetails();
System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
}
}
}
//Room class
import java.util.List;
public class Room{
private List<Wall> walls;
private Ceiling ceiling;
private Floor floor;
public Room(List<Wall> walls,Ceiling ceiling,Floor floor){
this.walls = walls;
this.ceiling = ceiling;
this.floor = floor;
}
public List<Wall> getWalls(){
return this.walls;
}
public Ceiling getCeiling(){
return this.ceiling;
}
public Floor getFloor(){
return this.floor;
}
public void getRoomDetails(){
}
}
//Wall class
public class Wall{
private String type;
private String color;
public Wall(String type, String color){
this.type = type;
this.color = color;
}
public void getWallDetails(){
System.out.println("Wall is made up of "+this.type+" and is of "+this.color+" color");
}
}
//Ceiling class
public class Ceiling{
private String make;
private String color;
public Ceiling(String make,String color){
this.make = make;
this.color = color;
}
public void getCeilingDetails(){
System.out.println("Ceiling is made up of "+this.make+" and is of "+this.color+" color");
}
}
//Floor class
public class Floor{
private String make;
public Floor(String make){
this.make = make;
}
public void getFloorDetails(){
System.out.println("Floor is made up of "+this.make);
}
}
//Sofa class
public class Sofa{
private String type;
private int number;
public Sofa(String type,int number){
this.type = type;
this.number = number;
}
public void getSofaDetails(){
System.out.println("There is "+this.number+" Sofa which are "+this.type+" type");
}
}
//Chair class
public class Chair{
private String type;
private int number;
public Chair(String type,int number){
this.type = type;
this.number = number;
}
public void getChairDetails(){
System.out.println("There is "+this.number+" chair which are "+this.type+" type");
}
}
//TV class
public class TV{
private String type;
private String make;
private int number;
public TV(String type,String make,int number){
this.type = type;
this.make = make;
this.number = number;
}
public void getTVDetails(){
System.out.println("There is "+this.number+" TV which is "+this.type+" type ,manufactured by "+this.make);
}
}
//Table class
public class Table{
private String type;
private int number;
public Table(String type,int number){
this.type = type;
this.number = number;
}
public void getTableDetails(){
System.out.println("There is "+this.number+" Table which is of "+this.type);
}
}
//Drawing Room class
import java.util.List;
public class DrawingRoom extends Room{
private Sofa sofa;
private Chair chair;
private TV tv;
private Table table;
public DrawingRoom(List<Wall> walls,Ceiling ceiling,Floor floor,Sofa sofa,Chair chair,TV tv,Table table){
super(walls,ceiling,floor);
this.sofa = sofa;
this.chair = chair;
this.tv = tv;
this.table = table;
}
@Override
public void getRoomDetails(){
System.out.println(this.getClass().getSimpleName());
getWalls().get(getWalls().size()-1).getWallDetails();
getCeiling().getCeilingDetails();
getFloor().getFloorDetails();
this.sofa.getSofaDetails();
this.chair.getChairDetails();
this.tv.getTVDetails();
this.table.getTableDetails();
}
}
//Bed Room class
import java.util.List;
public class BedRoom extends Room{
private TV tv;
public BedRoom(List<Wall> walls,Ceiling ceiling,Floor floor,TV tv){
super(walls,ceiling,floor);
this.tv = tv;
}
@Override
public void getRoomDetails(){
System.out.println(this.getClass().getSimpleName());
getWalls().get(getWalls().size()-1).getWallDetails();
getCeiling().getCeilingDetails();
getFloor().getFloorDetails();
this.tv.getTVDetails();
}
}
//Bath Room class
import java.util.List;
public class BathRoom extends Room{
private TV tv;
public BathRoom(List<Wall> walls,Ceiling ceiling,Floor floor){
super(walls,ceiling,floor);
}
@Override
public void getRoomDetails(){
System.out.println(this.getClass().getSimpleName());
getWalls().get(getWalls().size()-1).getWallDetails();
getCeiling().getCeilingDetails();
getFloor().getFloorDetails();
}
}
//Main class
import java.util.List;
import java.util.ArrayList;
public class HouseTest{
public static void main(String [] args){
List<Wall> wall = new ArrayList<Wall>();
List<Room> room = new ArrayList<Room>();
wall.add(new Wall("Cement","Yellow"));
room.add(new DrawingRoom(wall,new Ceiling("Cement","Purple"),new Floor("Marble"),new Sofa("Leather",4),new Chair("Wooden",2),new TV("LED Plasma","Samsung",1),new Table("Glass",1)));
room.add(new BedRoom(wall,new Ceiling("Cement","Purple"),new Floor("Marble"),new TV("LED Plasma","Samsung",1)));
room.add(new BathRoom(wall,new Ceiling("Cement","Purple"),new Floor("Marble")));
House house = new House(room);
house.getHouseDetails();
}
}