robnyr2317
10-21-2007, 04:46 PM
Im new to java and I need to make a constructor definition that has two parameters, a manufacturers brand and a screen size, the parameters have to bring in information. inside the constructor i have to assign the values taken in from the parameters to the corresponding fields. Here is what I have so far for the constructor but im not sure if it is even the right thing to start with
public class Television
{
private String MANUFACTURER;
private int SCREEN_SIZE;
boolean powerOn;
int channel ;
int volume;
public Television(String MANUFACTURER, int SCREEN_SIZE)
{
}
Here is the other file that is supposed to correspond with the constructor I am trying to make. Thanks for any help.
import java.util.Scanner;
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 instatiate 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() +
bigScreen.getManufacturer() +" has been turned on.");
//prompt the user for input and store into station
System.out.println("What channel do you want? ");
station = keyboard.nextInt();
//change the channel on the television
bigScreen.setChannel(station);
//display 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
}
}
public class Television
{
private String MANUFACTURER;
private int SCREEN_SIZE;
boolean powerOn;
int channel ;
int volume;
public Television(String MANUFACTURER, int SCREEN_SIZE)
{
}
Here is the other file that is supposed to correspond with the constructor I am trying to make. Thanks for any help.
import java.util.Scanner;
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 instatiate 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() +
bigScreen.getManufacturer() +" has been turned on.");
//prompt the user for input and store into station
System.out.println("What channel do you want? ");
station = keyboard.nextInt();
//change the channel on the television
bigScreen.setChannel(station);
//display 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
}
}