Hi all,
I'm almost done with a problem for a java class I'm taking. The chapter I'm studying is on inheritance and I think I understand it ok. The parent class will compile fine, but when the child class tries to compile I get an error saying it cannot find the constructor in the parent class.

I am supposed to write an application that creates an object of each class, and demonstrate that all the methods work correctly.

Take a look, any input would be VERY appreciated!


Parent Class:

public class HotelRoom
{
  double rentRate;
  int roomNum;
  
  public HotelRoom(int num)
  {
    roomNum = num;
    if(roomNum < 300)
	   rentRate = 69.95;
	 else
	   rentRate = 89.95;	 

  }
  public double getRentRate()
  {
    return rentRate;
  }
  public int getRoomNum()
  {
    return roomNum;
  }
}

Child Class:

public class Suite extends HotelRoom
{
  public Suite(int num)
  {  
	 roomNum = num;
	 if(roomNum > 500)
    rentRate += 40.00;
  }
}

Demo Class:

public class UseHotelRoom
{
  public static void main(String[] args)
  {
         HotelRoom guestRoom = new HotelRoom(100);
	 Suite isSuite = new Suite(600);

	 System.out.println("Your hotel room number is " +
	 guestRoom.getRoomNum() + "\nThe total comes to $" +
	 guestRoom.getRentRate());
	 
	 System.out.println("Your hotel room number is " +
	 isSuite.getRoomNum() + "\nThe total comes to $" +
	 isSuite.getRentRate());
  }
}

I just found a thread online that helped me. I can't believe I have been toying with this for the last few hours and the only thing I needed to do was call the super class instead of put the "roomNum = num;" line in each method! The only change I made was in the child class.

From:
roomNum = num;

To:
super(num);

public class Suite extends HotelRoom
{
  public Suite(int num)
  {  
	 super(num);
	 if(roomNum > 500)
    rentRate += 40.00;
  }
}
This question has already been answered. Start a new discussion instead.