Results 1 to 6 of 6
- 04-02-2012, 02:51 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
looking for feed back on my code(methods), thank you
Hello, I am working on a project involving constructor, accessor, and mutator methods.
I have a file with the code I have written, Television, and a file with a code my professor provided,TelevisionDemo. The main method is in TelevsionDemo, and it is suppose to compile and run with the Television class. However, when I attempt to compile I get error messages stating that "method power in class Television cannot be applied to given types", and "TelevisionDemo cannot find the symbol(s)".
************************************************** *****************************
//my code
import java.util.*;
public class Television
{
//declare constant fields
public String MANUFACTURER; //brand name
public int SCREEN_SIZE; //size of screen
//declare other fields
public static boolean powerOn;
public static int channel;
public static int volume;
//declare scanner
Scanner keyboard = new Scanner(System.in);
//to create an object, constructor definition. declares brand name,
//size, and current state of the television
public Television(String brand, int size)
{
MANUFACTURER = brand;
SCREEN_SIZE = size;
brand = "";
powerOn = false;
channel = 2;
volume = 20;
}
//accessor methods
//methods to control the state of the televisions attributes
//method to return volume
public int getVolume()
{
return volume;
}
//method to return channel
public int getChannel()
{
return channel;
}
//method will return Name brand
public String getMANUFACTURER()
{
return MANUFACTURER;
}
//method will return size of screen
public int getScreenSize()
{
return SCREEN_SIZE;
}
//mutator methods
//set channel allows the manipulation of the channel
public void setChannel(int channel)
{
channel = keyboard.nextInt();
}
//power allows you to turn your tv on or off
public void power(boolean powerOn)
{
powerOn = !powerOn;
}
//increase and decrease volume lets you change the volume
public void increaseVolume(int volume)
{
volume = volume++;
}
public void decreaseVolume(int volume)
{
volume = volume--;
}
}
************************************************** ***************
//code provided by professor
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 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 WHERE YOU WILL INSERT YOUR CODE TO PERFORM TASK #5
}
}
Thank you kindly
- 04-02-2012, 05:07 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: looking for feed back on my code(methods), thank you
Could you please format the code that you've post so that easier for us to read? And also please tell us exactly which line number that give errors in your program.
Website: Learn Java by Examples
- 04-02-2012, 05:52 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Re: looking for feed back on my code(methods), thank you
yes, sorry. I have worked with it since the first post and now I am only receiving one error on line 29 of TelevisionDemo when I attempt to compile. However I feel that it is fault of my own code causing the error because like I said before the TelevisionDemo was provided by my professor. I hope this is easier to read, i have marked the line where the error occurs in red. Error message:
TelevisionDemo.java:29: error: cannot find symbol bigScreen.getMANUFACTURER() + "has been turned on");
symbol: method getMANUFACTURER()
location: variable bigScreen of type Television
//my code
import java.util.*;
public class Television
{
//declare constant fields
public String MANUFACTURER; //brand name
public int SCREEN_SIZE; //size of screen
//declare other fields
public static boolean powerOn;
public static int channel;
public static int volume;
//*********************************************
//declare scanner
Scanner keyboard = new Scanner(System.in);
//to create an object, constructor definition. declares brand name,
//size, and current state of the television
public Television(String brand, int size)
{
MANUFACTURER = brand;
SCREEN_SIZE = size;
powerOn = false;
channel = 2;
volume = 20;
}
//************************************************** *******
//accessor methods
//methods to control the state of the televisions attributes
//method to return volume
public int getVolume()
{
return volume;
}
//method to return channel
public int getChannel()
{
return channel;
}
//method will return Name brand
public String getMANUFACTURER(String MANUFACTURER)
{
return MANUFACTURER;
}
//method will return size of screen
public int getScreenSize()
{
return SCREEN_SIZE;
}
//mutator methods
//set channel allows the manipulation of the channel
public void setChannel(int channel)
{
channel = keyboard.nextInt();
}
//power allows you to turn your tv on or off
public void power()
{
powerOn = !powerOn;
}
//increase and decrease volume lets you change the volume
public void increaseVolume()
{
volume = volume++;
}
public void decreaseVolume()
{
volume = volume--;
}
}
//Code provided by professor
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 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."); //error occurs here
//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 WHERE YOU WILL INSERT YOUR CODE TO PERFORM TASK #5
}
}
- 04-02-2012, 06:41 AM #4
Re: looking for feed back on my code(methods), thank you
Go through the forum FAQs and discover how to post your code so that it retains its formatting.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-02-2012, 07:30 AM #5
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: looking for feed back on my code(methods), thank you
Please remember that Java is a case sensitive in its nature, so getManufacturer() is a different method to getMANUFACTURER().
Website: Learn Java by Examples
- 04-02-2012, 07:52 AM #6
Re: looking for feed back on my code(methods), thank you
It'll return the passed-in String. And it doesn't make sense to do that.Java Code://method will return Name brand public String getMANUFACTURER(String MANUFACTURER) { return MANUFACTURER; }
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Edit jar, see the code, edit code and back it as a jar
By RichersooN in forum New To JavaReplies: 1Last Post: 10-10-2011, 05:33 AM -
Is it possible to see code of java methods.
By efozdel in forum New To JavaReplies: 10Last Post: 08-25-2011, 07:46 AM -
Scriptlet Not Running on JSP after coming back from back button of browser
By jason.3dmagic in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 06-23-2011, 07:44 AM -
hi can you give me some idea to move this code back to soabean (Presentation bean). c
By bharanik in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-21-2011, 09:46 AM -
I need a back and forward code
By Jaymz in forum New To JavaReplies: 9Last Post: 10-12-2008, 11:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks