Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Learning Objectives Practice using variables to draw graphics that scale relative to the window size Practice using loops to repeat actions Practice using nested loops

Learning Objectives

  • Practice using variables to draw graphics that scale relative to the window size
  • Practice using loops to repeat actions
  • Practice using nested loops

Pretend you are the Scientist-in-Chief at the United States Institute of Heraldry (Links to an external site.). Your assignment is to create a program that can generate alternate versions of the U.S. flag (within certain constraints).

Part 1

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 a demo video of the program in action, for your reference: https://youtu.be/Pi3V_SXOqc0 (Links to an external site.)

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.

After you have finished:

  • Create a video of yourself explaining your code and demonstrating your program. Be sure to discuss each of the items on the rubric below!
  • I recommend using the free screencast-o-matic software for this (instructions (Links to an external site.)).
  • Upload your source code file(s) to Canvas on or before the deadline.
  • Upload your video file to Canvas too. Ideally, you will upload your video the same day as your code, but it's OK if you submit the video up to seven days after the due date. However, you will not receive any points until both your code and video are submitted.

RUBRIC:

  1. Explain how you calculate the width of the blue box. (3 points)
  2. Explain how you calculate the height of the blue box. (3 points)
  3. Explain how you calculate the width of the stripes. (3 points)
  4. Explain how you calculate the height of the stripes. (3 points)
  5. Explain how you calculate the size of the stars/circles. (3 points)
  6. Demonstrate that the flag scales so that it exactly fills the window. (3 points)
  7. Demonstrate that the top stripe is red. (2 points)
  8. Demonstrate that the blue box covers the height of the top 7 stripes. (2 points)
  9. Demonstrate that the blue box covers 2/5 of the width of the entire flag. (2 points)
  10. Demonstrate that the white stars (circles) extend the entire width and height of the blue box. (2 points)
  11. Demonstrate that the flag scales correctly when the window is resized. (2 points)
  12. The flag scales correctly when you change the number of stripes and the number of star rows/columns. (3 points)
  13. Show that each major section of the program is commented. (1 point)
  14. Show that your source code is neatly and consistently indented. (1 point)
  15. Show that all your variable and method names start with a lowercase letter. (1 point)
  16. Show that all your class names start with an uppercase letter. (1 point)

------------------------------------------------------- TOTAL: 35 points

Extras:

  • (+5 points) EXTRA CREDIT: Make a second program that draws a picture of the flag of your home country or state. In your video, demonstrate that your program draws your home flag, and explain your code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions