Question: Task # 2 : TallyCounter Class / TallyCounterDemo In this project, you will be including two classes, a concrete class called TallyCounter and a demo
Task #: TallyCounter Class TallyCounterDemo
In this project, you will be including two classes, a concrete class called TallyCounter and a demo class TallyCounterDemo that houses the main method.
Step:
your concrete class will contain:
two instance variables :
counter: of type int public int counter ;
color: of type String public String color;
three public void instance methods:
increaseCounter: this method increases the counter
displayCounter: this method prints the counter
displayColor: this method prints the color
no constructor
In the main method of the Demo class:
instantiate two TallyCounter objects named concert and bus, assign color values to each object.
Print the counter and color of each object using the displayColor and displayCounter methods.
Increase the concert counter by by invoking increaseCounter method times, then display the counter.
Step :
Change the access modifier for the instance variables from public to private, and now you will have errors.
You will not be able to access the instance variables from outside the class.
To solve this problem you will need to write methods called accessors and mutators getters and setters
setColor, setCounter
getColor, getCounter
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
