Results 1 to 4 of 4
- 02-21-2010, 11:01 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 14
- Rep Power
- 0
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
then I figured it should go like thisJava Code:{ powerOn = !powerOn; }
Needless to say that dont work, got this result (note: red letter indicates where jgrasp pointed an arror to point out the error.Java Code:public void power(boolean powerOn); { boolean power = powerOn; }
Next I have to create a "volume controller" that adds or reduces stated volume by one. This is what I did: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;
errorJava Code:public void increaseVolume (int volume + 1)
Thank you, I know the questions are dumb but Im very new to Java.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
-
Let's see your entire program if possible.
- 02-21-2010, 11:28 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 14
- Rep Power
- 0
Thanks in advanced!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) }
-
OK, everything from here on is fercockt:
You have two method bodies without the head: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) }
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:{ System.out.print("Input channel: "); setChannel = keyboard.nextInt(); setChannel = channel; } { powerOn = !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:// Powers on TV public void power(boolean powerOn); { power = powerOn; } }
I'm guessing that part of this code was given to you, and part you've tried to create yourself.Java Code:public void increaseVolume (int volume + 1) }
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
-
Boolean method help
By syferite in forum New To JavaReplies: 6Last Post: 10-28-2009, 01:32 PM -
Testing boolean method
By SteroidalPsycho in forum New To JavaReplies: 7Last Post: 10-23-2009, 04:12 AM -
destroyApp(boolean unconditional) method
By thienphongvu in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 09:14 AM -
im not familiar with boolean in method...
By PureAwesomeness in forum New To JavaReplies: 19Last Post: 02-22-2009, 02:36 AM -
[SOLVED] boolean method problem
By shadowblade19 in forum New To JavaReplies: 6Last Post: 11-30-2008, 02:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks