Question: Write a Java program: public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears

Write a 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(4, '*', 'B', 'G'); will generate the string:

*BBBBBBBBBBBBBBBBBBB **GGGGGGGGGGGGGGGGGG ***GGGGGGGGGGGGGGGGG ****BBBBBBBBBBBBBBBB ****BBBBBBBBBBBBBBBB ***GGGGGGGGGGGGGGGGG **GGGGGGGGGGGGGGGGGG *BBBBBBBBBBBBBBBBBBB

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().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!