Question: // TO DO: add your implementation and JavaDocs public class MyAbacus implements Abacus { // ADD MORE PRIVATE MEMBERS HERE IF NEEDED! // Remember: Using
// TO DO: add your implementation and JavaDocs
public class MyAbacus implements Abacus {
// ADD MORE PRIVATE MEMBERS HERE IF NEEDED! // Remember: Using an array in this class = no credit on the project! private int size = 0; private int baseNum; public MyAbacus(int base) { // throws IllegalArgumentException if base is invalid // remember: an abacus should always have at least one // column! this.baseNum = base; if(baseNum%2!=0 || baseNum<2){ throw IllegalArgumentException("Invalid"); } else{ return baseNum; } } public int getBase() { // O(1) return this.baseNum; //default return, make sure to remove/change }
public int getNumPlaces() { // O(1) return ; //default return, make sure to remove/change } public int getBeadsTop(int place) { // O(1) return -1; //default return, make sure to remove/change } public int getBeadsBottom(int place) { // O(1) return -1; //default return, make sure to remove/change } public boolean equals(MyAbacus m) { // O(N) where N is the number of places currently // in use by the abacus return false; //default return, make sure to remove/change } public DynArr310
return null; //default return, make sure to remove/change } // -------------------------------------------------------- // example testing code... edit this as much as you want! // -------------------------------------------------------- public static void main(String[] args) { //this is the sequence from the project description Abacus a = new MyAbacus(10); DynArr310
This is the interface for the above to be implemented
// -------------------------------------------------------- // DO NOT EDIT ANYTHING BELOW THIS LINE // --------------------------------------------------------
/** * Interface for an abacus for the AbacusGUI to use. */ public interface Abacus { /** * Gets the number base of the abacus. This base * will never be an odd number and never be less * than 2. * * @return the number base of the abacus */ public int getBase(); /** * Returns the number of places (bead columns) the * abacus is using to represent the number. This * will never be less than one. * * @return the number of places in use */ public int getNumPlaces(); /** * Gets the number of beads in the top area of the * abacus which are in-use for a given place. (The * number of beads in the top which are pushed down * to the center.) * * @param place the beads column of interest (0 is the right-most place) * @return the number of beads currently in use * @throws IndexOutOfBoundsException if the place requested is not in use */ public int getBeadsTop(int place); /** * Gets the number of beads in the bottom area of the * abacus which are in-use for a given place. (The * number of beads in the bottom which are pushed up * to the center.) * * @param place the beads column of interest (0 is the right-most place) * @return the number of beads currently in use * @throws IndexOutOfBoundsException if the place requested is not in use */ public int getBeadsBottom(int place); /** * Adds the given string representation of a number to * the current value of the abacus. The abacus is updated * to this new position. It returns the steps to perform * the add (snap shots of the abacus at each step). The * abacus may be left in an "improper state" if the * provided arguements are invalid. * *
A snapshot is required for each of the following steps: *
- *
- - the initial state *
- - the final state *
- - expansions (beads should not be moved, the abacus just * becomes bigger/smaller) *
- - exchanges (beads are exchanged in one step) *
- - movement of X beads up OR down (not both at the same time) * in ONE place on the bottom OR top of the abacus (not both * at the same time) *
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
