Write the following Java program:
public static String getFlag(int size, char color1, char color2,
char color3) - This method returns a string where a triangle
appears on the left size of the diagram, followed by horizontal
lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y');
will generate the string:
R............................................
RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRRRR....................................
RRRRRRRRR....................................
RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
R............................................
The diagram has a number of rows that corresponds to size * 2 and a number of colums that corresponds to size * 5. The first and last row will use color2 (except for the first character that will use color1). The center two rows will use color2 and the rest color3. The triangle will rely on color1 and will have a height corresponding to size * 2. If the size parameter is less than three, the method will return null and will not generate any diagram. For this method you can assume the colors are valid. The method MUST not rely on System.out.println().
If you have any doubts, please give me comment...
public class DrawingApp {
public static void main(String[] args) {
System.out.println(DrawingApp.getFlag(9, 'R', '.', 'Y'));
}
public static String getFlag(int size, char color1, char color2, char color3) {
String result = "";
for (int i = 0; i < size; i++) {
for (int j = 0; j <= i; j++)
result += color1;
for (int j = 0; j < (size*5) - i - 1; j++) {
if (i == 0 || i == size - 1)
result += color2;
else
result += color3;
}
result += "\n";
}
for (int i = size - 1; i >= 0; i--) {
for (int j = 0; j <= i; j++)
result += color1;
for (int j = 0; j < (size*5) - i - 1; j++) {
if (i == 0 || i == size - 1)
result += color2;
else
result += color3;
}
result += "\n";
}
return result;
}
}

Write the following Java program: public static String getFlag(int size, char color1, char color2, char color3)...
public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y'); will generate the string: R............................................ RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRR.................................... Write a Java program and the result has to match the pattern which showed above.
Write a Java method . public static boolean upChecker(char [][] wordSearch, String word, int row, int col) This method does the following: compare the first character from word to the character in puzzle[row][col] if they match subtract one from row (to check the previous character in the same column) and continue comparing characters, by advancing to the next character in word else if puzzle[row][col] is NOT part of puzzle array or the character in the cell does not match the...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
(IN JAVA) Write a program named Review.java and implement the following methods: public static boolean isValidTicTacToeBoardString(String str) This method takes as its parameter a String that contains 9 characters representing the status of the Tic Tact Toe game. The String is mixed with X, O, x, o, and other letters. The first three letters represent the first row, letter 4 through letter 6 represent the second row, and the rest for the last row. To be considered as a valid...
Step 2: Create the method specified below. static int GetValidWidth(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero width entered by the user Step 3: Create the method specified below. static int GetValidHeight(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero positive height entered by the user Step 4: Create the method specified below. static void DisplayBox(int width, int height, char fillChar) Input parameters width: width of each...
Java code about writing two methods: public static String randomStringone(int length) public static String randomStringtwo(int length) This method should return a String of random lowercase letters with the given length by using for loops. To generate a random lowercase letter, use a local Random variable and the method nextInt() to generate a number between 97 and 122, then cast the result to a char. The method nextInt() can be found here: https://www.geeksforgeeks.org/java-util-random-nextint-java/ In randomStringone(), you should use String concatenation...
Given the following classes: StringTools.java: public class StringTools { public static String reverse(String s){ char[] original=s.toCharArray(); char[] reverse = new char[original.length]; for(int i =0; i<s.length(); i++){ reverse[i] = original[original.length-1-i]; } return new String(reverse); } /** * Takes in a string containing a first, middle and last name in that order. * For example Amith Mamidi Reddy to A. M. Reddy. * If there are not three words in the string then the method will return null * @param name in...
Java
Here is the template
public class ShiftNumbers {
public static void main(String[] args) {
// TODO: Declare matrix shell size
// TODO: Create first row
// TODO: Generate remaining rows
// TODO: Display matrix
}
/**
* firstRow
*
* This will generate the first row of the matrix, given the size n. The
* elements of this row will be the values from 1 to n
*
* @param size int Desired size of the array
* @return...
Can anyone please solve this for me in java. Thanks Complete the program below that prints a square. The program will read the size (an integer value) of the square and a character. It will then generate a square with a number of rows and columns that corresponds to size, and where the * character is used for the square border. The provided character will be used for the rest of the diagram. Use the message “Enter size:” and “Enter...
How can i print a diamond implementing these methods public static void printNChars(int n, char c)). This method will print n times the character c in a row, public static void printDiamond(int size, char edgeChar, char fillChar). This method will call printNChars() method to print the shape. It will use the edgeChar to print the sides and the fillChar to fill the interior of the shape. The shape will have a height and a width of the given size. public...