I am working on this assignment to draw the flag of Liberia for my essentials of computer programming class.
I finished it but had extra time to kill and noticed that a couple similar blocks of code are not very concise and could be shortened with a loop, but right now I can't seem to form the code just right!
Below I have included one of the methods that I would like to shorten:
public static void flagOfLiberia(Graphics g) {
Expo.setBackground(g,Expo.black);
for (int d = 1; d <= numDots; d++) {
int x = Expo.random(0,1000);
int y = Expo.random(0,650);
if (x < 300 && y < 300)
Expo.setColor(g,Expo.darkBlue);
else if (y < 50)
Expo.setColor(g,Expo.red);
else if (y < 100)
Expo.setColor(g,Expo.white);
else if (y < 150)
Expo.setColor(g,Expo.red);
else if (y < 200)
Expo.setColor(g,Expo.white);
else if (y < 250)
Expo.setColor(g,Expo.red);
else if (y < 300)
Expo.setColor(g,Expo.white);
else if (y < 350)
Expo.setColor(g,Expo.red);
else if (y < 400)
Expo.setColor(g,Expo.white);
else if (y < 450)
Expo.setColor(g,Expo.red);
else if (y < 500)
Expo.setColor(g,Expo.white);
else if (y < 550)
Expo.setColor(g,Expo.red);
else if (y < 600)
Expo.setColor(g,Expo.white);
else if (y < 650)
Expo.setColor(g,Expo.red);
drawDot(g,x,y);
Expo.setColor(g,Expo.white);
Expo.fillStar(g,150,150,100,5);
}
showName(g,"Liberia");
}