-4

I am following a Book in this book the code is given i tried to compile it but it shows errors here is the Code-

  class TapeDeck {
    boolean canRecord = false;

    void playTape() {
        System.out.println("tape recording");
    }

    void recording() {
        System.out.println("tape recording");
    }
}
class TapeDeckTestDrive {
    public static void main (String [] args) {
        TapeDeck t = new TapeDeck( );
        t.canRecord = true;
        t.play();

        if (t.canRecord == true) {
            t.recordTape();
        }
    }
} 

and an error is....

    TapeDeck.java:16: error: cannot find symbol
                t.play();
                 ^
  symbol:   method play()
  location: variable t of type TapeDeck
TapeDeck.java:19: error: cannot find symbol
                        t.recordTape();
                         ^
  symbol:   method recordTape()
  location: variable t of type TapeDeck
2 errors
Tom
  • 16,842
  • 17
  • 45
  • 54
user16674
  • 11
  • 4
  • `TapeDeck` doesn't have `play` and `recordTape` methods. – janos Nov 13 '16 at 11:40
  • Your functions are playTape() and recording(). You're calling play() and recordTape(). – Bijay Gurung Nov 13 '16 at 11:40
  • after fixing it i have an error like this.. 'Error: Main method not found in class TapeDeck, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application' – user16674 Nov 13 '16 at 11:54
  • Just copy and paste this message into a search engine ... – Tom Nov 13 '16 at 11:54
  • Don't change the subject of your existing question. If you have a new one, then ask a new question. And as I already wrote: ***DO SOME RESEARCH***. Being new is no valid excuse for being lazy. Your questions have been asked millions of times, so go and look for them and learn from them. – Tom Nov 13 '16 at 12:02

2 Answers2

0

It's because play() is not a method of class TapeDeck. However, you do have the following method:

void playTape() {
    System.out.println("tape recording");
}

If this is the method that you meant, then change t.play() to t.playTape(). If not, you will need to create play() in TapeDeck.

Smittey
  • 2,475
  • 10
  • 28
  • 35
0

You're getting this because you're trying to call methods that TapeDeck doesn't have: play() and recordTape(). Most likely the book you're referring to just didn't show the implementation for the sake of size.

You can just add those methods to your TapeDeck class, or change the methods you're calling from your main method to the ones already in your TapeDeck class (playTape() and recording()).

Gulllie
  • 523
  • 6
  • 21