Question: Package Name: hmwk05 Source File Name: (Submit this file) Pattern.java Test Files: C2800_Ch05_Hmwk1_Pattern_Test.zip This program will only have 1 class with a single method, just

Package Name:

hmwk05

Source File Name:

(Submit this file)

Pattern.java

Test Files:

C2800_Ch05_Hmwk1_Pattern_Test.zip

This program will only have 1 class with a single method, just main(). We want to practice for and switch statements.

Your program will print a variety of patterns:

Prompt the user for the type of pattern and the size of the pattern

Use a switch statement (not if-else if) to determine which pattern to print

Let N be the size of the pattern

Pattern type 1 print N *s

Pattern type 2 print 1 to N (with a space after each number)

Pattern type 3 print a right triangle of *s. The first line has 1 *, the second line has 2 *s, and so on, up to the Nth line with N *s

Pattern type 4 print a curve pattern (2 triangles, one on top of another). The first line is N *s, the second line is 1 space and N-1 *s until you get to a single *. Then reverse the printing. See sample run 4 for an example of N=3.

Use for loops to print the patterns

If you would like to make one of the patterns using a do..while instead of a for loop, you may. That would allow you to practice a dowhile loop. But keep in mind that for this kind of problem, for loops would be the best choice.

Print a message If the user enters an invalid pattern choice

Requirements:

All numbers entered are integers

Put System.out.println() after the prompt line. This will help you match the Test Program and make it easier to use it.

Sample Run #1: (the highlighted text is what the user types)

Pattern(1=*, 2=nums, 3=triangle, 4=curve) size? 1 5

*****

Sample Run #2: (the highlighted text is what the user types)

Pattern(1=*, 2=nums, 3=triangle, 4=curve) size? 2 4

1 2 3 4

Sample Run #3: (the highlighted text is what the user types)

Pattern(1=*, 2=nums, 3=triangle, 4=curve) size? 3 6

*

**

***

****

*****

******

Sample Run #4: (the highlighted text is what the user types)

Pattern(1=*, 2=nums, 3=triangle, 4=curve) size? 4 3

***

**

*

*

**

***

Sample Run #5: (the highlighted text is what the user types)

Pattern(1=*, 2=nums, 3=triangle, 4=curve) size? 5 2

Invalid pattern

Extra Notes:

Did you correctly name the package/folder?

Did you correctly name the class/file?

Did you include comments?

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!