Tuesday, April 2, 2013

Drawing in Java flag: danghwangwa Really Need Help?

Main issue by thomas: Drawing flags in Java: stumped and really need help?

I am really stumped on how to do this, my assignment is to make a program that can draw various flags of the world when prompted. We were given a skeleton of code (shown below) but I do not know where to begin. I don’t want everything done since I want to know how to do this myself, but can someone give code for the first flag or at least tell me where I can begin? I think I need a main method to get this to run at all but i dont know where to start with that. Note that the first flag is the easiest: Top half of the flag is red while the bottom half of the flag is white.


package studentCode;

import java.awt.Color;

import java.util.Scanner;


import GridTools.MyGrid;


public class FlagMaker {


/* Draws a single flag as indicated by the second parameter */

/* into the grid passed as the first parameter */

public static void drawFlag(MyGrid grid, int countryCode) {


Scanner scanner = new Scanner(System.in);


/* Get input from user about what flag to draw */

System.out.println(“Type the number corresponding to the name: “);

System.out.println(“1 Indonesia”);

System.out.println(“2 Lithuania”);

System.out.println(“3 Rwanda”);

System.out.println(“4 Malta”);

System.out.println(“5 Afghanistan”);

System.out.println(“6 Eritrea”);

System.out.println(“7 Macedonia”);

System.out.println(“8 The Bahamas”);

System.out.println(“9 Zimbabwe”);

System.out.print(“Your choice here:”);

int choice = scanner.nextInt();

System.out.print(“Choose a size (4 or larger): “);

int size = scanner.nextInt();


}


Truly focused on Drawing flags in Java: stumped and really need help? you will desire to clear up dilemmas in their own business. We hope this will help to in several ways; and also make everything considerably better. Desiring focused on Drawing flags in Java: stumped and really need help? should be an answer sooner or later.

Optimum solution:


Answer by deonejuan

this line…

import GridTools.MyGrid;

is a non-standard Java library. Hopefully, they gave you methods there to make flags.


The bare-bones code they gave you would run a terminal and prompt for 1 – 9 and again for >4. You would write on the next line a switch statment


switch( choice ) {


case 1: // Indonesia flag chosen

int x1 = (grid.width() / 2) – ( size * rectangle.width() ) / 2;

int y1 = (grid.height() / 2 ) – ( size * rectangle.height() ) / 2;

// that gives you the top lefthand x,y to draw a rectangle

// other methods of grid to draw with

break;



case 3:

… // draw the Rwanda

break;


default:

System.out.println( choice + ” is not a valid selection”);

}


We don’t know what tools you have been given in GridTools.MyGrid. You should have a javadoc listing what MyGrid can do and it will be like:

grid.setColor( Color.red );

grid.fill( topBox );


That part you will have to research


Figure out far better?

Add your ultimate answer in the comments!


Get the X Factor Indonesia songs on iTunes: www.itunes.com/xfactorindonesia Subscribe now for more X Factor Indonesia videos: http://youtube.com/XFactorIndon…


Prambanan, Indonesia


Concept by means of Prambanan, Indonesia


www.indonesia-zsolt72.blogspot.com


Drawing in Java flag: danghwangwa Really Need Help?

No comments:

Post a Comment

Blog Archive