Question: Write a Java application that draws a simplified U.S. flag. Here are the requirements: The top stripe must be red, and every stripe below will

Write a Java application that draws a simplified U.S. flag. Here are the requirements:

  • The top stripe must be red, and every stripe below will alternate between white and red.
  • All stripes must be the same height.
  • The blue box must be in the top-left corner.
  • The blue box's height should be equal to the height of 7 stripes.
  • The blue box's width must be 2/5 of the width of the entire flag.
  • The blue box must be covered with white stars (ovals, in our case).
  • The white ovals must be all the same size.
  • The flag must scale cleanly when the window is resized.

Hints

  • Fill in the entire background as either red or white, then draw in the stripes of the other color.
  • Draw the blue rectangle next, and the stars last.
  • Use for loops to draw the stripes and stars.
  • Use lots of variables! Calculate the height of the stripes, the width & height of the blue box, the width/height of the stars (etc.) and store them in variables for use in your drawing commands. At the very least, you must store the number of stripes, the number of star-rows, and the number of star-columns in variables, as you will be modifying these at run-time in Part 2 (below).
  • For testing/debugging, first try using 13 stripes, 6 rows of stars, and 8 columns of stars (this is what the flag looked like in 1958, incidentally). Then change them and make sure everything still works.
  • Here is the demo video https://youtu.be/Pi3V_SXOqc0

Part 2

Instead of hard-coding the number of stripes and star rows/columns in your code, prompt the user to enter these in a series of three JOptionPane pop-up boxes.

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!