Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ILL GIVE YOU A GOOD REVIEW FOR YOUR HELP. (Please provide comments on each step so I know whats going on and keep it simple,

ILL GIVE YOU A GOOD REVIEW FOR YOUR HELP. (Please provide comments on each step so I know whats going on and keep it simple, dont import any unusual methods from the java library besides what the question ask you. thank you )

Pascals Triangle

I. Definition

In mathematics, Pascal's triangle is a triangular array of the binomial coefficients. In much of the Western world, it is named after French mathematician Blaise Pascal, although other mathematicians studied it centuries before him in India, Persia, China, Germany, and Italy.

The rows of Pascal's triangle are conventionally enumerated starting with row n = 0 at the top (the 0th row). The entries in each row are numbered from the left beginning with k = 0 and are usually staggered relative to the numbers in the adjacent rows. The triangle may be constructed in the following manner: In row 0 (the topmost row), there is a unique nonzero entry 1. Each entry of each subsequent row is constructed by adding the number above and to the left with the number above and to the right, treating blank entries as 0. For example, the initial number in the first (or any other) row is 1 (the sum of 0 and 1), whereas the numbers 1 and 3 in the third row are added to produce the number 4 in the fourth row.

- Wikipedia

E.g. Here is a Pascals Triangle of 12 rows:

1

1 1

1 2 1

1 3 3 1

1 4 6 4 1

1 5 10 10 5 1

1 6 15 20 15 6 1

1 7 21 35 35 21 7 1

1 8 28 56 70 56 28 8 1

1 9 36 84 126 126 84 36 9 1

1 10 45 120 210 252 210 120 45 10 1

1 11 55 165 330 462 462 330 165 55 11 1

A Pascals Triangle of 12 Rows

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) or String.valueOf(input), both of which return String input as an int

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

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_2

Step: 3

blur-text-image_3

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

1. Identify six different types of history.

Answered: 1 week ago

Question

2. Define the grand narrative.

Answered: 1 week ago

Question

4. Describe the role of narratives in constructing history.

Answered: 1 week ago