Here' the Class :
public class Rectangle {
private double lenght ;
private double width ;
public String name ;
public Rectangle (double len, double w, String n)
{
lenght = len;
width = w;
name = n;
}
public double getLenght()
{
return lenght ;
}
public double getWidth ()
{
return width ;
}
public String getName()
{
return name ;
}
public double getArea ()
{
return lenght * width ;
}
}
And here' s my constructor:
public class roomConstructor {
public static void main(String[] args) {
double roomLenght, roomWidht, totalArea;
String roomName;
Rectangle kitchen, bedroom, den;
Scanner keyboard = new Scanner (System.in);
System.out.println("What is the name of your kitchen? " );
roomName = keyboard.nextLine();
System.out.println("What is the lenght of the kitchen ? " );
roomLenght = keyboard.nextDouble();
System.out.println("What is the widht of the kitchen ? ");
roomWidht =keyboard.nextDouble();
kitchen = new Rectangle(roomLenght, roomWidht, roomName );
System.out.println("What is the name of your bedroom? " );
roomName = keyboard.nextLine();
keyboard.nextLine();
System.out.println("What is the lenght of the bedroom ? ");
roomLenght = keyboard.nextDouble();
System.out.println("What is your bedroom withd ? ");
roomWidht = keyboard.nextDouble();
bedroom = new Rectangle(roomLenght,roomWidht, roomName );
System.out.println("What is the name of your den? " );
roomName = keyboard.nextLine();
keyboard.nextLine();
System.out.println(" What is the lenght of your den ? ");
roomLenght =keyboard.nextDouble();
System.out.println("What is the widht of your den ? ");
roomWidht =keyboard.nextDouble();
den = new Rectangle ( roomLenght, roomWidht,roomName);
totalArea = kitchen.getArea() + bedroom.getArea() + den.getArea();
System.out.println(" The total area of your room is : " + totalArea);
System.out.println(" The name of your kitchen is : " + kitchen.getName());
System.out.println(" The name of your kitchen is : " + bedroom.getName());
System.out.println("The name of your bedroom is : " + den.getName());
System.out.println("The lenght of the kitchen is : " + bedroom.getLenght());
}
}
When I try to get the bedroom or den name it's missing the all name answer I get is the kitchen then there are 2 blank answers 5lmissing name for bedroom and den) What should I do please ? Thanks for your help