Question
1. Output your name and Solution
2. Prompt for and read a character
3. Repeat while the character is not ‘X’
a. Prompt for and read an integer
b. If the integer is <= 0 or > 10, Print an error message
Else if the character is not ‘A’..’D’, Print an error message
Else print the design specified by the character (see the chart below)
c. Prompt for and read another character
4. Print program complete
These are the designs to be printed. The design is determined by the character and the number of asterisks to print is determined by the integer. Here are examples.
‘A’ Print a left justified triangle with the longest row on the bottom
‘B’ Print a left justified triangle with the longest row on the top
‘C’ Print a right justified triangle with the longest row on the bottom
‘D’ Print a right justified triangle with the longest row on the top
Requirements:
1. Other than the error messages and prompts, your program must output only one character (either ‘*’ or a blank) at a time. Use println as needed.
2. Nested for loops must be used to print the designs.
3. A while loop must be used for the outer loop.
4. A switch must be used to determine which design to print.
Restrictions:
1. Use only the following type of statements.
a. sequence (declaration, assignment, input, output)
b. decision (if-else, switch)
c. repetition (while, for)
2. Do not use any other types of statements. If in doubt, ask.
3. Do not use arrays or Strings for printing the designs.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.util.Scanner;public class Solution {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
char inChar = ' ';
int inNum = 0;
while(inChar != 'X')
{
System.out.print("Please enter in a character: ");
inChar = input.next().charAt(0);
if(inChar != 'X')
{
System.out.print("Please enter an integer: ");
inNum = input.nextInt();
if(inNum <= 0 || inNum > 10)
System.err.println("Incorrect number entered");
else if(inChar < 'A' || inChar > 'D')
System.err.println("Incorrect character entered");
}
switch(inChar)
{
case('A'):
for(int i = 0; i < inNum; i++)
{
for(int j = 0; j <= i; j++)
System.out.print("*");
System.out.println();
}
break;
case('B'):
for(int i = 0; i < inNum; i++)
{
for(int j = 0; j < inNum-i; j++)
System.out.print("*");
System.out.println();
}
break;...