Question

java question - fill in the information

/**
   This class models a tally counter.
*/
public class Counter
{
   private int value;
   private int max;

   public void setLimit(int maximum)
   {
      max = maximum;
   }

   /**
      Gets the current value of this counter.
      @return the current value
   */
   public int getValue()
   {
      return value;
   }

   /**
      Advances the value of this counter by 1.
   */
   public void count() 
   {
    //-----------Start below here. To do: approximate lines of code = 4
    // increments value by 1. if value exceeds limit, print "Limit exceeded" and reset value to 0
    
    
    
    
    
    
    //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
   }

   /**
      Resets the value of this counter to 0.
   */
   public void reset()
   {
      value = 0;
   }
}

public class CounterTester
{
   public static void main(String[] args)
  {
        Counter c1 = new Counter();
        c1.setLimit(100);
        
        for (int i = 0; i < 50; i++)
        {
         c1.count();
        }
        System.out.println("Tally: " + c1.getValue());
        System.out.println("Expected:\nTally: 50");
        
        for (int i = 0; i < 51; i++)
        {
         c1.count();
        }
        System.out.println("Tally: " + c1.getValue());
        System.out.println("Expected:\nLimit Exceeded");
        System.out.println("Tally: 0");
        
        Counter c2 = new Counter();
        c2.setLimit(0);
        
        for (int i = 0; i < 5; i++)
        {
         c2.count();
        }
        System.out.println("Tally: " + c2.getValue());
        System.out.println("Expected:\nLimit exceeded\nLimit exceeded\nLimit exceeded\nLimit exceeded\nLimit exceeded");
        System.out.println("Tally: 0");
  }
}


0 1
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
java question - fill in the information
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • I need help fixing my java code for some reason it will not let me run...

    I need help fixing my java code for some reason it will not let me run it can someone pls help me fix it. class LinearProbingHashTable1 { private int keyname; private int valuename; LinearProbingHashTable1(int keyname, int valuename) { this.keyname = keyname; this.valuename = valuename; } public int getKey() { return keyname; } public int getValue() { return valuename; } } class LinearProbingHashTable2 { private final static int SIZE = 128; LinearProbingHashTable2[] table; LinearProbingHashTable2() { table = new LinearProbingHashTable2[SIZE]; for (int...

  • Introduction to Java Programming Question: I’m doing a java game which user clicks on two different...

    Introduction to Java Programming Question: I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically looking for codes that could make my memory match game more difficult or more interesting.(a timer, difficulty level, color, etc.) GUI must be included in the code. Here is what I got so far: package Card; import javax.swing.JButton; public class Card extends JButton{    private int id;   ...

  • Introduction to Java Programming Question: I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically look...

    Introduction to Java Programming Question: I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically looking for codes that could make my memory match game more difficult or more interesting.(a timer, difficulty level, color, etc.) GUI must be included in the code. Here is what I got so far: package Card; import javax.swing.JButton; public class Card extends JButton{    private int id;    private boolean...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • java problem here is the combination class class Combination {    int first,second,third, fourth;    public...

    java problem here is the combination class class Combination {    int first,second,third, fourth;    public Combination(int first, int second, int third,int fourth)    {        this.first=first;        this.second=second;        this.third=third;        this.fourth=fourth;    }    public boolean equals(Combination other)    {               if ((this.first==other.first) && (this.second==other.second) && (this.third==other.third) && (this.fourth==other.fourth))            return true;        else            return false;    }    public String toString()    {   ...

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

  • USE JAVA Using recursion, find the largest element in an array. Skeleton code is provided. Please...

    USE JAVA Using recursion, find the largest element in an array. Skeleton code is provided. Please do not change the DataSetDemo code. Hint: Find the largest element in the subset containing all but the last element. Then compare that maximum to the value of the last element. Skeleton Code: DataSet: /** Computes the maximum of a set of data values. */ public class DataSet { private int[] values; private int first; private int last; /** Constructs a DataSet object. @param...

  • using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the...

    using Data Structures using Java. Modify it to make the ADT resizable. For this ADT, the MAX_SIZE will not be final, but rather will be increased whenever an new item needs to be added and the array is full (ie. size==MAX_SIZE). Whenever the array needs to grow, add the lesser of: (i) half the current size, or; (ii) 50 additional. Have your ADT report its old and new maximum size whenever the resize operation is called by printing “ADT resized...

  • IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value...

    IN JAVA Task: Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program: Min miles: -10 Max miles: 40 Given Code: import java.util.Scanner; public class ArraysKeyValue { public static void main (String [] args) { final int NUM_ROWS = 2; final int NUM_COLS = 2; int [][] milesTracker = new int[NUM_ROWS][NUM_COLS]; int i = 0; int j = 0; int maxMiles = 0;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT