SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 16 Dec 2017 My Price 10.00

RolloverCounter.java and CounterTest.java

Once you've compiled and tested your code, submit your completed RolloverCounter.java file.

Download the attached files: RolloverCounter.java and CounterTest.java

The CounterTest is a program you can use to test your code. You will write your code in the RolloverCounter.java file.

In the RolloverCounter.java file you will implement a RolloverCounter class that should include:

1) A private integer variable to store the current count.

2) Another private integer variable to store the maximum value this counter can count up to.

3) A constructor that takes a single integer as an argument and uses it to set the maximum counter value. The count should be set to 0.

4) An increment() method that increases the count value by 1, but sets it back to 0 if the count goes above the maximum.

5) A decrement() method that decreases the count value by 1, but sets it to the maximum value if it goes below 0.

6) A toString() method that returns a String representing the current count value

7) A reset() method that sets the count value back to 0.

Notes:

+ This class is meant to be like the values on a car's odometer readout that tick upwards through the digits 0 to 9 and then "rolls over" back to 0.

+ The count should always be a number between 0 and the maximum value that was set when the counter was created.

+ You can use the Integer.toString() method to convert the int value into a String to return it in your toString() method

+ The constructor should throw an exception if the given max value is less than 1

+ the increment(), decrement(), and reset() methods take in no arguments and return nothing/*
* MCS 141
* HW 4
* a program that uses the RolloverCounter class to test its functionality
* You don't need to change anything in the program...it is just here to help you test your code in the RolloverCounter
*
When this program is run the output should be:
*************************************************
creating new counters...
creating counter c1 with max value = 5...
creating counter c2 with max value = 3...
creating counter c3 with max value = -2 (this should not work)...
Error creating counter: java.lang.RuntimeException: invalid maximum value

incrementing the counts 10 times and printing counts...
c1: 1 c2: 1
c1: 2 c2: 2
c1: 3 c2: 3
c1: 4 c2: 0
c1: 5 c2: 1
c1: 0 c2: 2
c1: 1 c2: 3
c1: 2 c2: 0
c1: 3 c2: 1
c1: 4 c2: 2

decrementing the counts 7 times and printint counts...
c1: 3 c2: 1
c1: 2 c2: 0
c1: 1 c2: 3
c1: 0 c2: 2
c1: 5 c2: 1
c1: 4 c2: 0
c1: 3 c2: 3

resetting counters...
c1: 0 c2: 0
*****************************************************
*/

public class CounterTest {
    public static void main(String args[]) {
        System.out.println("creating new counters...");
        System.out.println("creating counter c1 with max value = 5...");
        RolloverCounter c1 = new RolloverCounter(5);
        System.out.println("creating counter c2 with max value = 3...");
        RolloverCounter c2 = new RolloverCounter(3);
        
        try {
          System.out.println("creating counter c3 with max value = -2 (this should not work)...");
          RolloverCounter c3 = new RolloverCounter(-2);
        } catch (Exception e) {
          System.out.println("Error creating counter: " + e);
        }

        System.out.println("\nincrementing the counts 10 times and printing counts...");
        for (int i=1; i<=10; i++) {
            c1.increment();
            c2.increment();
            System.out.println("c1: " + c1 + "\tc2: " + c2);
        }

        System.out.println("\ndecrementing the counts 7 times and printint counts...");
        for (int i=1; i<=7; i++) {
            c1.decrement();
            c2.decrement();
            System.out.println("c1: " + c1 + "\tc2: " + c2);
        }

        System.out.println("\nresetting counters...");
        c1.reset();
        c2.reset();
        System.out.println("c1: " + c1 + "\tc2: " + c2);
        
    } //end main
} //end CounterTest


/*
* MCS 141
* HW 4
* Write the code for the RolloverCounter class below
*
* In the RolloverCounter.java file you will implement a RolloverCounter class that should include:
1) A private variable to store the current count.
2) Another private variable to store the maximum value this counter can count up to.
3) A constructor that takes a single integer as an argument and uses it to set the maximum counter value.  The count should be set to 0.
4) An increment() method that increases the count value by 1, but sets it back to 0 if the count goes above the maximum. no arguments, returns nothing
5) A decrement() method that decreases the count value by 1, but sets it to the maximum value if it goes below 0. no arguments, returns nothing
6) A toString() method that returns a String representing the current count value.  no arguments.
7) A reset() method that sets the count value back to 0.  no arguments, returns nothing.

Notes:
+ This class is meant to be like the values on a car's odometer readout that tick upwards through
the digits 0 to 9 and then roll back to 0.
+ The count should always be a number between 0 and the maximum value that was set when the counter was created.
+ The constructor should throw an exception if the argument for the maximum value is not a positive number (0 or less)
*/

public class RolloverCounter {
  //TODO - Write the code for the class here.
 

} //end RolloverCounter

Answers

(5)
Status NEW Posted 16 Dec 2017 07:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)