Java cannot find symbol: constructor error
I am writing a class (Suite) that is inheriting from another class (HotelRoom). The HotelRoom class has a constructor that requires an argument (an int) and so in the constructor for Suite I called super(room) which from what I can tell should work. HotelRoom complies just fine, however Suite gives the constructor error. Any help would be greatly appreciated. Here is my code below:
public class HotelRoom
{
private int roomNumber;
protected double nightlyRate;
private final int maxRoomNumber = 999;
boolean didEnterCorrectRoomNumber = false;
public HotelRoom(int room)
{
if (room > 0 && room <= 299)
{
nightlyRate = 69.95;
didEnterCorrectRoomNumber = true;
//return didEnterCorrectRoomNumber;
}
else if (room > 299 && room <= maxRoomNumber)
{
nightlyRate = 89.95;
didEnterCorrectRoomNumber = true;
//return didEnterCorrectRoomNumber;
}
else
{
//return didEnterCorrectRoomNumb开发者_运维百科er;
}
}
public int getRoomNumber ()
{
return roomNumber;
}
public double getNightlyRate ()
{
return nightlyRate;
}
public boolean getDidEnterCorrectRoomNumber ()
{
return didEnterCorrectRoomNumber;
}
public void displayRoom ()
{
System.out.println("Room Number: " + roomNumber);
System.out.format("Cost per Night: $%.2f%n", nightlyRate);
}
}
and my subclass:
public class Suite extends HotelRoom
{
private final double suiteSurchargeRate = 40.00;
private double nightlyRateWithSuite;
public Suite (int room)
{
super(room);
//boolean didEnterCorrectRoomNumber = super.getDidEnterCorrectRoomNumber();
nightlyRateWithSuite = super.getNightlyRate() + suiteSurchargeRate;
//return didEnterCorrectRoomNumber;
}
public void displayRoom ()
{
super.displayRoom();
System.out.format("Suite Surcharge: $%.2f%n", suiteSurchargeRate);
System.out.format("Total Cost per Night: $%.2f%n", nightlyRateWithSuite);
}
}
Exact compiler error:
MacBook-Air:HotelRoom Nick$ javac Suite.java Suite.java:12: cannot find symbol symbol : constructor HotelRoom(int) location: class HotelRoom super(room); ^ 1 error
I have saved and recompiled both a few times and I just get the same result. HotelRoom compiles fine, but Suite does not. They are the only two java files in their directory, so there are no issues with calling the wrong class. :)
I think it relates to your Java setup on your Mac. Using Java 1.6 on a PC running Linux it compiles and runs fine for me, tested with following Main class
public class Main {
public static void main(String[] args) {
Suite suite = new Suite(10);
suite.displayRoom();
}
}
Output:
Room Number: 0
Cost per Night: $69.95
Suite Surcharge: $40.00
Total Cost per Night: $109.95
精彩评论