Java error: constructor in class cannot be applied to given types
Your problem is this line here: Building b = new Building(); // Creates the object b
Your constructor is set up to take two arguments, a double and an int, but you pass neither.
Try something like this to remove the error:
double area = 0.0;
int floors = 0;
Building b = new Building(area, floors);
Perhaps a better idea would be to just have a constructor that took no parameters...
public Building{
this.area = 0.0;
this.floors = 0;
}
After I apply these changes, the code compiles and runs... (see the picture below)
I have fixed and tested your code. It now runs. You need to add two arguments to the constructor (double and int).
import java.util.*;
public class Building // The class begins
{
static Scanner console = new Scanner(System.in);
double area; // Attributes of a building
int floors;
public Building (double squarefootage, int stories)
{
area = squarefootage;
floors = stories;
}
void get_squarefootage() // The user enters the area of floor
{
System.out.println ("Please enter the square footage of the floor.");
area = console.nextDouble();
}
void get_stories() // The user enters the amount of floors in the building
{
System.out.println ("Please enter the number of floors in the building.");
floors = console.nextInt();
}
void get_info() // This function prints outs the vaibles of the building
{
System.out.println ("The area is: " + area + " feet squared");
System.out.println ("The number of stroies in the building: " + floors + " levels");
}
public static void main(String[] args) // Main starts
{
char ans; // Allows for char
do{ // 'do/while' loop starts so user can reiterate
// the program as many times as they desire
double a = 1;
int c = 2;
Building b = new Building(a, c); // Creates the object b
b.get_squarefootage(); // Calls the user to enter the area
b.get_stories(); // Calls the user to enter the floors
System.out.println("---------------");
b.get_info(); // Displays the variables
System.out.println("Would you like to repeat this program? (Y/N)");
ans = console.next().charAt(0); // The user enters either Y or y until
// they wish to exit the program
} while(ans == 'Y' || ans == 'y'); // Test of do/while loop
}
}