Results 1 to 4 of 4
  1. #1
    gto400no1 is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default Boolean and Method help on Homework

    Been trying to figure this out all afternoon, and need some help. In a nutshell my assignment is to write a program that defines a TV, by defining its brand, size, channel, volume, on, off, ect.

    I am to use a boolean to toggle the power on and off.
    I used the
    Java Code:
    {
    powerOn = !powerOn;
    }
    then I figured it should go like this
    Java Code:
    public void power(boolean powerOn);
    	{
    	boolean power = powerOn;
    	}
    Needless to say that dont work, got this result (note: red letter indicates where jgrasp pointed an arror to point out the error.
    Television.java:85: missing method body, or declare abstract
    public void power(boolean powerOn);

    Television.java:87: cannot find symbol
    symbol : variable power
    location: class Television
    power = powerOn;
    Next I have to create a "volume controller" that adds or reduces stated volume by one. This is what I did:
    Java Code:
    public void increaseVolume (int volume + 1)
    error
    Television.java:94: ')' expected
    public void increaseVolume (int volume + 1)

    Television.java:94: illegal start of type
    public void increaseVolume (int volume + 1)

    Television.java:94: <identifier> expected
    public void increaseVolume (int volume + 1)

    Television.java:94: ';' expected
    Thank you, I know the questions are dumb but Im very new to Java.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Let's see your entire program if possible.

  3. #3
    gto400no1 is offline Member
    Join Date
    Feb 2010
    Posts
    14
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;  // Needed for the Scanner class
    
    // Create class definition Television
    public class Television
    {
    		
    	// Declare the 2 constant fields in the UML diagram
    	private String MANUFACTURER;	// Television manufacturer
    	private int SCREEN_SIZE;		// Screen size of television
    	
    	// Declare remaining fields in the UML diagram
    	private boolean powerOn;		// Powers television on and off
    	private int channel;				// Selects televisions channel
    	private int volume;				// Increases and decreases television volume
    	public int setChannel;			// Accepts channel number input
    	
    
    	/**
    	* Constructor
    	* Defines television, states particular model by defining
    	* brand and size, also defines status of TV by declaring
    	* current state of TV, off, volume of 20 and on channel 2
    	*/
    	public Television(String brand, int size)
    	{
    	MANUFACTURER = brand;
    	SCREEN_SIZE = size;
    
    
    	powerOn = false;
    	volume = 20;
    	channel = 2;
    	
    	}
    	
    	// Create a Scanner object for keyboard input.
          Scanner keyboard = new Scanner(System.in);
    	
    	/**
    	* Methods
    	*/
    	
    	// Method will return the value stored in the volume field
    	public int getVolume()
    	{
    		return volume;
    	}
    	
    	// Method will return the value stored in the channel field
    	public int getChannel()
    	{
    		return channel;
    	}
    	
    	// Method will return the constant value stored in the MANUFACTURER field
    	public String getMANUFACTURER()
    	{
    		return MANUFACTURER;
    	}
    	
    	// Method  will return the constant value stored in the SCREEN_SIZE field
    	public int getScreenSize()
    	{
    		return SCREEN_SIZE;
    	}
    	
    	// Television controlls
    	{	
    	System.out.print("Input channel: ");
          setChannel = keyboard.nextInt();
    		setChannel = channel;
    	}
    	{	
    	powerOn = !powerOn;
    	}
    	
    	// Powers on TV
    	public void power(boolean powerOn);
    	{
    	power = powerOn;
    	}
    
    	public void increaseVolume (int volume + 1)
    
    }
    Thanks in advanced!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    OK, everything from here on is fercockt:

    Java Code:
     // Television controlls
     {   
     System.out.print("Input channel: ");
       setChannel = keyboard.nextInt();
         setChannel = channel;
     }
     {   
     powerOn = !powerOn;
     }
     
     // Powers on TV
     public void power(boolean powerOn);
     {
     power = powerOn;
     }
    
     public void increaseVolume (int volume + 1)
    
    }
    You have two method bodies without the head:
    Java Code:
     {   
     System.out.print("Input channel: ");
       setChannel = keyboard.nextInt();
         setChannel = channel;
     }
     {   
     powerOn = !powerOn;
     }
    here you have a method head that ends in a semicolon- a no no, and also try to set a non-existing variable "power":
    Java Code:
     // Powers on TV
     public void power(boolean powerOn);
     {
     power = powerOn;
     }
    
    }
    And then you have a code statement that is sitting out in the middle of no-where, not in a method body or anything:
    Java Code:
     public void increaseVolume (int volume + 1)
    
    }
    I'm guessing that part of this code was given to you, and part you've tried to create yourself.

    You can't randomly type in words and hope it will magically work in programming; it just doesn't work that way. I think that you'll need to completely scrap your additions here, and then you need to re-study your notes and your text before attempting to add any more code. When you do add code, only add a small amount at a time, test the code frequently to see if it compiles, and if it doesn't fix the errors before adding any more code. If you don't do it this way, you'll end up with a rat's nest of errors like we see here.

    Good luck!

Similar Threads

  1. Boolean method help
    By syferite in forum New To Java
    Replies: 6
    Last Post: 10-28-2009, 01:32 PM
  2. Testing boolean method
    By SteroidalPsycho in forum New To Java
    Replies: 7
    Last Post: 10-23-2009, 04:12 AM
  3. destroyApp(boolean unconditional) method
    By thienphongvu in forum CLDC and MIDP
    Replies: 1
    Last Post: 08-07-2009, 09:14 AM
  4. im not familiar with boolean in method...
    By PureAwesomeness in forum New To Java
    Replies: 19
    Last Post: 02-22-2009, 02:36 AM
  5. [SOLVED] boolean method problem
    By shadowblade19 in forum New To Java
    Replies: 6
    Last Post: 11-30-2008, 02:01 AM

Posting Permissions

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