Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class GerbilLab {
- private static String ID = null;
- private static String name = null;
- static int numberOfTypes;
- static int numberOfGerbils;
- static Gerbil gerbilArray[];
- public static void main(String[] args) {
- Scanner keyboard= new Scanner(System.in);
- String foodName = null, gerbilID, gerbilName;
- String choice;
- int consume=0;
- boolean isBite=true;
- boolean isFlight=true;
- do {
- int maxConsume=0;
- System.out.println("Please input how many types of food the gerbils eat");
- numberOfTypes= keyboard.nextInt();
- Food [] foodArray = new Food[numberOfTypes];
- Food types = null;
- for(int i=0; i<numberOfTypes; i++){
- System.out.println("Name of food item "+(i+1));
- foodName = keyboard.next();
- types.setName(foodName);
- foodArray[i] = types;//something is wrong with this
- System.out.println("Max consumed per gerbil");
- maxConsume= keyboard.nextInt();
- types.setConsume(maxConsume);
- types = new Food(foodName,maxConsume);
- }
- Gerbil newGerbil = new Gerbil(ID, name, consume, isBite, isFlight);
- System.out.println("How many gerbils are in the lab?");
- numberOfGerbils=keyboard.nextInt();
- Gerbil[] gerbilArray = new Gerbil[numberOfGerbils];
- for (int j=0; j<numberOfGerbils; j++){
- gerbilArray[j] = newGerbil;
- System.out.println("Gerbil "+(j+1)+"'s lab ID:");
- String ID = keyboard.next();
- newGerbil.setID(ID);//how to get user input to seed the gerbilArray
- if (j == 1){
- if( newGerbil.getID() == ID){
- System.out.println("Error, the ID you just input is a duplicate. Try again");
- }
- }
- System.out.println("What name did the undergrad give "+ ID);
- String name = keyboard.next();
- int [] consumeArray = new int[numberOfTypes];
- for (int k=0; k<numberOfTypes; k++) {
- System.out.println(ID + " eats how many "+ foodArray[k].foodName + "'s per day");
- consume = keyboard.nextInt();
- consumeArray[k] = consume;
- if (consume > maxConsume){
- do {
- System.out.println("The food consumption you input is more than the daily max consumption of that particular food. Please try again");
- k--;
- } while (consume <= maxConsume);
- }
- }
- for(int m=0; m < numberOfGerbils; m++){
- for (int n=0; n< numberOfGerbils; n++){
- Gerbil temp = gerbilArray[n];
- gerbilArray[m] = gerbilArray[n];
- gerbilArray[n] = temp;
- }
- }
- System.out.println("Does " + ID + " bite? Please answer with true or false");
- String n = keyboard.next();
- do{
- if(!(n.equalsIgnoreCase("true") || n.equalsIgnoreCase("false"))){
- System.out.println("You have input something other than true or false, please try again");
- n = keyboard.next();
- }
- isBite = Boolean.parseBoolean(n);
- }while (!(n.equalsIgnoreCase("true") || n.equalsIgnoreCase("false")));
- System.out.println("Does " + ID + " try to escape? Please answer with true or false");
- String o = keyboard.next();
- do{
- if(!(o.equalsIgnoreCase("true") || o.equalsIgnoreCase("false"))){
- System.out.println("You have input something other than true or false, please try again");
- o = keyboard.next();
- }
- isFlight = Boolean.parseBoolean(o);
- }while(!(o.equalsIgnoreCase("true") || o.equalsIgnoreCase("false")));
- }
- System.out.println("What would you like to know? Please choose from: average, search, restart, quit.");
- choice = keyboard.next();
- if (choice.equals("average".toLowerCase())){
- averageFood();
- }
- if (choice.equals("search".toLowerCase())){
- searchForGerbil(choice);
- }
- if (choice.equals("restart".toLowerCase())){
- }
- if (choice.equals("quit".toLowerCase())){
- System.out.println("Thank you for using GerbilLab");
- }
- }while(choice.equals("restart"));
- }
- public static String averageFood(){
- //code goes here for averageFood method
- return null;
- }
- public static Gerbil searchForGerbil(String choice){
- //code goes here for SearchForGerbil method
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement