• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counter, Char java programming task.  RSS feed

 
Josh Brand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Good morning/afternoon/evening. I am attempting to write a program Value that will multiply/add/subtract two numbers from the specified char type.

The desired output is;


Starting Application...
Creating Counter object with a starting value of 1 and a step size of 3
*** Counting up 5, operation is *
counter = 1
counter = 3
counter = 9
counter = 27
counter = 81
Creating Counter object with a starting value of 5
*** Counting up 2, operation is -
counter = 5
counter = 4
*** Counting up 2, operation is ?
counter = 3
Invalid operation: ?



I am getting;

Starting Application...
*** Counting up 5
fail
Creating Counter object with a starting value of 1
*** Counting up 2
counter = 5
fail
Creating Counter object with a starting value of 1
*** Counting up 2
counter = 4
counter = 4
counter = 4
Creating Counter object with a starting value of 1


Could anyone please point me in the right direction?

Thankyou very much!

 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating Counter object with a starting value of 1 and a step size of 3

That implies (to me, with no other information) that should be in the constructor, so the constructor should take two values, a starting value and a step value.

*** Counting up 5, operation is *

This then implies that the countUp method should take two values, a number of steps and an operation.

A couple of comments on the code itself.  Get your indentation right, as it's hard to follow the flow of poorly formatted code.
Also give your variables meaningful names.  Again, this helps people (including yourself) when reading the code.
 
Josh Brand
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Creating Counter object with a starting value of 1 and a step size of 3

That implies (to me, with no other information) that should be in the constructor, so the constructor should take two values, a starting value and a step value.

*** Counting up 5, operation is *

This then implies that the countUp method should take two values, a number of steps and an operation.

A couple of comments on the code itself.  Get your indentation right, as it's hard to follow the flow of poorly formatted code.
Also give your variables meaningful names.  Again, this helps people (including yourself) when reading the code.



Thank you David, this issue is now resolved. Thank you very much!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!