Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Main Method Your program prompts the user for the name of a text file and the number of rows, a positive integer, that the

image text in transcribed

The Main Method Your program prompts the user for the name of a text file and the number of rows, a positive integer, that the Pascal's triangle will have. The main method does the following 1. The main method calls the nertRow method to generate and display the first row of the Pascal's triangle. 2. The main method then calls the nextRow method using the array repre- senting the first row to generate the array of coefficients for the second row. It iteratively generates and displays each n rows of the trian- gle from rows 1.n, each time calling the nextRow method with the ith row array to generate the (i1)st row array until all n rows are generated and printed Diaplaya a ro o the Paacal's triangl * paran rou an array containing binonial coefficients * aparnunRows the number of rows that the triangle will have * paran ohift the nunber of columna by which tho firot s coefficient, 1, of the next row is shifted leftuard * #r0 the fir t coatticiant on the previous row public atatic void printRoit. int nuxo, int shift) Your program will consist of only one class, PascalTriangleGenerator. Define all the methods listed above in the maln elass before the main method. Once displays the Pascal's triangle on the scroen as desired, modify the program so that it also writes the triangle to the text file. Your program should close the outpat file your program disploys he g boe Program Interaction A typical program interaction would be: Listing 1: Sample Run 1 Entor thu nae of tho output filo-> pasca15. txt 2 Enter the nuber of rows for the triangle 5 Listing 2: Sample Run2 1 Enter the nane of the output file->pascal7.txt 2 Enter the nunber of rovs for the triangle-7 Additional Requirements When your code can generate and display Pascal's triangles, do the following: 1. Add an additional explicit parameter for a Print Writer to the signature of the printRow method: public static void printRou(int row, int numRous, int shift, PrintWriter writer) Oparam writer a reference to a file output stream signature of the main method as follows: 2. Add the following Javadoc for this parameter to the printRow method's Javadoc: 3. Specify the standard Java language IOException by re-throwing it. Modify the public static void main (Stringlargs) throws IO Exception 4. As the coefficients are printed on the screen, also write them to the file. 5. Finally, don't forget to close the PrintWriter at the end of the main method if you aren't using a try-with-resource statement

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

How could any of these verbal elements be made stronger?

Answered: 1 week ago

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

a. What is the purpose of the team?

Answered: 1 week ago

Question

b. What are its goals and objectives?

Answered: 1 week ago