counter. A tally counter object typically starts at zero and goes up increments of 1 up to 999. The only
other function of the counter should be to reset it to zero. Your class should have a single instance data
field that keeps track of the current tally. It should also include two constructors, a default constructor
that sets the tally to zero and a single-argument constructor that sets the tally to an integer value between
0 and 999. If the argument is not within that range, set the tally to zero. Write a mutator method that
increments the tally by one – if the tally is at 999, the next increment should “roll” the tally back to zero.
Another mutator should allow the tally to be reset to zero no matter what value it currently holds.
Include also an accessor method and a toString() method.
but i'm stuck with it here what i've got:
package question1and2;
public class TallyCounter{
int count;
public TallyCounter(){
count=0; }
//accessors
public int getValue(){return count;}
public String toString(){return "TallyCounter["+count+"]";}
//muttators
public void addOne(){
do{
count=count+1;;
}while(count<=999);}
public void reset(){
if(count>999)
count=0;}
public static void main(String[] args)
{
TallyCounter c1=new TallyCounter();
TallyCounter c2=new TallyCounter();
c2.addOne();
int result=c1.getValue();
System.out.println(c1);
System.out.println(c2);
System.out.println(result);
}
}

New Topic/Question
Reply



MultiQuote





|