Hi the project i have is
Write a program that displays diamonds as text using a character provided by the user. For example,
a diamond of height 6 constructed from asterisks will display as follows:
__*
_***
*****
*****
_***
__*
(I cant make it line up perfectly... )
after finishing making the project and turn in the code to the server for the robot to check the mistakes i ended up failing many tests.
one of those tests were the NoCharacter test which tests whether no character was entered at the appropriate prompt. If no character was entered, it will prompt again.
The test Lower tests lower case. Additionally, the character it chooses to use is a space. Therefore, the output is a diamond of spaces.
i tried doing this by myself for a whole week and i came here to find some help since the due day has already passed
how do you make it prompt again after certain amount time and make spaces with diamond??
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
String input;
String character;
do
{
System.out.print("Enter diamond size (\"short\", \"average\", or \"tall\"): ");
input = kb.next().toLowerCase();
}
while (checkSize(input) == -1);
do
{
System.out.print("Enter pattern character: ");
character = kb.next();
}
while (character.length() > 1);
char ch = character.charAt(0);
displayPattern(checkSize(input), ch);
}
public static int checkSize(String size)
{
if (size.equals("short"))
{
return 6;
}
else if (size.equals("average"))
{
return 12;
}
else if (size.equals("tall"))
{
return 22;
}
return -1;
}
public static void displayPattern (int size, char ch)
{
int i,j,k;
for(i = size / 2; i > 0; i--)
{
for(j = 1; j < i; j++)
{
System.out.print(" ");
}
for(k = size; k >= j * 2; k--)
{
System.out.print(ch);
}
System.out.println();
}
for (i = 1; i <= size / 2; i++)
{
for(j = 1; j < i; j++)
{
System.out.print(" ");
}
for(k = size; k >= j * 2; k--)
{
System.out.print(ch);
}
System.out.println();
}
}
}