/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package petzoogarden; import java.util.Scanner; import java.io.*; import java.util.Arrays; /** * * @author jcmt * * For June 13, make an animal class and then put those in the array in zoo */ public class PetZoo { private int numAnimals; private String[] animals = new String[42]; private double zooChow; private int numVisitors; private double revenue; private static boolean goodZooGuyZoo = true; private int[][] longnecks = {{3, 15},{2, 48},{1, 17,14}}; private final int MAXSIZE = 75; /* * private String[] animals; * animals = new STring[42]; * */ public static void setGoodZooGuyZoo(boolean goodZooGuyZoo) { PetZoo.goodZooGuyZoo = goodZooGuyZoo; } public void setLongnecks(int[][] longnecks) { this.longnecks = longnecks; } public PetZoo() { numAnimals = 0; zooChow = 0.0; numVisitors = 0; revenue = 0.0; } public PetZoo(int nA, double zC) { numAnimals = nA; zooChow = zC; numVisitors = 0; revenue = 0.0; } public PetZoo(PetZoo joes) { numAnimals = joes.numAnimals; zooChow = joes.zooChow; numVisitors = joes.numVisitors; revenue = joes.revenue; } public int getNumAnimals() { return numAnimals; } public boolean setNumAnimals(int numAnimals) { if (numAnimals >= 0) { this.numAnimals = numAnimals; return true; } return false; } public String[] getAnimals() { return animals; } public double getZooChow() { return zooChow; } public int getNumVisitors() { return numVisitors; } public double getRevenue() { return revenue; } public String getOneAnimal(int ani) { if (ani <= 42) { return this.animals[ani]; } else { return ""; } } public void setAnimals(String[] animals) { this.animals[4] = "elephant"; this.animals[5] = "lion"; this.animals[2] = "tiger"; this.animals[3] = "bear"; int index = 0; for(String curr: this.animals) { if (index < animals.length ) { this.animals[index] = animals[index]; index++; } } for(String curr: this.animals) { System.out.println("another "+curr); } } public boolean setOneAnimal(String animal) { if (numAnimals < 42) { this.animals[numAnimals] = animal; this.numAnimals++; return true; } else { System.out.println("Animal storage is full"); return false; } } public void setZooChow(double zooChow) { this.zooChow = zooChow; } public void setNumVisitors(int visitors) { numVisitors = visitors; } public void setRevenue(double revenue) { Scanner input = new Scanner(System.in); while (revenue < 0) { System.out.print("Please enter a positive number: "); /* try */ if (revenue >= 0) { revenue = input.nextDouble(); } else throw new ArithmeticException("out of range"); /* catch(Exception ie) { System.out.print("Input exception, you knucklehead"); revenue = 0.0; } */ } this.revenue = revenue; } public String toRevString() { return String.format("Current revenue is $%7.2f",revenue); } }