Question: /** * This class provides the skeleton for the Pascal Triangle * assignment. */ public class PascalsTriangleBase { /** * This field controls the line

 /** * This class provides the skeleton for the Pascal Triangle * assignment. */ public class PascalsTriangleBase { /** * This field controls the line spacing of the output triangle. */ protected boolean doubleSpace; /** * Simple constructor to set the value for the field. */ public PascalsTriangleBase() { doubleSpace = false; } /** * This method is the primary printing method for the triangle. * Override this method to control the spacing between values in * the output triangle. * @param n The value to be printed */ protected void printInt(int n) { System.out.print(n); } /** * This method calculates the binomial coefficient, n choose k. These * values are used to construct Pascal's Triangle. They are called * binomial coefficients because "n choose k" is the value of * the coefficient of the xk term in the expansion of * (1 + x)n. * 

For this assignment, it should use the factorial algorithm; that is * the return value should be calculated as n! / (k! (n-k)!). * @param n The power for the binomial expansion * @param k The order of the term in the binomial expansion * @return The coefficient of the kth term. */ protected int nChooseK(int n, int k) { return k; } /** * The is a special method that is used to print the first value in each * row of Pascal's triangle. The amount of "indent" for the line can be * determined by the parameter values. * @param row The number of the row being printed * @param height The height of the completed triangle */ protected void printOne(int row, int height) { printInt(1); } /** * A simple input validation routine to see if the height is ok. * @param height The requested height for the triangle * @return True if the requested height is out of range */ protected boolean heightOutOfRange(int height) { return false; } /** * The core method for this assignment. It prints out the triangle, * using the helper methods defined above. This method is marked with * the final keyword. This means that this method cannot be * overridden in a subclass. Notice that all of the helper methods * are not declared final, so they are all available for * overriding. * @param height The requested height for the triangle to be printed. */ public final void printTriangle(int height) { System.out.println("Pascal\'s Triangle of height " + height); if(heightOutOfRange(height)) { System.out.println("Height is out of range. Cannot print Pascal's triangle."); return; } System.out.println(); for(int row = 0; row

Create a subclass of PascalsTriangleBase (given above with notes) named PascalsTriangle that overrides the protected methods of PascalsTriangleBase. The method shall accept height values between 0 and 10, inclusive. Create 4 test case scenarios and loop through and print 11 triangles when "all" is in the command line arguement is entered.

The core of this assignment is a method that prints out the Pascal's triangle of the height given in the parameter.

For this assignment, the application method (main) shall call the printTriangle method for each of the four values, (4),(1), (8) and (0). To check your input validation, call printTriangle a fifth time, passing the value -1. This should generate the error message. The program should end normally. The point of this assignment is to work with loops. So, the values in the triangle need to be calculated "on the fly". If you submit a program with hard-coded values for the triangle, you will receive a very bad score. This also applies to the "sum of the two upper neighbors" algorithm that is shown in the text book. Use the factorial algorithm,

The kth value in the nth row is  /** * This class provides the skeleton for the Pascal Triangle read "n choose k",

where 0

* assignment. */ public class PascalsTriangleBase { /** * This field controls = the line spacing of the output triangle. */ protected boolean doubleSpace; /**

Now, n! is read "n factorial". It is calculated like this: n!=1x2x3...(n-1). By definition, 0! = 1

Notice input validation in supported. If the input to printTriangle is out of range, an error message will be printed instead of the triangle. Print the triangles so:

the last line has it's first "1" in the first column

the one's column of alternating rows align vertically

the one's columns within any given row are spaced evenly

the rows of value alternate with blank rows. (double space)

For Example(the top 1 should be centered)

1

1 1 1 2 1 1 3 3 1 1 4 6 4 1

The command-line arguments, the args parameter of main. Depending on the value of the parameter, the output triangles will be different.

If there are no command-line arguments, print out the triangles for your four test cases and for -1, as instructed above.

If the command-line argument is the word "all", use a loop to print out the triangles for 0 - 10, inclusive. That's eleven triangles.

If there are command-line arguments, but it is not the single word "all", assume that those arguments are numerical values. Convert them to int values using Integer.parseInt, and print out the corresponding triangles.

I have attatched a screenshot of the desired outputs for the values 7, 8 and a partial of 9, to confirm thoughts, solutions.* Simple constructor to set the value for the field. */ public

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!