-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject3.java
More file actions
96 lines (80 loc) · 2.37 KB
/
Project3.java
File metadata and controls
96 lines (80 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
Cesar Marin
Project 3, TA: Ghazaleh Beigi
This program asks the user for input, a character (A-D) and an integer (1-10) and prints a design
based on the character chosen, and the length(height) of the integer.
*/
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3
{
public static void main(String[]args)
{
System.out.println("Cesar Marin");
System.out.println("Project 3");
System.out.println();
Scanner in = new Scanner (System.in);
String character = JOptionPane.showInputDialog ("Please enter a character (A-D, X to stop): ");
char ch = character.charAt(0);
//------------------------------------------------------------------------------------------------------------
while(ch!= 'X' && ch!='x')
{
System.out.println("Please enter and integer 1-10");
int lines = in.nextInt();
if(lines <=0 || lines >10){
System.out.println("Error: integer outside of range");
System.out.println();
}
else if(ch < 'A' || ch> 'D')
{
System.out.println("Error, character is out of range");
character = JOptionPane.showInputDialog ("Please enter another character (A-D, X to stop): ");
ch = character.charAt(0);
}
else
{
switch(ch)
{
case 'A':
for (int row = 1; row <= lines; row++)
{
for (int star = 1; star <= row; star++)
System.out.print ("*");
System.out.println();
}
break;
case 'B':
for (int row = 1; row <= lines; row++)
{
for (int star = lines; star >= row; star--)
System.out.print ("*");
System.out.println();
}
break;
case 'C':
for (int row = 1; row <= lines; row++)
{
for (int spaces = lines - 1; spaces >= row; spaces--)
System.out.print (" ");
for (int star = 1; star <= row; star++)
System.out.print("*");
System.out.println();
}
break;
case 'D':
for (int row = 1; row <= lines; row++)
{
for (int spaces = 0; spaces <= row; spaces++)
System.out.print (" ");
for (int star = lines; star >= row; star--)
System.out.print("*");
System.out.println();
}
break;
}
character = JOptionPane.showInputDialog ("Please enter another character (A-D, X to stop): ");
ch = character.charAt(0);
}
}
}
}