Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is causing my code to cause this 1 error in JGrasp? \"Television.java:59: c

ID: 3641112 • Letter: W

Question

What is causing my code to cause this 1 error in JGrasp?


"Television.java:59: class, interface, or enum expected
import java.util.Scanner;"

Help! Thanks.

john





// Television Class

// The purpose of this class is to model a television
// Your name and today's date
public class Television {
private final String MANUFACTURER ; //manufacturer of the TV
private final int SCREEN_SIZE ; //Screen size of the TV
private boolean powerOn; //power on/off button
private int channel; //channel
private int volume; //volume to increase/decrease
//two arguments constructor initializes all the attributes of the
//television class
public Television(String manu,int screen){
MANUFACTURER = manu;
SCREEN_SIZE = screen;
powerOn = false;
volume = 20;
channel = 2;
}
//returns the current volume
public int getVolume(){
return volume;
}
//return the current channel
public int getChannel(){
return channel;
}
//returns the manufacturer of the TV
public String getManufacturer(){
return MANUFACTURER;
}
//returns the screen-size
public int getScreenSize(){
return SCREEN_SIZE;
}
//sets the channel to a given number
public void setChannel(int ch){
channel=ch;
}
//sets the TV power on/off
public void power(){
powerOn = !powerOn;
}
//increases the TV volume by 1
public void increaseVolume(){
volume+=1;
}
//decreases the TV volume by 1
public void decreaseVolume(){
volume-=1;
}
} //end of the Television class


// TelevisionDemo.java

import java.util.Scanner;
/** This class demonstrates the Television class*/
public class TelevisionDemo {
public static void main(String[] args) {
//create a Scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
//declare variables
int station; //the user's channel choice
//declare and instantiate a television object
Television bigScreen = new Television("Toshiba", 55);
//turn the power on
bigScreen.power();
//display the state of the television
System.out.println("A " + bigScreen.getScreenSize() + " inch "+
bigScreen.getManufacturer() +
" has been turned on.");
//prompt the user for input and store into station
System.out.print("What channel do you want? ");
station = keyboard.nextInt();
//change the channel on the television
bigScreen.setChannel(station);
//increase the volume of the television
bigScreen.increaseVolume();
//display the the current channel and volume of the
//television
System.out.println("Channel: " +
bigScreen.getChannel() +
" Volume: " + bigScreen.getVolume());
System.out.println(
"Too loud!! I am lowering the volume.");
//decrease the volume of the television
bigScreen.decreaseVolume();
bigScreen.decreaseVolume();
bigScreen.decreaseVolume();
bigScreen.decreaseVolume();
bigScreen.decreaseVolume();
bigScreen.decreaseVolume();
//display the current channel and volume of the
//television
System.out.println("Channel: " +
bigScreen.getChannel() +
" Volume: " + bigScreen.getVolume());
System.out.println(); //for a blank line
//HERE IS TASK #5
Television portable=new Television("Sharp", 19);
portable.power();
//display the state of the television
System.out.println("A " + portable.getScreenSize() + " inch "+
portable.getManufacturer() +
" has been turned on.");
//prompt the user for input and store into station
System.out.print("What channel do you want? ");
station = keyboard.nextInt();
//change the channel on the television
portable.setChannel(station);
//decrease the volume of the television.
portable.decreaseVolume();
portable.decreaseVolume();
//display the current channel and volume of the
//television
System.out.println("Channel: " +
portable.getChannel() +
" Volume: " + portable.getVolume());
}
}

Explanation / Answer

If you are writing the whole code in a same file, place the import statement at top of the class declaration and save the file as TelevisionDemo.java. Create a new java class and save the following class as television.java, it will work fine. import java.util.Scanner; // Television Class // The purpose of this class is to model a television // Your name and today's date class Television { private final String MANUFACTURER; // manufacturer of the TV private final int SCREEN_SIZE; // Screen size of the TV private boolean powerOn; // power on/off button private int channel; // channel private int volume; // volume to increase/decrease // two arguments constructor initializes all the attributes of the // television class public Television(String manu, int screen) { MANUFACTURER = manu; SCREEN_SIZE = screen; powerOn = false; volume = 20; channel = 2; } // returns the current volume public int getVolume() { return volume; } // return the current channel public int getChannel() { return channel; } // returns the manufacturer of the TV public String getManufacturer() { return MANUFACTURER; } // returns the screen-size public int getScreenSize() { return SCREEN_SIZE; } // sets the channel to a given number public void setChannel(int ch) { channel = ch; } // sets the TV power on/off public void power() { powerOn = !powerOn; } // increases the TV volume by 1 public void increaseVolume() { volume += 1; } // decreases the TV volume by 1 public void decreaseVolume() { volume -= 1; } } // end of the Television class // TelevisionDemo.java /** This class demonstrates the Television class */ public class TelevisionDemo { public static void main(String[] args) { // create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in); // declare variables int station; // the user's channel choice // declare and instantiate a television object Television bigScreen = new Television("Toshiba", 55); // turn the power on bigScreen.power(); // display the state of the television System.out.println("A " + bigScreen.getScreenSize() + " inch " + bigScreen.getManufacturer() + " has been turned on."); // prompt the user for input and store into station System.out.print("What channel do you want? "); station = keyboard.nextInt(); // change the channel on the television bigScreen.setChannel(station); // increase the volume of the television bigScreen.increaseVolume(); // display the the current channel and volume of the // television System.out.println("Channel: " + bigScreen.getChannel() + " Volume: " + bigScreen.getVolume()); System.out.println("Too loud!! I am lowering the volume."); // decrease the volume of the television bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); bigScreen.decreaseVolume(); // display the current channel and volume of the // television System.out.println("Channel: " + bigScreen.getChannel() + " Volume: " + bigScreen.getVolume()); System.out.println(); // for a blank line // HERE IS TASK #5 Television portable = new Television("Sharp", 19); portable.power(); // display the state of the television System.out.println("A " + portable.getScreenSize() + " inch " + portable.getManufacturer() + " has been turned on."); // prompt the user for input and store into station System.out.print("What channel do you want? "); station = keyboard.nextInt(); // change the channel on the television portable.setChannel(station); // decrease the volume of the television. portable.decreaseVolume(); portable.decreaseVolume(); // display the current channel and volume of the // television System.out.println("Channel: " + portable.getChannel() + " Volume: " + portable.getVolume()); } } Output will look like the following: A 55 inch Toshiba has been turned on. What channel do you want? 59 Channel: 59 Volume: 21 Too loud!! I am lowering the volume. Channel: 59 Volume: 15 A 19 inch Sharp has been turned on. What channel do you want? 45 Channel: 45 Volume: 18

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote