 # Discussion In mathematics, a number is expressed in positional not...

## Question

Discussion
In mathematics, a number is expressed in positional notation to a certain base, B, a
For example, the 3-digit number 123 in base 4 represents 16+8+3=27 (base 10).
In this lab each digit is represented as a Counter object. A Counter object has an optional left neighbour which is also a Counter object. (The absence of a left neighbour is indicated with the keyword null.
The important methods to implement are getCount() and increment().
If there is no left neighbour, the count is the same as the digit.
If there is a left neighbour, the count is the sum of the digit and the modulus times the count of the left neighbour.
The increment() method increment's the Counter's digit and, if it reaches its maximum (modulus) value, it is reset to zero. Furthermore, if there is a left neighbour and if the Counter has rolled over, its left neighbour should be incremented as well.
The source code template for Counter can be accessed at the end.
There is also a class containing the main method, CounterTry,
Step 1: Create a Netbeans project
1. Create a Netbeans project called Counter which should be placed in a folder called lab3 (all lowercase and no spaces). The lab3 folder should itself be in your coe318 folder.
2. Create a Java file (class library type) called Counter; set the package to .lab3; then copy and paste the provided source code.
3. Similarly, create the Java file CounterTry. (Ensure you use the same .lab3 package name.
4. Generate the javadocs and compile and run the project.
5. It should compile correctly and produce output. Unfortunately, the output is incorrect and you have to fix it.
Step 2: Add instance variables and fix constructor and getters
1. Add instance variables for the two components of a counter.
2. Modify the constructor so that they are properly initialized.
3. Fix the remaining methods so that they work for a simple counter without a left neighbour.
4. Compile and run your project. As least some of the output should now be correct.
Step 3: Fix methods so it works when there is a left neighbour
1. Fix the remaining methods.

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/**
*
*/
package .lab3;

public class Counter {

//Instance variables here
private int modulus;
private Counter left;
private int digit;

public Counter(int modulus, Counter left) {
this.modulus = modulus;
this.left = left;
// default value is 0
this.digit = 0;
}

/**
* @return the modulus
*/
public int getModulus() {
return modulus;
}

/**
* Returns the Counter to the left attached to this Counter. Returns null if
* there is no Counter to the left.
*
* @return the left
*/
public Counter getLeft() {
return left;
}

/**
* @return the digit
*/
public int getDigit() {
return digit;
}

/**
* @param digit the digit to set
*/
public void setDigit(int digit) {
// invalid input input
if (digit < 0 || digit > modulus...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

\$23.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.