This lab sheet contains work that is to be submitted for assessmentand will contribute to 3% of the finalmark in this unit.
Submission is viaDetails concerning what must be undertaken and submitted are given below.
Acknowledgement: the flag pictures and information come from the. Theflag selection was based purely on the suitability of the images fora computer graphics project.
In this lab we will write a class called FlagDrawer
thatwill have methods for drawing a variety of flags. In the lab session, we will help for drawing the first 10 flags (the Libya flag is excluded). You must be very creative if you want get the full marks. Do as many of themas you can!
For example, the Luxembourg flag (height:width 3:5) looks like this:
We could draw it as follows:
public void drawLUX(int width) { int height = width * 3 / 5; SimpleCanvas c = new SimpleCanvas("Luxembourg flag", width, height); // This draws the top stripe as a bunch of horizontal lines c.setForegroundColour(java.awt.Color.red); for (int i = 0; i < height/3; i++) { c.drawLine(0, i, width, i); } // This draws the bottom stripe the same way c.setForegroundColour(java.awt.Color.cyan); for (int i = height * 2 / 3; i < height; i++) { c.drawLine(0, i, width, i); }}
Make sure you understand drawLUX
before you start.Note the following.
SimpleCanvas
being an instance variable ofFlagDrawer
, we will get eachmethod to create its own SimpleCanvas
with the correctproportions.Each method takes as its argument the width of the flag, then it sets the height accordingly. Your methods must work for any reasonable value of width
.height/3
horizontal red lines at the top andthe same number of horizontal cyan lines at the bottom, leaving (notionally) white lines in-between.java.awt.Color
for the standard colours used here. You can access the interface and documentation for this class from the BlueJ Tools
menu. The class also provides methods for constructing less common colours: probably easiest to use is the Color
constructor that takes three int
s. (Your colours don't need to be absolutely precise, though.) c
will bedestroyed; however the actual window on your screen will not bedeleted. This means that if you call the method again, youwill get a new window.The FlagDrawer
class should implement as many of the following methods as you can.
public void drawUKR(int width)
public void drawFR(int width)
public void drawTH(int width)
public void drawGA(int width)
public void drawUAE(int width)
public void drawFI(int width)
public void drawSW(int width)
public void drawCB(int width)
public void drawQ(int width)
public void drawSC(int width)
public void drawSY(int width)
public void drawJP(int width)
public void drawGD(int width)
public void drawSA(int width)
public void drawSK(int width)
public void drawAG(int width)
public void drawAB(int width)
public void drawHK(int width)
public void drawAN(int width)
public void drawWS(int width)
Each method should drawthe flag of the country whose code is in the method name. You may just omit the methods you do not want to submit.The final exam usually contains a flag-drawing question, so selecting only the easiest flags is likely to be costlyin the long run. Also notice that the Libyan flag is deliberately omitted from your list of choices.
You must ensure that your method signatures match the above or they will not be marked. No validator is provided, and no JUnit tests are provided: test your methods by inspecting the flags drawn for various values of width
. We recommend that you follow the CS-readability checkstyle rules.
Marks will be allocated as follows:
Your flags do not have to be pixel-perfect, but they must be clearly recognisable by eye. You must have roughly the right colours, and the right markings with roughly the right shapes and dimensions.