Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Done in Java. Any help is greatly appreciated!! Note: No arrays or any other data structure (arraylist, hashmap, sets, linkedlist, stacks, queue) is allowed Hints:

Done in Java. Any help is greatly appreciated!!

Note: No arrays or any other data structure (arraylist, hashmap, sets, linkedlist, stacks, queue) is allowed

Hints:

Note that this program will always terminate when the user hits 'E'

After printing the pattern again display the menu to the user.

Take care of printing the spaces in the patterns

The pattern should look exactly how it does in the pdf.

The user also has to input the size of the pattern which can be taken in the next line after the user inputs the menu option.

You have to use nested loops to do this problem.

An easier way to approach this problem is by breaking down a bigger pattern into smaller parts.

image text in transcribed

image text in transcribed

Here is what I have so far. I am struggling with patterns 1 and 3.

***** Note for pattern 1: The pattern size user picks is the number of rows * number of columns

If user chooses three they would have:

101

010

101

// import statements import java.lang.*; import java.util.*;

public class DesigningPatterns {

public static void main(String[] args) { // TODO Auto-generated method stub char select; // Scanner so user can choose design Scanner input = new Scanner(System.in); // while loop to keep going through options until user exits while(true) { // menu System.out.println(); System.out.println("Menu"); System.out.println("A. Pattern 1"); System.out.println("B. Pattern 2"); System.out.println("C. Pattern 3"); System.out.println("D. Pattern 4"); System.out.println("E. Exit"); System.out.println(); System.out.print("Please select your pattern: "); select = input.next().charAt(0); // switch case to make menu usable switch(select) { // calls pattern 1 when A chosen case 'A': pattern1(); break;

// calls pattern 2 when B chosen case 'B': pattern2(); break;

// calls pattern 3 when C chosen case 'C': pattern3(); break;

// calls pattern 4 when D chosen case 'D': pattern4(); break;

// exits program case 'E': System.exit(0);

// printed when user doesn't select correctly default : System.out.println(" Please select above options only ");

} } } // pattern 1 method public static void pattern1() { // variables for the for loops int n, i, j;

// Scanner to get design size System.out.println(); Scanner input = new Scanner(System.in); System.out.print("Enter the size of the pattern: ");

// make sure int given n = input.nextInt(); System.out.println();

// for loop to add on each line for(i = 1; i = i ; j--) { System.out.println("0"); } } } // pattern 2 method public static void pattern2() { // variables for the for loops int n, i, j; // Scanner to get design size System.out.println(); Scanner input = new Scanner(System.in); System.out.print("Enter the size of the pattern: "); // make sure int given n = input.nextInt(); System.out.println(); // for loop to add on each line for(i = 1; i

// for loop to get bottom triangle for(i = 1; i

2. Designing Patterns Create a menu-based program to generate the given patterns. A menu-based program is a program that provides the user a "menu of options and user has a choice to select any item from the menu. The program will not stop till user chooses to exit the program with option 'E'. Program should only accept 'A', 'B', 'C', 'D' and 'E' as valid options. User will also provide a number that will be used as size to draw the chosen pattern. Patterns with size 5 are shown below. A. 10101 01010 10101 01010 10101 B. c. ABCDEF ABCDE ABCD ABC AB A A AB ABC ABCD ABCDE ABCDEF D. Example Menu: A. Pattern 1 B. Pattern 2 C. Pattern 3 D. Pattern 4 E. Exit

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

Students also viewed these Databases questions