Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class GerbilLab {
  4. private static String ID = null;
  5. private static String name = null;
  6. static int numberOfTypes;
  7. static int numberOfGerbils;
  8. static Gerbil gerbilArray[];
  9.  
  10. public static void main(String[] args) {
  11. Scanner keyboard= new Scanner(System.in);
  12. String foodName = null, gerbilID, gerbilName;
  13. String choice;
  14. int consume=0;
  15. boolean isBite=true;
  16. boolean isFlight=true;
  17. do {
  18. int maxConsume=0;
  19. System.out.println("Please input how many types of food the gerbils eat");
  20. numberOfTypes= keyboard.nextInt();
  21. Food [] foodArray = new Food[numberOfTypes];
  22. Food types = null;
  23. for(int i=0; i<numberOfTypes; i++){
  24. System.out.println("Name of food item "+(i+1));
  25. foodName = keyboard.next();
  26. types.setName(foodName);
  27. foodArray[i] = types;//something is wrong with this
  28. System.out.println("Max consumed per gerbil");
  29. maxConsume= keyboard.nextInt();
  30. types.setConsume(maxConsume);
  31. types = new Food(foodName,maxConsume);
  32. }
  33.  
  34.  
  35. Gerbil newGerbil = new Gerbil(ID, name, consume, isBite, isFlight);
  36. System.out.println("How many gerbils are in the lab?");
  37. numberOfGerbils=keyboard.nextInt();
  38. Gerbil[] gerbilArray = new Gerbil[numberOfGerbils];
  39. for (int j=0; j<numberOfGerbils; j++){
  40. gerbilArray[j] = newGerbil;
  41. System.out.println("Gerbil "+(j+1)+"'s lab ID:");
  42. String ID = keyboard.next();
  43. newGerbil.setID(ID);//how to get user input to seed the gerbilArray
  44. if (j == 1){
  45. if( newGerbil.getID() == ID){
  46. System.out.println("Error, the ID you just input is a duplicate. Try again");
  47. }
  48. }
  49.  
  50. System.out.println("What name did the undergrad give "+ ID);
  51. String name = keyboard.next();
  52. int [] consumeArray = new int[numberOfTypes];
  53. for (int k=0; k<numberOfTypes; k++) {
  54. System.out.println(ID + " eats how many "+ foodArray[k].foodName + "'s per day");
  55. consume = keyboard.nextInt();
  56. consumeArray[k] = consume;
  57. if (consume > maxConsume){
  58. do {
  59. System.out.println("The food consumption you input is more than the daily max consumption of that particular food. Please try again");
  60. k--;
  61. } while (consume <= maxConsume);
  62. }
  63. }
  64.  
  65. for(int m=0; m < numberOfGerbils; m++){
  66. for (int n=0; n< numberOfGerbils; n++){
  67. Gerbil temp = gerbilArray[n];
  68. gerbilArray[m] = gerbilArray[n];
  69. gerbilArray[n] = temp;
  70. }
  71. }
  72.  
  73.  
  74. System.out.println("Does " + ID + " bite? Please answer with true or false");
  75. String n = keyboard.next();
  76. do{
  77. if(!(n.equalsIgnoreCase("true") || n.equalsIgnoreCase("false"))){
  78. System.out.println("You have input something other than true or false, please try again");
  79. n = keyboard.next();
  80. }
  81. isBite = Boolean.parseBoolean(n);
  82.  
  83. }while (!(n.equalsIgnoreCase("true") || n.equalsIgnoreCase("false")));
  84.  
  85. System.out.println("Does " + ID + " try to escape? Please answer with true or false");
  86. String o = keyboard.next();
  87. do{
  88. if(!(o.equalsIgnoreCase("true") || o.equalsIgnoreCase("false"))){
  89. System.out.println("You have input something other than true or false, please try again");
  90. o = keyboard.next();
  91. }
  92. isFlight = Boolean.parseBoolean(o);
  93. }while(!(o.equalsIgnoreCase("true") || o.equalsIgnoreCase("false")));
  94.  
  95.  
  96.  
  97. }
  98.  
  99. System.out.println("What would you like to know? Please choose from: average, search, restart, quit.");
  100. choice = keyboard.next();
  101.  
  102. if (choice.equals("average".toLowerCase())){
  103. averageFood();
  104.  
  105. }
  106. if (choice.equals("search".toLowerCase())){
  107. searchForGerbil(choice);
  108.  
  109. }
  110. if (choice.equals("restart".toLowerCase())){
  111.  
  112. }
  113. if (choice.equals("quit".toLowerCase())){
  114. System.out.println("Thank you for using GerbilLab");
  115. }
  116. }while(choice.equals("restart"));
  117. }
  118. public static String averageFood(){
  119. //code goes here for averageFood method
  120. return null;
  121. }
  122. public static Gerbil searchForGerbil(String choice){
  123. //code goes here for SearchForGerbil method
  124. return null;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement