The following code should let a user input the square feet and stories of a building. I keep having problems with the code in main and for the life of me I cannot figure out why.
import java.util.*;
public class Building
{
static Scanner console = new Scanner(System.in);
double area, squarefootage;
int floors, stories;
char ans
void get_squarefootage()
{
System.out.println ("Please enter the square footage of the floor.");
area = console.nextDouble();
}
void set_squarefootage(double area)
{
squarefootage = area;
}
void get_stories()
{
System.out.println ("Please enter the number of floors in the building.");
floors = console.nextInt();
}
void set_stories(int floors)
{
stories = floors;
}
void get_info()
{
System.out.println (" The area is: " + squarefootage + " feet squared");
System.out.println (" The number of stroies in the building: " + stories + " levels");
}
public static void main(String[] args)
{
Building b = new Building();
b.get_squarefootage();
b.set_squarefootage(area);
b.get_stories();
b.set_stories(floors);
System.out.println ("---------------");
b.get_info();
System.out.println ("Would you like to repeat this program? (Y/N)");
}
}
The problem im having are on lines 48 and 50 and it displays the error;
Building.java:48: error: non-static variable area cannot be referenced from a static context
b.set_squarefootage(area);
^
Building.java:50: error: non-static variable floors cannot be referenced from a static context
b.set_stories(floors);
Thanks for the help
Relatedsection.areaon line 48, where do you expect it to come from?