User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,585 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 2,953 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: 472 | Replies: 3 | Solved
Reply
Join Date: Dec 2007
Posts: 19
Reputation: Danii is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Danii Danii is offline Offline
Newbie Poster

writing a definition of a class

  #1  
Dec 2nd, 2007
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 .
  1. my code:
  2. public class play
  3. {
  4. int counter =0;
  5. public void increment()
  6. public getValue(){ //something is wrong here
  7. return counter;}
  8. }

Any advice would be appreciated
Last edited by cscgal : Dec 2nd, 2007 at 3:24 pm. Reason: Added code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation: Black Box is on a distinguished road 
Rep Power: 1
Solved Threads: 6
Black Box Black Box is offline Offline
Junior Poster in Training

Re: writing a definition of a class

  #2  
Dec 2nd, 2007
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.

  1. public void increment() {
  2. // something needs to happen here.
  3. }

[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 3:53 pm.
Reply With Quote  
Join Date: Dec 2007
Posts: 19
Reputation: Danii is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Danii Danii is offline Offline
Newbie Poster

Re: writing a definition of a class

  #3  
Dec 2nd, 2007
thanks Black Box I fixed it now tyty !!
Reply With Quote  
Join Date: Nov 2007
Location: Belgium
Posts: 62
Reputation: Black Box is on a distinguished road 
Rep Power: 1
Solved Threads: 6
Black Box Black Box is offline Offline
Junior Poster in Training

Re: writing a definition of a class

  #4  
Dec 2nd, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC