Question
Problems of the day The purpose of these small problems are to help you develop your craft. Each problem will only be open for a
Problems of the day
The purpose of these small problems are to help you develop your craft. Each problem will only be open for a fixed time period. The problems are short and will take anywhere from a few minutes up to half an hour.
For each problem you will be provided with sample inputs and corresponding outputs. All input is done via the console (unless specified otherwise) and all output is to be done to the console as well.
Your code must run without syntax errors. If it does not, you will receive a 0 on that portion of the problem.
Instructions
Way to go! You are in a class of your own! We will give you the main method, but you will be creating the entire class object from start to finish.
This week we will be working in the Museum of Natural History. Everyone is interested in seeing Gus the Gopher Tortoise (Link). As he is getting a bit old (over 95 years!), people rush to meet this fine tortoise.
To keep track of the number of visitors that meet up with Gus each day, we need to keep an accurate tally. You will be creating the class `TallyCounter` which we will use and modify throughout the week. Details for this class are given below.
Details
Input
In the file `TallyCounter.java` you will create the TallyCounter class. This class will require field necessary to keep track of a count of museum visitors. The counter must start at zero.
Processing
The TallyCounter must keep track of the count. You will create the necessary field members for all needs of the class.
A TallyCounter has two methods (so far!): 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.
You will need to set up the TallyCounter class, including field members, constructors and methods. The main method of PoD.java will instantiate a new TallyCounter and read in methods to call.
Output
The get() method returns an integer value.
Sample input/output:
Activity in Main | Activity in TallyCounter |
---|---|
Instantiate new TallyCounter increment increment increment get | count initially set to 0 count increase by 1 to 1 count increase by 1 to 2 count increase by 1 to 3 returns value 3 (count) |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started