Question: Recursion ProgramWrite a recursive program to determine and print the Nth line of Pascal's Triangle, as shown below. Each interior value is the sum of

Recursion ProgramWrite a recursive program to determine and print the Nth line of Pascal's Triangle, as shown below. Each interior value is the sum of the values above it.(Hint: Use a 2D array to store the values on each line.)11112113311464115101051161520156117213535217118285670562881To do this, you will create two classes:PacalTriangleGenerator and the DriverPascalTriangleGenerator class:Instance variable: two integer arrays, row1 and row2Methods: Constructor that instantiates the two arrays/ The first array will contain one element and the other will contain two elements. Set the value of each element to 1. computeRow() This is your recursive method that computes the specified row of Pascals triangle. Accepts an integer that represents a row number and returns an integer arrayo There will be two base cases: value passed in is a one, which would only occur if the original number is a one, and if value passed in is a 2o Initially the specified row that is passed in is the bottom of the triangle. With each call of this method recursively, you will work your way up the triangle until you are on row 2.o The general case calls the computeNextRow method and passes into it the result of calling the computerRow method, decreasing the row number by 1 each time computeNextRow() computes the next row of Pascals Triangle given the previous one. It accepts an integer array that represents the previous row and returns an integer arrayDriver class:This class will only contain one method, in addition to the main method. It will prompt the user for a total lines, call the method to create a pascal triangle and then prompt the user to indicate whether a new triangle should be drawn. Methods: newTriangle- This method does not receive or return anything. It draws the Pascal Triangle.o Prompt and accept the number of rowso Inside a loop- loop should traverse each row of the triangle Instantiate a PascalsTriangleGenerator object Call the computeRow method of PascalsTriangleGenerator Output the triangle Main()o Inside a loop- loop should terminate when the user indicates they want to stop Call the newTriangle Prompt and accept user input for whether they want another triangle? Sample output:How many lines of Pascal's Triangle? 5111121133114641 Another (y/n)? y How many lines of Pascal's Triangle? 7111121133114641151010511615201561 Another (y/n)? n

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 Programming Questions!