Project I: AddtionPattern
This project involves the implementation of the AddtionPattern class, which generates a number pattern. The AdditionPattern object is constructed with two positive integer parameters, as described below.
The first positive integer parameter indicates the starting number in the pattern. The second positive integer parameter indicates the value that is to be added to obtain each subsequent number in the pattern.
The AdditionPattern class also supports the following methods:
currentNumber(): returns the current number in the pattern
next(), which moves to the next number in the pattern
prev(), which moves to the previous number in the pattern or takes no action if there is no previous number
The following table illustrates the behavior of an AdditionPattern object that is instantiated by the following statement.
plus3.currentNumber();
2
The current number is initially the starting number in the pattern.
plus3.next();
The pattern adds 3 each time, so move to the next number in the pattern (5).
plus3.currentNumber();
5
The current number is 5.
plus3.next();
The pattern adds 3 each time, so move to the next number in the pattern (8).
plus3.next();
The pattern adds 3 each time, so move to the next number in the pattern (11).
plus3.currentNumber();
11
The current number is 11.
plus3.prev();
Move to the previous number in the pattern (8).
plus3.prev();
Move to the previous number in the pattern (5).
plus3.prev();
Move to the previous number in the pattern (2).
plus3.currentNumber();
2
The current number is 2.
plus3.prev();
There is no previous number in the pattern prior to 2, so no action is taken.
plus3.currentNumber();
2
The current number is 2.
Your task
Write the complete AdditonPattern class. Your implementation must meet all specifications and conform to all examples.
Your code should also include a main() method to test all methods in class. I recommend you put your main() method in another class other than AddtionPattern.
In your code, you should follow "data encapsulation" standard: Keep All Instance Variables Private. Violate this standard would cause you lose points.
Last updated