Results 1 to 6 of 6
  1. #1
    Ecrisp is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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.

  3. #3
    Ecrisp is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Exclamation 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
    }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default 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.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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().

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: looking for feed back on my code(methods), thank you

    Java Code:
    //method will return Name brand
     public String getMANUFACTURER(String MANUFACTURER)
     {
     return MANUFACTURER;
     }
    It'll return the passed-in String. And it doesn't make sense to do that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Edit jar, see the code, edit code and back it as a jar
    By RichersooN in forum New To Java
    Replies: 1
    Last Post: 10-10-2011, 06:33 AM
  2. Is it possible to see code of java methods.
    By efozdel in forum New To Java
    Replies: 10
    Last Post: 08-25-2011, 08:46 AM
  3. Scriptlet Not Running on JSP after coming back from back button of browser
    By jason.3dmagic in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-23-2011, 08:44 AM
  4. Replies: 0
    Last Post: 03-21-2011, 10:46 AM
  5. I need a back and forward code
    By Jaymz in forum New To Java
    Replies: 9
    Last Post: 10-13-2008, 12:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •