I am new to Java and have to do this for a class:
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:
*
***
*****
*****
***
*
Besides specifying a character, the user will specify one of three possible heights for each diamond – 6, 12, or 22 – by providing one of the strings “short”, “average”, or “tall”.
Write the following methods in the program:
• Public static int checkSize(String size) – This method will return 6 if size equals “short”, 12 if size equals “average”, 22 if size equals “tall”, or -1 otherwise. Be sure that the comparison is not case sensitive.
• Public static void displayPattern (int size, char ch) – This method will display a diamond of height size constructed from pattern character ch.
Use a do-while loop in the main method to verify that the diamond size that user enters must be “short”, “average”, or “tall”. If invalid string is input, the program should ask for new input until the valid input is given.
All of the help I found online was to make diamond shapes off of predetermined values for the shape. so im having some difficulty doing it how the assignment asks for it.
my code thus far:
im getting a bunch of errors stating that java compiler can "not find symbols" for n and pimport java.util.Scanner; public class Diamonds { public static void main(String[] args) { Scanner kb = new Scanner(System.in); do { System.out.println("enter diamond size (short, average, or tall):"); String size = kb.nextString(); equalIgnoreCase(size); }while (size != "short" || "average" || "tall"); int s = checkSize(size); System.out.println("enter pattern character:"); Char p = kb.nextChar(); displayPattern(s,p); } public static int checkSize(String size) { if (size = "short") { return 6; } else if (size = "average") { return 12; } else if (size = "tall") { return 22; } else { return -1; } } public static void displayPattern (int size, char ch) { for (int s = 6; s <= n; s++) { for (int j = 0; j < (n - s); j++) System.out.print(" "); for (int j = 1; j <= s; j++) System.out.print(p); for (int k = 1; k < s; k++) System.out.print(p); System.out.println(); } for (int s = n - 1; s >= 1; s--) { for (int j = 0; j < (n - s); j++) System.out.print(" "); } }
any help would be great.
thankyou