import java.util.Scanner;

 class Room_Dimension
{

    private double length;
    private double width;

    public Room_Dimension(double length, double width) 
    {
        this.length = length;
        this.width = width;
    }

    public void setLength(double length) 
    {
    this.length = length;
    }

    public void setWidth(double width) 
    {
    this.width = width;
    }

    public double getLength() 
    {
        return length;
    }

    public double getWidth() 
    {
        return width;
    }

    public Room_Dimension(Room_Dimension roomDimensions)
    {
        this.length = roomDimensions.getLength();
        this.width  = roomDimensions.getWidth();
    }

    public double getArea() 
    {
        return length * width;
    }

}

 class Room_Flooring 
{
    private String floorMaterial;
    private Room_Dimension roomDimensions;
    private double cost_of_material;

    public Room_Flooring(Room_Dimension roomDimensions, String floorMaterial) 
    {
        this.roomDimensions = roomDimensions;
        this.floorMaterial = floorMaterial;
        this.cost_of_material = cost_of_material;
    }

    public Room_Dimension getSize()
    {
        return roomDimensions;
    }

    public void setFloorMaterial(String floorMaterial)
    {
        this.floorMaterial = floorMaterial;
    }

    public String getFloorMaterial()
    {
        return floorMaterial;
    }

    public double getCost_of_Material(String floorMaterial)
    {
        if (floorMaterial == "NormalTile")
        {
            cost_of_material = 2.0;
        }

        if (floorMaterial == "FancyTile")
        {
            cost_of_material = 4.0;
        }

        return cost_of_material;
    }

    public Room_Flooring(Room_Flooring roomFlooring)
    {
        this.roomDimensions = roomFlooring.roomDimensions;
        this.floorMaterial     = roomFlooring.getFloorMaterial();
        this.cost_of_material = roomFlooring.getCost_of_Material(floorMaterial);
    }

    public double getTotalCost() 
    {
        return (getCost_of_Material(floorMaterial)) * roomDimensions.getArea();
    }

    public String toString()
    {
        return ""+ getTotalCost() +"" ;
    }

}

public class Pricing 
{
    public static void main(String[] args) 
    {
        System.out.print('\u000C');

        Scanner room = new Scanner(System.in);

        // Get the length of the room.
        System.out.println("Enter the length of room: ");
        double length = room.nextDouble();

        // Get the width of the room.
        System.out.println("Enter the width of room: ");
        double width = room.nextDouble();

        System.out.println("Enter the floor material that you want- NormalTile or FancyTile: ");
        String floorMaterial = room.nextLine();

        // Create Room_Dimension and Room_Flooring objects.
        Room_Dimension dimensions = new Room_Dimension(length, width);
        Room_Flooring roomFlooring = new Room_Flooring(dimensions, floorMaterial);

        // Print the object calling the toString
        System.out.println(roomFlooring);
    }
}

Don't worry, it's not really your fault. You are roughly the one millionth person to be trapped by this stupidity in the design of the Scanner clsss.

Here's the explanation (it uses ints, but doubles work the same way).

You have some input with an int followed by some text, eg
101
John Doe
... and you try to read it with
int num = scanner.nextInt();
String name = scanner.nextLine();
... and name is an empty String ("")!

Here's why:
Your input looks like this with the new line characters shown explicitly
101\nJohn Doe\n
nextInt takes the int value from the scanner, and stops when it finds a chaacter that's not part of an int, so it takes the "101", leaving this in the scanner
"\nJohn Doe\n"
then nextLine takes everything up to the first \n character - a zero-length String ("").

Possible fixes:

  1. Add add extra nextLine() between the nextInt and the real nextLine to clear the unwanted \n. This may be difficult if the nextInt and the nextLine are in different areas of code which are not always executed together.
  2. Give up on nextInt (etc) and just read whole lines and parse then into ints (etc) with Integer.parseInt (etc) - in which case you can junk the whole scanner and use a BufferedReader instead.
    new BufferedReader(new InputStreamReader(System.in))

  3. Use this class instead of Scanner:
    https://www.daniweb.com/programming/code/506346/a-simpler-safer-alternative-to-java-util-scanner
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.