Question: This question involves the implementation of the TriangleNumberTracker class which is used to keep track of triangle numbers. The triangle numbers form a sequence, the

This question involves the implementation of the TriangleNumberTracker class which is used to keep track of triangle numbers. The triangle numbers form a sequence, the first 5 terms of which are shown below. This first term of this sequence is 1, and subsequent terms are found by incrementing the previous term by the term number.This question involves the implementation of the TriangleNumberTracker class which is used

A TriangleNumberTracker object is created with an integer term number which determines the starting term to which the tracker refers. For example if the term number is 4, the tracker begins at the 4th triangle number, which is 10.

The TriangleNumberTracker class provides a constructor and the following methods.

  • currentTriangle which returns the triangle number which the tracker points at as an int.
  • nextTriangle which changes the tracker to point at the next triangle number.
  • prevTriangle which changes the tracker to point at the previous triangle number, unless it already points at the first triangle number (1).

to keep track of triangle numbers. The triangle numbers form a sequence,

Term number 1 2 3 4 5 Triangle Number 1 3 6 10 15 Explanation 1 + 2 = 3 3+3= 6 6 + 4 = 10 10 + 5 = 15 The following table contains a sample code execution sequence and the corresponding results. Statements and Expressions Value Returned (blank if no value) Comment TriangleNumberTracker t = new TriangleNumberTracker(4); tis initialized pointing to the 4th triangle number t.currentTriangle(); 10 The 4th Triangle number is 10 t.nextTriangle(); Moves current triangle number to the 5th 15 21 t.currentTriangle(); t.nextTriangle(); t.current Triangle(); t.prevTriangle(); t.prev Triangle(); t.prevTriangle(); t.currentTriangle(); t.prevTriangle(); t.prev Triangle(); t.current Triangle(); 6 The 5th Triangle number is 15 Moves current triangle number to the 6th The 6th Triangle number is 21 Moves current triangle number to the 5th Moves current triangle number to the 4th Moves current triangle number to the 3rd The 3rd Triangle number is 6 Moves current triangle number to the 2nd Moves current triangle number to the 1st The 1st Triangle number is 1 Does nothing as current triangle number is already 1st (lowest possible) The 1st Triangle number is 1 1 t.prevTriangle(); t.current Triangle(); Write the complete TriangleNumberTracker class including the constructor and any required instance variables and methods. Your implementation must meet all specifications and conform to the example

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!