saadismail85 0 Newbie Poster
import java.util.Scanner;
public class Draw {
	
	public static  void display1 ()
	{
		System.out.println("=============================================");
		System.out.println("|                 SELECTION                 |");		
		System.out.println("|===========================================|");		 
		System.out.println("| Option :                                  |");
		System.out.println("|         0: Exit                           |");
		System.out.println("|         1: Empty Shape                    |");
		System.out.println("|         2: Filled Shape                   |");
		System.out.println("=============================================");
		
	}

	public static void main(String[] args) {
		Scanner input =  new Scanner (System.in);
		
		int width = 0;
		int height = 0;
		int select;
		boolean x = true;
		while(x==true)
		{
			System.out.println("\nDraw\n0: Exit\n1:Quadrilateral \n2:Rectangle\n3:Triangle");
			
			int draw =input.nextInt();
			
			if (draw==0)
			{
				System.out.println(" ...EXIT...");
				System.exit(0);
			}
		switch (draw)
		{
		case 1 :
				display1();
				select = input.nextInt();
			System.out.print("Enter Width :");
			width = input.nextInt();
			switch (select)
			{
			case 0 :
				System.out.println(" ...EXIT...");
				System.exit(0);
				break;
				
			case 1 :
				
				System.out.println("Empty Shape ");
				int i,j,k;
			
				for(i=1;i<=width;i++)
				{
				for(j=width-i;j>=1;j--)
				{
				System.out.print(" ");
				}
				for(k=1;k<=i;k++)
				{
				if(k==1||k==i)
				System.out.print("*"+" ");
				else
				System.out.print(" "+" ");
				}
				System.out.println();
				}

				for(i=width-1;i>=1;i--)
				{
				for(j=width-i;j>=1;j--)
				{
				System.out.print(" ");
				}
				for(k=1;k<=i;k++)
				{
				if(k==1||k==i)
				System.out.print("*"+" ");
				else
				System.out.print(" "+" ");
				}
				System.out.println();
				}
				System.out.println("Width :"+width);
			break;
			
			case 2 :
				
				
		
				for ( i = 1; i <= width; i++) 
				{

					for ( j = width; j >= i; j--)

					{
						System.out.print(" ");
					
						if (j == i) 
						{
							for (int d = 1; d <= i; d++) 
							{
								System.out.print(" ");
								System.out.print("*");
								
							
							}
						}
					}
					System.out.println("");
				}
				
				for ( i = width-1; i >= 1; i--) 
				{

					for ( j = width; j >= i; j--)
					

					{
					System.out.print(" ");
					
						if (j == i) 
						{
							for (int d = 1; d <= i; d++) 
							{
								System.out.print(" ");
								System.out.print("*");
							}
						}
				}	
				System.out.println("");
				}
				System.out.println("Width :"+width);
				break;
			}
			break;
			
		case 2:
				display1();
				select = input.nextInt();
			System.out.print("Enter Width :");
			width = input.nextInt();
			
			System.out.print("Enter Height :");
			height = input.nextInt();
			
			switch (select)
			{
			case 0 :
				System.out.println(" ...EXIT...");
				System.exit(0);
				break;
			case 1:
				System.out.println("Empty Shape ");
				for(int i=1;i<=height;i++)
				{
					for(int j=1;j<=width;j++)
					{
				
						if((i==1 || i==height) || (j==1 || j==width))
						{
							
							System.out.print("* ");
						
						}
				
						else
						{
							System.out.print("  ");
						}
				
					}
					System.out.println();
				}
				
				System.out.println("Width :"+width+" Height :"+height);
				break;
			case 2:
				System.out.println("Filled Shape ");

				for(int i=1;i<=height;i++)
				{
					for(int j=1;j<=width;j++)
					{
				
						if((i==1 || i==height) || (j==1 || j==width))
						{
							System.out.print("* ");
						}
				
						else
						{
							System.out.print("* ");
						}
				
					}
					System.out.println();
				}
				System.out.println("Width :"+width+" Height :"+height);
				break;
			}
		
				break;
				
		case 3:
			
			display1();
			select = input.nextInt();
		System.out.print("Enter Width :");
		width = input.nextInt();
		switch (select)
		{
		case 0 :
			System.out.println(" ...EXIT...");
			System.exit(0);
			break;
		case 1:
		System.out.println("Empty Shape ");
		int i,j,k;
		for(i=1;i<=width;i++)
		{
			for(j=width-i;j>=1;j--)
			{
				System.out.print(" ");
			}
			
				for(k=1;k<=i;k++)
				{
					if(k==1 || k==i || i==width)
						System.out.print("*"+" ");
					else
						System.out.print(" "+" ");
				}
				
				
				System.out.println();
			}
		break;
		case 2:
			System.out.println("Filled Shape ");
			
			for(i=1;i<=width;i++)
			{
				for(j=width-i;j>=1;j--)
				{
					System.out.print(" ");
				}
				
					for(k=1;k<=i;k++)
					{
						if(k==1 || k==i || i==width)
							System.out.print("*"+" ");
						else
							System.out.print("*"+" ");
					}
					
					
					System.out.println();
				}
			break;
			}
		}
			}
			
		}

			
				

	

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.