Question: Task # 2 : TallyCounter Class / TallyCounterDemo In this project, you will be including two classes, a concrete class called TallyCounter and a demo

Task #2: 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.
Step1:
your concrete class will contain:
-two instance variables :
counter: of type int (public int counter =0;)
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 5 by invoking increaseCounter method 5 times, then display the counter.
Step 2:
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 4 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!