Sunday, November 3, 2019

ICSE Project on Menu Driven Program With 20 Patterns

This is a BlueJ Menu Driven Program to check choice from user (1-20) and display different patterns. The programs ends when the user enters 0


import java.util.Scanner;
class Max
{
    Scanner sc=new Scanner(System.in);
    void takeChoice()
{
    int ch;
        System.out.print("\nUser will enter choice between 1 to 20 to display different patterns\nIf '0' is entered, the program will be terminated");
    do
    {
        System.out.println("\n\nEnter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):");
        ch=sc.nextInt();
        switch(ch)
        {
             case 1:
                    pattern1();
                    break;
             case 2:
                    pattern2();
                    break;
             case 3:
                    pattern3();
                    break;
             case 4:
                    pattern4();
                    break;
             case 5:
                    pattern5();
                    break;
             case 6:
                    pattern6();
                    break;
             case 7:
                    pattern7();
                    break;
             case 8:
                    pattern8();
                    break;
             case 9:
                    pattern9();
                    break;
             case 10:
                    pattern10();
                    break;


             case 11:
                    pattern11();
                    break;
             case 12:
                    pattern12();
                    break;
             case 13:
                    pattern13();
                    break;
             case 14:
                    pattern14();
                    break;
             case 15:
                    pattern15();
                    break;
             case 16:
                    pattern16();
                    break;
             case 17:
                    pattern17();
                    break;
             case 18:
                    pattern18();
                    break;
             case 19:
                    pattern19();
                    break;
             case 20:
                    pattern20();
                    break;
             case 0:
                   System.out.print("\nEnd of Program...");
                   break;
             default:   
                   System.out.print("\nEnter Your Choice Properly (1-20).");
                   
        }
               
    }while(ch!=0);
}
private void pattern1()
{

int i,j,x=1;
for ( i=0;i<=5;i++)
{
for(j=0;j<=i;j++)
{
System.out.print(x);
if(x>0)
x--;
else
x++;
}
System.out.println();
}
}

private void pattern2()
{
   int x;
   for(int i=0;i<=4;i++)
    {
for(int j=i;j<=4;j++)
{
    x=5-i;
System.out.print(x);
}
System.out.println();
}
}

 private void pattern3()
{
    int i,j,x;
for(i=0;i<=4;i++)
{
x=1;
for(j=0;j<=4;j++)
{
if(i+j==4)
System.out.print("*");
else
System.out.print(x++);
}
System.out.println();
}
}

  private void pattern4()
{
int i,j,x,y=1;
for( i=0;i<=2;i++)
{
x=y;
for(j=0;j<=i;j++)
{
System.out.print("        "+x);
x=x-2;
}
System.out.println();
y=y+2;
}
 }

 private void pattern5()
{
 int x;
for(int i=0;i<=4;i++)
{
x=6;
for(int j=0;j<=i;j++)
{
System.out.print(" "+x);
x=x+6;
}
System.out.println();
}
}

private void pattern6()
{
for(int i=0;i<=4;i++)
{
int x=5;
for(int j=0;j<=4;j++)
{
System.out.print(x+ " ");
if(j
x=x-1;
}
System.out.println();
}
}

private void pattern7()
{
    int x;
for(int i=1;i<=4;i++)
{
x=1;
for(int j=1;j<=6;j++)
{
System.out.print(" "+x);
x=x+i;
}
System.out.println();
}
}

private void pattern8()
{
 for(int i=0; i<=3; i++)
{
for(int j=0; j<=i; j++)
{
System.out.print(i+" ");
}
System.out.println();
}
}

private void pattern9()
{  
 for(int i=0; i<=3; i++)
{
for(int j=0; j<=i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}

private void pattern10()
{
    for(int i=0; i<=3; i++)
{
for(int j=i; j<4 j="" o:p="">
{
System.out.print(i+" ");
}
System.out.println();
}
}

private void pattern11()
{
    for(int i=0; i<=3; i++)
{
for(int j=i; j<=3; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}

private void pattern12()
{
   int x=1;
 for(int i=0; i<=3; i++)
{
for(int j=0; j<=i; j++)
{
System.out.print(x+" ");
x++;
}
System.out.println();
}
}

private void pattern13()
{
   int x=1;
 for(int i=0; i<=3; i++)
{
for(int j=i; j<=3; j++)
{
System.out.print(x+" ");
x++;
}
System.out.println();
}
}

private void pattern14()
{
   int x=1;
 for(int i=0; i<=3; i++)
{
for(int j=i; j<=3; j++)
{
 if (x<10 o:p="">
System.out.print("0"+x+" ");
else
System.out.print(x+" ");
x++;
}
System.out.println();
}
}

 private void pattern15()
{
    for(int i=0; i<=3; i++)
{
for(int j=0; j<=3; j++)
{
System.out.print('@');
}
System.out.println();
}
}

private void pattern16()
{
    int x=1;
for(int i=0;i<=6;i++)
{
for(int j=0;j<=x-1;j++)
{
System.out.print("*");
}
if(i< 7/2)
x++;
else
x--;
System.out.println();
}
}

private void pattern17()
{
String s1;
int i,j,len,sp=0,c,s=1;
s1="Suddhashil Chakraborty";
len=s1.length()-1;
for(i=0;i<=len;i++)
{
if(s1.charAt(i)==' ')
s++;
}
while(true)
{
c=0;
if (s==sp)
break;
sp++;
for(i=0;i<=len;i++)
{
if(s1.charAt(i)==' ')
c++;
if(c==sp)
break;
System.out.print(s1.charAt(i));
}
System.out.println();
}
}

private void pattern18()
{
int i,j,len;
String s1="INDIA";
len=s1.length()-1;
for(i=0;i<=len;i++)
{
for(j=0;j
{
System.out.print(s1.charAt(j));
}
System.out.println();
}
}

private void pattern19()
{
int i,j,len;
String s1="BLUEJ";
len=s1.length();
for (i=len-1;i>=0;i--)
{
for(j=len-1;j>=i;j--)
System.out.print(s1.charAt(i));
System.out.println();
}
}

private void pattern20()
{
int i,j,len;
String s="BLUEJ";
len=s.length()-1;
for(i=0; i <=len; i++)
{
 for(j=0;j<= i;j++)
{
System.out.print(s.charAt(i));
}
System.out.println();
}
}

public static void main(String args[])
{
Max ob=new Max();
ob.takeChoice();
}
}

Sample Input Output

User will enter choice between 1 to 20 to display different patterns
If '0' is entered, the program will be terminated

Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
1
1
01
010
1010
10101
010101


Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
54

Enter Your Choice Properly (1-20).

Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
2
55555
4444
333
22
1


Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
6
5 5 5 5 5
5 4 4 4 4
5 4 3 3 3
5 4 3 2 2
5 4 3 2 1


Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
7
 1 2 3 4 5 6
 1 3 5 7 9 11
 1 4 7 10 13 16
 1 5 9 13 17 21


Enter Choice (1-14 for numberic pattern, 15-16 for character pattern and 17-20 for pattern on string, 0 for exit):
0

End of Program...


Variable Description

Type of Variable
Name of Variable
Description
int
ch
This variable holds user choice
int
i
Loop Control variable
int
j
Loop control variable
Int
x
This variable is used inside loops of function body to display numbers in the pattern
int
len
This variable is used inside pattern displaying function body to hold length of string
Scanner
sc
Input object
String
s
This object is used inside pattern displaying function body to hold  string value
String
s1
This object is used inside pattern displaying function body to hold  string value


No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner