Question: import java.util.*; public class PoD { public static void main (String [] args ) { Scanner in = new Scanner( System.in ); PrettyTally tally =

![[] args ) { Scanner in = new Scanner( System.in ); PrettyTally](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4e08725e21_29466f4e086a9431.jpg)
import java.util.*;
public class PoD {
public static void main (String [] args ) { Scanner in = new Scanner( System.in ); PrettyTally tally = new PrettyTally(in.next()); while (in.hasNext()) { String nextTask = in.next(); if (nextTask.equals("increment")) { tally.increment(); } else if (nextTask.equals("toString")) { System.out.println(tally); } else if (nextTask.equals("decrement")) { tally.decrement(); } } in.close(); } }
Instructions Today's task is to subclass the TallyCounter class once to make a really useful and "pretty" tally counter. This time you will not only be able to count up, but also decrease the count when someone leaves the room. Not only that, but the updated toString will output a bit more useful information. The Museum of Natural History needs your help once more. They would like you to help pretty up their tally counter (call it a PrettyTally) and make it more useful in a variety of situations. They need you to subclass the original TallyCounter. They need you to modify it in two ways. First, when they instantiate the PrettyTally, they'd like to specify what they are tallying by passing a string to the constructor that names what they are tallying. Also, they would like to be able to allow for decreasing the count within an exhibit with the use of a decrement method. You will subclass the TallyCounter class and implement a new tally counter called "PrettyTally which will meet those requirements. Details for this class are given below. Recall: The Tally Counter keeps track of the count. A Tally Counter has two methods: the increment() method and the get() method. These methods do the following: - Increment(): This method increases the total count by one. This method is used when a new visitor comes to visit Gus. One more visitor, one more push of the TallyCounter button to Increment the count by one. get(): This method returns an integer count of the number of visitors that have been by to see Gus so far. Details Input In the file Pretty Tally.java you will subclass the TallyCounter class. You will add the functionality to decrement the counter. Just like the TallyCounter, PrettyTally must keep track of the count. You will create the necessary field members for all needs of the class. PrettyTally constructor will expect a new String parameter tallyObject to keep track of what is being tallied. Processing A PrettyTally will have all the same functionality of the TallyCounter, but it will also have a decrement() method. This method decreases the total count by one. If a visitor chooses to leave an exhibit, we can decrement the count by one. The form of the new toString should be the current tally count and the name of the objects being tallied, separated by a space. You will need to set up the PrettyTally subclass, including any new field members, constructor and method. The main method of PoD.Java will instantiate a new PrettyTally and read in methods to call. Output Ouput is handled for you in this problem. Sample Input/output: Sample Input Sample Output bikes count initially set to O, tallyObject set to "bikes" toString returns "O bikes" increment count increased by 1 to 1 increment count increased by 1 to 2 decrement count decreased by 1 to 1 increment count increased by 1 to 2 toString returns "2 bikes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
