i was asked to write a program that will display a diamond and a hollow diamond. It need to ask the user to input the size and character, which to form the diamond, and must use 3 methods.
• Public static int checkSize(String size) – This method will return 6 if size equals “short”, 12 if size equals “average”, 24 if size equals “tall”, or -1 otherwise. Be sure that the comparison is not case sensitive.
• Public static void displayDiamond (int size, char ch) – This method will display a diamond of height size constructed from pattern character ch.
• Public static void displayHollowDiamond (int size, char ch) – This method will display a hollow diamond of height size constructed from pattern character ch.
in main method i had to use a do-while loop also, until the user input "short","average","tall", for size of 6,12,24.
an output of "short" should look like ( "o"means space
oo*
o***o
*****
*****
o***o
oo*
oo*
o*oo*o
*oooo*
*oooo*
o*oo*
oo*
And here is what i have so far (ive only completed the hollow diamond and no idea what to do for the other 2 methods.)
import java.util.Scanner;
public class Diamonds
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
String input;
do
{
System.out.print("enter diamond size (\"short\", \"average\", or \"tall\"): ");
input = kb.nextLine();
}while();
System.out.print("enter pattern character: ");
char character = kb.nextChar();
}
public static int checkSize(String size)
{
if(size!=
}
public static void displayDiamond(int size, char ch)
{
}
public static void displayHollowDiamond(int size, char ch)
{
int i, j, k, l;
for(i=1, i<=size; i++)
k = i<=size/2 ? 2*1-1 : 2*(size-i+1)-1;
j = (size-k)/2;
for(l=0; l<k; l++)
System.out.print(" ");
for(l=0; l<k; l++)
if(l==0 || l==k-1)
System.out.print(ch);
else
System.out.print(" ");
System.out.println();
}
}
any hint and helps??
