Thread: array problem
View Single Post
  #1 (permalink)  
Old 12-11-2007, 06:13 PM
wats wats is offline
Member
 
Join Date: Dec 2007
Posts: 1
wats is on a distinguished road
array problem
I am trying to create an array of a custom class. the user is asked with util scanner ("What kind of ant? (1 for Queen, 2 for Worker and 3 for Drone or -99 to quit)"); and the choice of the array are printed and the program ends when they enter a sentinel value. Here is the code I have so far.

Code:
public class driver { public static void main(String Args[]) { ant z = new ant(); z.set_ant(); ant ar[] = new ant[3]; int count = 0; while(z.get_ant-ar() != "end") { ar[count] = z.get_ant_ar(); count++; System.out.println(ar[count]); } } }
Code:
import java.util.Scanner; public class ant extends insect { Scanner input = new Scanner(System.in); private int z; private String ant; public void set_ant() { System.out.println("What kind of ant? (1 for Queen, 2 for Worker and 3 for Drone or -99 to quit)"); z = input.nextInt(); } } public String get_ant_ar() { if(z == 1) ant = "Queen"; if(z == 2) ant = "Worker"; if(z == 3) ant = "Drone"; return "ant"; } }
Reply With Quote
Sponsored Links