gBaseNInt1 Class

Step 1: problem domain

In this section, we want to develop a class that can support numbers in different bases. By the use of this class users can define numbers in any bases. For example users can define numbers in binary or octal. After that users can do all mathematics operations among them.

This class is used just for java long numbers and the base can be 2 to 10. (Simple Version)

Step 2: Public Interface

2-1- Constructor Methods

public gBaseNInt1(int base); // set to 0
public gBaseNInt1(int base, long defaultvalue);

public gBaseNInt1(gBaseNInt1 number);
// if number.base is different from this.base CHANGE number to this.base

2-2- Setter Methods

public void Set(long number);
public void Set(gBaseNInt1 number); 
// CHANGE number if number.base is different from this.base

2-3- Getter Methods

public int getBase();
public long getNumber();

2-4- Functionalities of class (Methods)

public long getNumberInBase(int base);
// to get number in different base

// In all mathematics operations, if a.base or b.base is different from
// this.base, CHANGE base of a and b to perform the operation. 

// x.setSum(a,b);  instead of   x=a+b;
public void setSum(gBaseNInt1 a, gBaseNInt1 b);

// x.setMinus(a,b);  instead of   x=a-b;
public void setMinus(gBaseNInt1 a, gBaseNInt1 b);

// x.setMultiple(a,b);  instead of   x=a*b;
public void setMultiple(gBaseNInt1 a, gBaseNInt1 b);

// x.setDiv(a,b);  instead of   x=a/b;
public void setDiv(gBaseNInt1 a, gBaseNInt1 b);

// x.setMod(a,b);  instead of   x=a%b;
public void setMod(gBaseNInt1 a, gBaseNInt1 b);

// x.setFact(4);  instead of   x=4!;
public void setBigFact(int a);

// x.setBigPow(2,4);  instead of   x=2^4;
public void setBigPow(int a,int b);

2-5- Standard Library Methods overloading (such as toString, equals,…)

public String toString();
public int compareTo(gBaseNInt1 a);
public boolean equals(Object anObject);
public int hashCode();
public gBaseNInt1 clone();

 

Step 3: private variables

Private variables of this class are one long for number and one int for the base.

 

Step 4: implementing main classes

Students work !

Step 5: useful application

This class will be used in CALC projects.