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 9209133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:46:14+00:00 2026-06-18T00:46:14+00:00

OK so I have an issue with a homework problem. I’m building a class

  • 0

OK so I have an issue with a homework problem. I’m building a class that be used in a tester class provided by my instructor. Its nothing more than a basic counter. I’ve got the counter set up to where numbers passed by the tester to my class work fine and output is as expected. However my class must have the initial count set to 0 and a default increment/decrement of 1.

Here is my class:

public class Counter
{
    private int count;
    private int stepValue;

    /**
     * This method transfers the values called from CounterTester to instance variables
     * and increases/decreases by the values passed to it. It also returns the value
     * of count. 
     *
     * @param args
     */ 
    public Counter (int initCount, int value)
    {       
        count=initCount;
        stepValue=value;
    }   

    public void increase ()
    {
        count = count + stepValue;
    }

    public void decrease ()
    {
        count = count - stepValue;
    }

    public int getCount()
    {
        return count;
    }

}

Here is the tester class:

public class CounterTester
{

    /**
     * This program is used to test the Counter class and does not expect any
     * command line arguments. 
     *
     * @param args
     */
    public static void main(String[] args)
    {
        Counter counter = new Counter();

        counter.increase();
        System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());

        counter.increase();
        System.out.println("Expected Count: 2 -----> Actual Count: " + counter.getCount());

        counter.decrease();
        System.out.println("Expected Count: 1 -----> Actual Count: " + counter.getCount());


        counter = new Counter(3, 10);
        System.out.println("Expected Count: 3 -----> Actual Count: " + counter.getCount());

        counter.increase();
        System.out.println("Expected Count: 13 ----> Actual Count: " + counter.getCount());

        counter.decrease();
        System.out.println("Expected Count: 3 -----> Actual Count: " + counter.getCount());

        counter.decrease();
        System.out.println("Expected Count: -7 ----> Actual Count: " + counter.getCount());
    }

}
  • 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-06-18T00:46:15+00:00Added an answer on June 18, 2026 at 12:46 am

    You don’t have a no arg constructor in your Counter class for the first time you instantiate it, so do

    Counter counter = new Counter(0,1);
    

    Which should set the initial and step values.

    Or you can provide a no-arg constructor:

    public class Counter
    {
      private int count;
      private int stepValue;
    
      public Counter () { //no argument constructor - must be explictly made now
        count=0;
        stepValue = 1;
      }
    
      public Counter (int initCount, int value)
      {       
        count=initCount;
        stepValue=value;
      }  
    
      //rest of code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework problem that I have. I have been doing some research
I have this problem for homework and the issue I'm having is when I
I have an issue and NO it is not homework, it's just a programmer
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
The following issue is that i have 3 calendar controls (different ID) in a
I have issue with a strange url request to my site.. that may come
For my homework assignment for my C++ class, I have to create a Linked
I have some homework that I was flying through until I got to this
I have issue to dynamically create list(ol or ul). The problem I face is

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.