-3
public class RoomListener implements ActionListener
{
    public void actionPerformed(ActionEvent event)
    {
        double roomtype; 

        if (event.getSource() == room1)
            roomtype = 60;
        else if (event.getSource() == room2)
            roomtype = 75;
        else 
            roomtype = 100;
    }

}


public class CostListener implements ActionListener
{
    public void actionPerformed(ActionEvent event)
    {
        double NightLength, roomNumber, cost;
        String NightText = NumberOfNights.getText();
        String RoomText = NumberOfRooms.getText();

        NightLength = Double.parseDouble(NightText);
        roomNumber = Double.parseDouble(RoomText);

        RoomListener.actionPerformed(RoomType);
        cost = roomtype * NightLength * roomNumber;

        CostCalculation.setText(Double.toString(cost));
        NumberFormat fmt = NumberFormat.getNumberInstance();
        CostCalculation.setText(fmt.format(cost));
    }
}
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Sam D.
  • 1
  • 2
  • 3
    so what's the problem? what error are you getting? – 0x6C38 Dec 06 '16 at 23:42
  • for RoomListener.actionPerformed(roomtype); - it says that "The method actionPerformed(ActionEvent) in the type HotelBookingPanel.RoomListener is not applicable for the arguments (double)" – Sam D. Dec 07 '16 at 01:07

1 Answers1

0

RoomListener.actionPerformed(RoomType);

  1. This isn't a static method. You can't call it using the class name.

  2. What is RoomType? If it isn't an ActionEvent, then it won't work. Look at the method.

    public void actionPerformed(ActionEvent event)
    
  3. You really shouldn't be calling out to another listener's actionPerformed, or at least I can't think of a reason to. You need to add a new RoomListener() onto your RadioButtons. Though, I'd suggest you look into a RadioGroup class, and reading the JavaDoc for the correct listener which lets you determine the source of the selected radio button.

  4. Nothing is returned from this method. double roomtype is a local variable and it is discarded (garbage collected) when you exit this method. Maybe you meant to modify a member variable? this.roomtype? Along with that point - I can't tell what room1 and room2 are here... They don't seem to be accessible.

    public void actionPerformed(ActionEvent event)
    {
        double roomtype; 
    
        if (event.getSource() == room1)
            roomtype = 60;
        else if (event.getSource() == room2)
            roomtype = 75;
        else 
            roomtype = 100;
    }
    
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245