I am making an ABACUS MODEL program which adds counters to pegs. The program compiles fine but when i use the test that was issued to me (as pictured) it appears as though my program does not work as intended. I don't know if anyone will be able to help me solve this but any attempts or suggestions will be very helpful. Not particularly talented with Java.

## Variables:

**thisPeg** - an integer that refers to any of the pegs in the abacus**peg_array[]** - stores the number of counters present in each of the pegs in the abacus**max_num_counters** - controls the maximum number of counters stored in each element (9 counters)**num_of_pegs** - stores the number of pegs the abacus has (7 pegs)

## MY CODE AbacusModel

```
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.event.*;
class AbacusModel extends JPanel
{
int num_of_pegs;
int max_num_counters;
int peg_array[];
public AbacusModel(int num_pegs, int num_counters)
{
max_num_counters = num_counters;
num_of_pegs = num_pegs;
peg_array = new int[num_of_pegs];
}
boolean addCounter(int thisPeg)
{
// Trying to add a counter when that column of the abacus is full
// add a counter to peg_array[thisPeg] if it is a valid index
// its these conditions below that are probably incorrect as returning undesired results????
if (peg_array[thisPeg] >= 0 || peg_array[thisPeg] < num_of_pegs
|| max_num_counters < 8)
{
peg_array[thisPeg]++;
return true;
}
// if not then do nothing...
else
return false;
}
boolean removeCounter (int thisPeg)
{
// its these conditions below that are probably incorrect as returning undesired results????
if (peg_array[thisPeg] >= 0 || peg_array[thisPeg] <= num_of_pegs
|| max_num_counters > 0 || peg_array[thisPeg] < max_num_counters)
{
peg_array[thisPeg]--;
return true;
}
else
return false;
}
int getNumCounters(int thisPeg)
{
// possibly these conditions too??
if (peg_array[thisPeg] >= 0 && peg_array[thisPeg] <= num_of_pegs)
{
return peg_array[thisPeg];
}
else
return 0;
}
public static void main (String[] args)
{
AbacusModel myAbacus = new AbacusModel(7, 9);
}
```

Anything somebody may be able to provide help with will help me greatly. Thanks