Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Java.

Tally counter that increases and decreases. Refer to screenshot.

 

Here is some code (class PoD):

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();
}
}

 

Class PrettyTally:

public class PrettyTally extends TallyCounter{

}

 

 

Class TallyCounter

import java.util.*;

public class TallyCounter {

protected int count=0;

public TallyCounter()
{
this.count = 0;
}

public void increment()
{
this.count++;
}

public int get()
{
return this.count;
}
}

### 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 **TallyCounter** keeps track of the count. A **TallyCounter** 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 `PrettyTally.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 `
expand button
Transcribed Image Text:### 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 **TallyCounter** keeps track of the count. A **TallyCounter** 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 `PrettyTally.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 `
### Input of the Test Case
```
1. bikes
2. increment
3. increment
4. increment
5. toString
6. decrement
7. toString
8. increment
9. increment
10. toString
```

### The Correct Output of the Test Case
```
1. 3 bikes
2. 2 bikes
3. 4 bikes
```
expand button
Transcribed Image Text:### Input of the Test Case ``` 1. bikes 2. increment 3. increment 4. increment 5. toString 6. decrement 7. toString 8. increment 9. increment 10. toString ``` ### The Correct Output of the Test Case ``` 1. 3 bikes 2. 2 bikes 3. 4 bikes ```
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education