Commit 06fb2a2a authored by Trisha Gee's avatar Trisha Gee
Browse files

[Ch2] Fully working code for the Be The Compiler exercises.

parent 15227aeb
Loading
Loading
Loading
Loading

src/main/java/ch2/DVDPlayer.java

deleted100644 → 0
+0 −23
Changes for src/main/java/ch2/DVDPlayer.java: 0 added lines, 23 removed lines.
Original line number Diff line number Diff line
package ch2;

class DVDPlayer {

  boolean canRecord = false;

  void recordDVD() {
    System.out.println("DVD recording");
  }
}

class DVDPlayerTestDrive {
  public static void main(String[] args) {

    DVDPlayer d = new DVDPlayer();
    d.canRecord = true;
    d.playDVD();

    if (d.canRecord == true) {
      d.recordDVD();
    }
  }
}
 No newline at end of file
+27 −0
Changes for src/main/java/ch2/Episode.java: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch2;

class Episode {
  int seriesNumber;
  int episodeNumber;

  void play() {
    System.out.println("Playing episode " + episodeNumber);
  }

  void skipIntro() {
    System.out.println("Skipping intro...");
  }

  void skipToNext() {
    System.out.println("Loading next episode...");
  }
}

class EpisodeTestDrive {
  public static void main(String[] args) {
    Episode episode = new Episode();
    episode.seriesNumber = 4;
    episode.play();
    episode.skipIntro();
  }
}
 No newline at end of file
+26 −0
Changes for src/main/java/ch2/StreamingSong.java: 26 added lines, 0 removed lines.
Original line number Diff line number Diff line
package ch2;

class StreamingSong {
  String title;
  String artist;
  int duration;

  void play() {
    System.out.println("Playing song");
  }

  void printDetails() {
    System.out.println("This is " + title +
                       " by " + artist);
  }
}

class StreamingSongTestDrive {
  public static void main(String[] args) {
    StreamingSong song = new StreamingSong();
    song.artist = "The Beatles";
    song.title = "Come Together";
    song.play();
    song.printDetails();
  }
}
 No newline at end of file

src/main/java/ch2/TapeDeck.java

deleted100644 → 0
+0 −26
Changes for src/main/java/ch2/TapeDeck.java: 0 added lines, 26 removed lines.
Original line number Diff line number Diff line
package ch2;

class TapeDeck {

  boolean canRecord = false;

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

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

class TapeDeckTestDrive {
  public static void main(String[] args) {

    t.canRecord = true;
    t.playTape();

    if (t.canRecord == true) {
      t.recordTape();
    }
  }
}
 No newline at end of file