basically i am working on a project for uni, which is to create a form of an abacus model.
- peg_array[] stores the number of counters/beads present in each of the pegs(lines) of the abacus.
i am trying to use 2 boolean methods:
"boolean removeCounter(int thisPeg)"
"boolean removeCounter(int thisPeg)"
thisPeg - An integer that refgers to any of the pegs in the abacus
Please can someone help me solve this? All i am trying to do is to recognise where possible errors may occur and prevent them from happening. E.G. if conditions are true then add one counter to the peg peg_array[thisPeg]++. If they are false then do nothing... Similarly the same thing but for removing counters peg_array[thisPeg]--. I am not too great with java and any help people can give me would be hugely appreciated!
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)
{
// add a counter to peg_array[thisPeg] if it is a valid index
if (peg_array[thisPeg] >= 0 || peg_array[thisPeg] <= num_of_pegs)
{
peg_array[thisPeg]++;
}
// if index is not valid then do nothing...
else
return false;
} // error here "error: missing return statement"
boolean removeCounter (int thisPeg)
{
// remove a counter from peg_array[thisPeg] if it is a valid index
if (thisPeg >= 0 || thisPeg <= num_of_pegs)
{
peg_array[thisPeg]--;
}
// if index is not valid then do nothing...
else
return false;
} // error here "error: missing return statement"
int getNumCounters(int thisPeg)
{
// empty temporarily, for use in subsequent tasks...
} // error here "error: missing return statement"
public static void main (String[] args)
{
AbacusModel myAbacus = new AbacusModel(7, 9);
}