Results 1 to 3 of 3
Thread: Program not working!!
- 01-18-2014, 02:34 AM #1
Member
- Join Date
- Jan 2014
- Posts
- 1
- Rep Power
- 0
Program not working!!
Hello everybody!!
I am new to Java, wrote my first program last week. My program is compiling but it is not giving me the result I was hoping for. I would appreciate it if somebody could point out to my mistake.
Thanks.
public class Counter
{
int counter=0;
int stepValue;
public Counter(int step)
{
step=stepValue;
}
public void increase(){
counter = counter+stepValue;
}
public void decrease(){
counter = counter-stepValue;
}
public int getCount(){
return counter;
}
public static void main(String[] args)
{
Counter counter = new Counter(1); //create a new counter with a step value of 1
counter.increase(); //add 1
System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());
counter.increase(); //add 1
System.out.println("Expected Count: 2 -----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 1
System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());
counter = new Counter(10); //create a new counter with a step value of 10
System.out.println("Expected Count: 0 -----> Actual Count: " + counter.getCount());
counter.increase(); //add 10
System.out.println("Expected Count: 10 ----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 10
System.out.println("Expected Count: 0 -----> Actual Count: " + counter.getCount());
counter.decrease(); //subtract 10
System.out.println("Expected Count: -10 -----> Actual Count: " + counter.getCount());
}
}Last edited by JosAH; 01-18-2014 at 08:04 AM. Reason: reinstalled original text
- 01-18-2014, 02:40 AM #2
Senior Member
- Join Date
- Oct 2012
- Posts
- 176
- Rep Power
- 9
Re: Program not working!!
What is it giving you add please place your codes in
With the right know how, anything is possible
- 01-18-2014, 03:33 AM #3
▼ dafuq did I do?
- Join Date
- Dec 2013
- Posts
- 204
- Rep Power
- 0
Similar Threads
-
the count on my program is not working as i would like it to
By abi in forum New To JavaReplies: 5Last Post: 02-28-2013, 03:46 AM -
program not working
By Dax Le Foundry in forum New To JavaReplies: 7Last Post: 08-09-2011, 09:10 PM -
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 07:53 PM -
Driving me insane - Program not working as it should ><
By mainy in forum New To JavaReplies: 1Last Post: 08-27-2009, 02:20 PM -
My program is not working
By MICHAELABICK in forum New To JavaReplies: 6Last Post: 12-23-2008, 12:05 AM
Bookmarks