Question: Need help, please follow all specifications II. The PascalsTriangle Class - Specifications Create a class that will create a PascalsTriangle with a given number of

Need help, please follow all specifications

II. The PascalsTriangle Class - Specifications

Create a class that will create a PascalsTriangle with a given number of rows. To receive credit for this assignment, your class must use a 2D array of int as its principal data structure.

Your PascalsTriangle class will have a constructor with one parameter the number of rows and these additional methods:

1. A method that creates the PascalsTriangle (i.e. populates the array). This should be a private method, called by the class constructor

2. A toString() method that returns the PascalsTriangle as a multi-line String, meticulously formatted as shown above

III. The Test Class - Specifications

Write a test class with a main() method that does the following:

1. Get the number of rows from the user

2. Create the PascalsTriangle object

2. Call toString() and print the String returned

Use a loop to coerce the user to enter a valid number of rows - from 1 to 13, inclusive, - as a String.

If the String entered is not a valid int, print an error message and make the user try again. Otherwise, convert to int and check whether it is between 1 and 13, inclusive. If so, create the PascalsTriangle and print the triangle returned by toString(). Otherwise, print an error message and have the user try again. Your code must allow the user any number of attempts to enter a valid number

Hints:

use a boolean variable to control the number of iterations

review Scanner class method hasNextInt

to convert a String to int, use Integer.parseInt(input)

Design your main() method to enable the user to create any number of PascalsTriangles in each run

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!