Question: I had to copy a Java program from my textbook, but I'm getting compile errors. I realise the program has no main method, It wasn't
I had to copy a Java program from my textbook, but I'm getting compile errors. I realise the program has no main method, It wasn't supose to run, just compile. I can't figure out what the problem is. Here is a copy of the program.
public class TV { int channel = 1; // Default channel is 1 int volumeLevel = 1; // Default volume level is 1 boolean on = false; // TV is off
public TV() { }
public void turnOn() { on = true; }
public void turnOff() { on = false; } public void setChannel(int newChannel) { if (on && newChannel >= 1 && newChannel <= 120) channel = newChannel; }
public void setVolume(int newVolumeLevel) { if (on && newVolumeLevel >= 1 && newVolumeLevel <= 7) volumeLevel = newVolumeLevel; }
public void channelUp() { if (on && channel < 120) channel++; }
public void channelDown() { if (on && channel > 1) }
public void volumeUp() { if (on && volumeLevel < 7) volumeLevel++; }
public void volumeDown() { if (on && volumeLevel > 1) volumeLevel; } }
This is a copy of the error messages
----jGRASP exec: javac -g TV.java TV.java:41: error: illegal start of statement } ^ TV.java:50: error: illegal character: '\u2014' volumeLevel; ^ TV.java:50: error: not a statement volumeLevel; ^ TV.java:50: error: illegal character: '\u2013' volumeLevel; ^ 4 errors
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
