Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:43+00:00 2026-05-26T10:40:43+00:00

I’m having trouble visualizing the end product of this problem: Define a class called

  • 0

I’m having trouble visualizing the end product of this problem:

Define a class called Counter whose objects count things. An object of this class
records a count that is a nonnegative integer. Include methods to set the counter
to 0, to increase the count by 1, and to decrease the count by 1. Be sure that no
method allows the value of the counter to become negative. Include an accessor
method that returns the current count value and a method that outputs the
count to the screen. There should be no input method or other mutator methods.
The only method that can set the counter is the one that sets it to zero. Also,
include a toString method and an equals method. Write a program (or programs)
to test all the methods in your class definition.

Can someone better explain this problem for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:40:44+00:00Added an answer on May 26, 2026 at 10:40 am

    Write code that defines a class. The class’ name shall be Counter. (Think: what does this imply about the file name? Keep in mind that we will want this to be a public class so that we can use it for testing.) A Counter is used to count things (not surprising).

    To do this, each instance of the class will contain a “count” value. (Think: what would be a good name for this value? How do we make a separate value for each instance of a class, that belongs to the instances?) The value shall not be negative. (Obvious; how could you have a negative number of things?) You are expected to make sure that the value cannot become negative (this should happen automatically, if you are doing things in remotely normal ways).

    The class should provide the following functionality:

    • A method that sets the count value to 0. (Think: what is a good name for this method? It should be public of course, since it is part of how other code will use the class. Think: do you need any parameters for this method? If so, what?)

    • A method that increases the count by 1. (Think: as above.)

    • A method that decreases the count by 1. (Think: as above. Also, what happens if the count is already 0, given that we must not let it become negative? Decide what to do in this case.)

    • A method that returns the current count value. (This is called an “accessor”).

    • A method that displays the current count value. (Note: this is a very bad idea design-wise, but your assignment requires it. Hint: use one of the methods of System.out to output to the screen.)

    • A method called toString that returns a String representation of the counter. This should not take any parameters, and must return a String. (This is a standard piece of functionality that most objects in Java provide. Think: other than the count value, is there anything else that ought to be included in the string?)

    • A method called equals that compares the Counter to another Counter for equality. This method must take exactly one parameter, a Counter instance, and return a boolean indicating whether the two Counters are equal. (Think: what determines whether two counters are “equal”?)

    The class should NOT provide any of the following functionality:

    • Any other method that changes the value of the counter (especially not one that reads a value from standard input).

    Write a program that creates some Counter instances and uses their methods. The program should prove that your Counter class behaves as expected, by producing output that agrees with what you’d expect from reading the main program. (Hint: since this is Java, we will need another class for this program, with a public static void main(String[] args) method. Put it in another file. You may need to play around with package and import statements so that the main program can find your Counter class in the other file. Make sure you understand how to compile and run Java classes.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.