5 Replies - 1344 Views - Last Post: 13 October 2012 - 09:42 AM Rate Topic: -----

#1 AceWindgar1285  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 12-October 12

can not find symbol

Posted 13 October 2012 - 02:22 AM

I keep getting the this
Error: cannot find symbol
symbol: method pushButton(int)
location: variable selectedRadio of type Radio
and I've tried everything to fix it. Also have the same issue with the setButton method too.


public class AutoMusicSystem
{ 
  private static int MAX_BUTTONS = 6; 
  
  Radio selectedRadio = null;
  private AMRadio radioAM = new AMRadio();
  private FMPushButtonRadio radioFM1 = new FMPushButtonRadio();
  private FMPushButtonRadio radioFM2 = new FMPushButtonRadio();
  
  AutoMusicSystem()
  {
    radioFM1 = new FMPushButtonRadio(MAX_BUTTONS);
    radioFM2 = new FMPushButtonRadio(MAX_BUTTONS);
    selectedRadio = radioAM;
  }
  
  /*
   *
   * 
   */  
  public void up()
  {
    selectedRadio.up();
  }
  
  /*
   *
   * 
   */  
  public void down()
  {
    selectedRadio.down();
  }
  
  /*
   *
   * 
   */  
  public double getCurrentFrequency()
  {
    double getFreq = selectedRadio.getCurrentFrequency();
    return getFreq;
  }
  
  /*
   *
   * 
   */  
  public String toString()
  {
    String temp = "";
    if (selectedRadio == radioAM)
    {
      temp = temp+"(AM) ";
    }
    else if (selectedRadio==radioFM1)
    {
      temp = temp+"(FM1) ";
    }
    else
      temp = temp+"(FM2) ";
    return temp+ selectedRadio.toString() ;
  }
  
  /*
   *
   * Sets the current frequency to the button
   */ 
  public void setButton(int buttonNumber)
  {
  // selectedRadio.setButton();
  }
  
  /*
   *
   * Change the current radio button
   */
  public void pushButton(int buttonNumber)
  {
    selectedRadio.pushButton(buttonNumber);
  }
  
  /*
   *
   * 
   */
  public void pushSelector()
  {
    //if(selectedRadio == radioAm)
  }
}



Is This A Good Question/Topic? 0
  • +

Replies To: can not find symbol

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: can not find symbol

Posted 13 October 2012 - 03:01 AM

Apparently the Radio class (or interface or whatever it is) doesn't have a method named pushButton (or at least not one that takes an int as its argument).

This post has been edited by sepp2k: 13 October 2012 - 03:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 AceWindgar1285  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 12-October 12

Re: can not find symbol

Posted 13 October 2012 - 07:53 AM

All the classes are to work together. The pushButton method is in the FMPushButtonRadio. But in order get the auto music system to work I need to get the selector to work.






public class FMPushButtonRadio extends FMRadio
{
  // instance variables
  private  double [] buttonsArray;
  
  /*
   * Defualt Constructor
   * 
   */
  public FMPushButtonRadio()
  {   
    this(6);
  }
  
  /*
   * Overload Constructor
   * 
   */
  public FMPushButtonRadio(int numberButtons)
  {
    buttonsArray = new double[numberButtons];
    for(int i =0; i<buttonsArray.length;i++)
    {
      buttonsArray[i]=getMin_Freq();
    }
  }
  
  /*
   * Method use to set the setButton
   * 
   * @param - use to set setButton
   */ 
  public void setButton(int buttonNumber, double frequency)
  {
    if(buttonNumber<1 || buttonNumber>buttonsArray.length)
    {
      System.out.println("***** Error: Button number "+buttonNumber+" is not a valid choice");
    }
    else
      buttonsArray[buttonNumber-1]= frequency;
  }
  
  /*
   * Method use to return the current button
   * 
   * @return - returns the button
   */  
  public double getButton(int buttonNumber)
  {
    if(buttonNumber<1 || buttonNumber>buttonsArray.length)
    {
      System.out.println("***** Error: Button number "+buttonNumber+" is not a valid choice");
    }    
    return buttonsArray[buttonNumber-1];
  }
  
  /*
   * Method used to change the current station
   * 
   * @param - changes the station button
   */  
  public void pushButton(int buttonNumber)
  {
    if(buttonNumber<1 || buttonNumber>buttonsArray.length)
    {
      System.out.println("***** Error: Button number "+buttonNumber+" is not a valid choice");
    }
    else
      setCurrentFrequency(buttonsArray[buttonNumber-1]);    
  }
  
  /*
   * 
   * @return - returns a string
   */  
  public String toString()
  {
    String temp = "";
    for (int i=0;i<buttonsArray.length;i++)
    {
      temp = temp+"("+(i+1)+": "+buttonsArray[i]+")";
    }
    return super.toString() + "\n" + temp;
  }
  
}


public class FMRadio extends Radio
{
  // instance variables
  private static final double MAX_FREQ = 109.9;
  private static final double MIN_FREQ = 85.9;
  private static final double INCREMENT = 0.2;
  
  public FMRadio()
  {   
  }
  
  /*
   * 
   * 
   */ 
  public double getMax_Freq() {return MAX_FREQ;}
  
  /*
   * 
   * 
   */  
  public double getMin_Freq() {return MIN_FREQ;}
  
  /*
   * 
   * 
   */  
  public double getIncrement() {return INCREMENT;}
  
  /*
   * 
   * 
   */  
  public String toString()
  {
    return "FM" + super.toString();
  }
}


public class AMRadio extends Radio
{
  // instance variables
  private static final double MAX_FREQ = 1650;
  private static final double MIN_FREQ = 510;
  private static final double INCREMENT = 10;
  
  /*
   * default constructor 
   */
  public AMRadio()
  {
  }
  
  /*
   *  Sets the Max Frequency
   * 
   * @return - returns Max Frequency
   */
  public double getMax_Freq() {return MAX_FREQ;}
  
  /*
   * Sets the Min Frequency
   * 
   * @return - returns the Min Frequency
   */
  public double getMin_Freq() {return MIN_FREQ;}
  
    
  /*
   * Sets the Increment
   * 
   * @return - returns the Increment
   */
  public double getIncrement() {return INCREMENT;}
  
    
  /*
   *
   * 
   * @return - returns a string
   */
  public String toString()
  {
    return "AM" + super.toString();
  }
}


public abstract class Radio
{
  // instance variables
  private double currentFrequency;
  
  /*
   * Default Constructor
   * 
   */
  public Radio()
  {
    currentFrequency = getMin_Freq();
  }

  /*
   *
   * @return - returns the Min Frequency
   */
  public abstract double getMax_Freq();
  
  /*
   *
   * @return - returns the Max Frequency
   */  
  public abstract double getMin_Freq();
  
  /*
   *
   * @return - reurns the Increment
   */  
  public abstract double getIncrement();
  
  /*
   *
   * @param - moves the frequency up
   */  
  public void up()
  {
    currentFrequency = currentFrequency + getIncrement();
    if (currentFrequency > getMax_Freq())
    {
      currentFrequency = getMin_Freq();
    }
  }
  
  /*
   *
   * @param - moves the frequency down
   */  
  public void down()
  {
    currentFrequency = currentFrequency - getIncrement();
    if (currentFrequency < getMin_Freq())
    {
      currentFrequency = getMax_Freq();
    }
  }
  
  /*
   *
   * @return - returns the currentFrequency
   */  
  public double getCurrentFrequency()
  {
    return currentFrequency;
  }
  
  /*
   *
   * @param - sets the currentFrequency
   */  
  public void setCurrentFrequency(double freq)
  {
    currentFrequency = freq;
  }
  
  /*
   *
   * @returns - returns a string
   */  
  public String toString ()
  {
    return  " " + currentFrequency;
  }
  
  
}

Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: can not find symbol

Posted 13 October 2012 - 08:28 AM

View PostAceWindgar1285, on 13 October 2012 - 04:53 PM, said:

All the classes are to work together. The pushButton method is in the FMPushButtonRadio.


But the type of selectedRadio is Radio, not FMPushButtonRadio, so you're only allowed to call methods on it that are defined in Radio.
Was This Post Helpful? 0
  • +
  • -

#5 AceWindgar1285  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 12-October 12

Re: can not find symbol

Posted 13 October 2012 - 09:37 AM

So what do i need to do to fix this issuse?
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2113
  • View blog
  • Posts: 3,235
  • Joined: 21-June 11

Re: can not find symbol

Posted 13 October 2012 - 09:42 AM

Add the method to Radio, change the type of selectedRadio or don't call the method on selectedRadio.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1