A counter variable is normally used in a program to keep track of the current count value.Create your own counter data type which is able to perform common counter operations such as increment (by one) the counter value and decrement (by one) the counter value. It is also able to set the counter to a specific value and to retrieve the counter value. The minimum value the counter can attain is zero, while the maximum value attained is stored in attribute maxValue. The class should have the following private members (attributes): (first picture) In the main program, test the workablity of your member functions by first setting an initial value to the counter. Display this value before proceeding. Then test other functions by randomly incrementing and decrementing the object’s value. Be sure to keep track of your actions. At the same time you should also make sure that your minimum value should not be less than zero. Once this is reached you will not be allowed to do further decrements. Consequently, the maximum value should also be maintained. The user should always ensure that the current value does not exceed the maximum value. If this happens no more increments will be allowed. Display appropriate comments for these two cases. Finally, when there are no more increments or decrements to do, you should print the final value or the set of the operations. For purposes of reusability, separate the driver, specification and implementation files

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter5: Making Decisions
Section: Chapter Questions
Problem 8PE
icon
Related questions
Question

A counter variable is normally used in a program to keep track of the current count value.Create your own counter data type which is able to perform common counter operations such as increment (by one) the counter value and decrement (by one) the counter value. It is also able to set the counter to a specific value and to retrieve the counter value. The minimum value the counter can attain is zero, while the maximum value attained is stored in attribute maxValue. The class should have the following private members (attributes):

(first picture)

In the main program, test the workablity of your member functions by first setting an initial value to the counter. Display this value before proceeding. Then test other functions by randomly incrementing and decrementing the object’s value. Be sure to keep track of your actions. At the same time you should also make sure that your minimum value should not be less than zero. Once this is reached you will not be allowed to do further decrements. Consequently, the maximum value should also be maintained. The user should always ensure that the current value does not exceed the maximum value. If this happens no more increments will be allowed. Display appropriate comments for these two cases. Finally, when there are no more increments or decrements to do, you should print the final value or the set of the operations. For purposes of reusability, separate the driver, specification and implementation files

Initial value of counter: 5
Maximum value of counter: 10
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 1
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Sorry, cannot proceed.. the current value already reach zero value
Enter [1] For increment [2] For decrement [0] Quit: 1
Enter [1] For increment [2] For decrement [0] Quit: 1
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 2
Enter [1] For increment [2] For decrement [0] Quit: 1
Enter [1] For increment [2] For decrement [0] Quit: 0
Thank you to use the system
Current value of the counter = 1
The number of successful increment = 4
The number of successful decrement
= 8
Transcribed Image Text:Initial value of counter: 5 Maximum value of counter: 10 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 1 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Sorry, cannot proceed.. the current value already reach zero value Enter [1] For increment [2] For decrement [0] Quit: 1 Enter [1] For increment [2] For decrement [0] Quit: 1 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 2 Enter [1] For increment [2] For decrement [0] Quit: 1 Enter [1] For increment [2] For decrement [0] Quit: 0 Thank you to use the system Current value of the counter = 1 The number of successful increment = 4 The number of successful decrement = 8
Attribute
Description
int count
the counter value
int maxValue
the maximum counter value
The class should also have the following member functions (methods):
Attribute
Description
increment
Increments the counter
decrement
Decrement the counter
setCount
Sets the counter value
setMaxVal
Sets the maximum value
getCount
Returns the count
getMaxValue
Returns the maximum value
Transcribed Image Text:Attribute Description int count the counter value int maxValue the maximum counter value The class should also have the following member functions (methods): Attribute Description increment Increments the counter decrement Decrement the counter setCount Sets the counter value setMaxVal Sets the maximum value getCount Returns the count getMaxValue Returns the maximum value
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT