•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,982 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 593 | Replies: 3 | Solved
![]() |
| |
•
•
Join Date: Dec 2007
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 0
Hi Please help me with this problem
Write the definition of a class Play containing:
An instance variable counter of type int , initialized to 0.
A method called increment that adds one to the instance variable counter . It does not accept parameters or return a value.
A method called getValue that doesn't accept any parameters. It returns the value of the instance variable counter .
Any advice would be appreciated
Write the definition of a class Play containing:
An instance variable counter of type int , initialized to 0.
A method called increment that adds one to the instance variable counter . It does not accept parameters or return a value.
A method called getValue that doesn't accept any parameters. It returns the value of the instance variable counter .
java Syntax (Toggle Plain Text)
my code: public class play { int counter =0; public void increment() public getValue(){ //something is wrong here return counter;} }
Any advice would be appreciated
Last edited by cscgal : Dec 2nd, 2007 at 4:24 pm. Reason: Added code tags
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
Ok, your method increment needs to increment that counter variable, which you aren't doing...
There actually isn't anything wrong with the method getValue.
Try to think about what should happen in the increment method and then post again what you have if it isn't working.
[wrong]Why did you think there was something wrong with your return statement?[/wrong]
Ok, there is something wrong there, every method in Java needs to know what its return value is.
Black Box.
There actually isn't anything wrong with the method getValue.
Try to think about what should happen in the increment method and then post again what you have if it isn't working.
java Syntax (Toggle Plain Text)
public void increment() { // something needs to happen here. }
[wrong]Why did you think there was something wrong with your return statement?[/wrong]
Ok, there is something wrong there, every method in Java needs to know what its return value is.
Black Box.
Last edited by Black Box : Dec 2nd, 2007 at 4:53 pm.
•
•
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation:
Rep Power: 1
Solved Threads: 6
No problem, welcome to DaniWeb btw. 
If you're pretty new to Java, you might want to check out the sticky topic posted by sos at the top of this Java-forum. A lot of basic useful information which will take you to the next level in no time.
Black Box.

If you're pretty new to Java, you might want to check out the sticky topic posted by sos at the top of this Java-forum. A lot of basic useful information which will take you to the next level in no time.
Black Box.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- virtual string ToFileFormat() (C++)
- Am i writing my code properly? (Python)
- HELP writing structure and class definition - Visual C++ (C++)
- writing a class without the class declaration? (C++)
- Dynamic memory allocation homework (C++)
- Classes (C++)
Other Threads in the Java Forum
- Previous Thread: number coordinates help
- Next Thread: Hi I am a new user to java and would like an advise where to start.


Hybrid Mode