/** This code is supposed to take the user input of the length
and breadth of the room in one class, get the user input of the
material and cost from the other class and calculate the total cost.*/
import java.util.Scanner;
//My first class
class RoomFlooring
{
private String FloorMaterial;
private double material_cost = 0;
public void setFloorMaterial(String FloorMaterial)
{
System.out.print('\u000C');
// Choosing the floor material
Scanner Floor = new Scanner(System.in);
System.out.println("Choose your floor material: FancyTile or NormalTile: ");
FloorMaterial = Floor.nextLine();
}
public String getFloorMaterial()
{
return FloorMaterial;
}
// determining the cost according to the floor materials
public void setMaterial_Cost(double material_cost)
{
if (FloorMaterial == "FancyTile")
{
material_cost = 2;
}
else
{
material_cost = 4;
}
}
public double getMaterial_Cost()
{
return material_cost;
}
}
// class to set and get the room dimensions from the user
class RoomDimensions
{
private double length;
private double width;
// getting the length of the room
public void setLength(double length)
{
Scanner room = new Scanner(System.in);
System.out.println("Enter the length of the room: ");
length = room.nextDouble();
}
// getting the width of the room
public void setWidth(double width)
{
Scanner room = new Scanner(System.in);
System.out.println("Enter the width of the room: ");
width = room.nextDouble();
}
public double getLength()
{
return length;
}
public double getWidth()
{
return width;
}
// calculating the area of the room
public double getArea()
{
return length*width;
}
}
//Public class that has the main method
public class PriceCalculator
{
private RoomFlooring room_flooring ;
private RoomDimensions room_dimensions ;
// passing the data of the above classes to this public class
public PriceCalculator(RoomFlooring room_flooring, RoomDimensions room_dimensions)
{
this.room_flooring = room_flooring;
this.room_dimensions = room_dimensions;
}
public void main(String[] args)
{
double final_cost;
final_cost = room_flooring.getArea() * room_dimensions.getMaterial_Cost();
// I get my error on the above line of the code
System.out.println(final_cost);
}
}
guffadi 0 Newbie Poster
rproffitt 2,662 "Nothing to see here." Moderator
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
guffadi commented: If i make my main method static, it says : non-static variable room flooring cannot be referenced from a static context +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
guffadi commented: It still gives me the same error message when I put everything in my main method +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
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.