Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Menu {
  5.  
  6. public static int id=0;
  7.  
  8. public static ArrayList<AnimalClass> animalArray = new ArrayList<AnimalClass>();
  9.  
  10. public static Scanner readerInt = new Scanner(System.in);
  11.  
  12. public static Scanner readerString = new Scanner(System.in);
  13.  
  14. public static void main(String[] args) {
  15.  
  16. System.out.println("Welcome in to Animal Shelter Mnager");
  17.  
  18. for(;;) {
  19. System.out.println("1.add animal");
  20. System.out.println("delete animal");
  21. System.out.println("edit anmial");
  22. System.out.println("show animal status");
  23. System.out.println("info");
  24. System.out.println("Type what you want to do");
  25. String choice = readerString.nextLine();
  26.  
  27. switch (choice) {
  28. case "add animal":
  29. addAnimal();
  30. break;
  31. case "delete animal":
  32. deleteAnimal();
  33. break;
  34. case "edit animal":
  35. editAnimal();
  36. break;
  37. case "show status":
  38. showAnimalStatus();
  39. break;
  40. case "info":
  41. info();
  42. break;
  43. case "exit":
  44. System.exit(0);
  45. }
  46. }
  47. }
  48.  
  49.  
  50. public static void addAnimal() {
  51. id++;
  52. System.out.println("Age:");
  53. int age = readerInt.nextInt();
  54.  
  55. System.out.println("Type:");
  56. String type = readerString.nextLine();
  57.  
  58. System.out.println("Acceptance date:");
  59. int acceptanceDate = readerInt.nextInt();
  60.  
  61. System.out.println("Name:");
  62. String name = readerString.nextLine();
  63.  
  64. animalArray.add(new AnimalClass(id,age,acceptanceDate,type,name));
  65. }
  66.  
  67. public static void deleteAnimal() {
  68. System.out.println("Id of animal:");
  69. int deleteId = readerInt.nextInt();
  70. for (AnimalClass pet: animalArray){
  71. if (pet.getId()==deleteId){
  72. animalArray.remove(deleteId);
  73. }
  74. }
  75.  
  76. }
  77.  
  78. public static void editAnimal() {
  79. System.out.println("Enter animal id");
  80. int editID = readerInt.nextInt();
  81. for (AnimalClass pet: animalArray) {
  82. if(editID==pet.getId()){
  83. System.out.println("Enter what you want to edit (age, acceptance date, type, name):");
  84. String editChoice = readerString.nextLine();
  85.  
  86. switch (editChoice) {
  87. case "age":
  88. System.out.println("Enter new age:");
  89. int newAge = readerInt.nextInt();
  90. pet.setAge(newAge);
  91. break;
  92. case "acceptance date":
  93. System.out.println("Enter new date:");
  94. int newAccDate = readerInt.nextInt();
  95. pet.setAcceptanceDate(newAccDate);
  96. break;
  97. case "type":
  98. System.out.println("Enter new type:");
  99. String newType = readerString.nextLine();
  100. pet.setType(newType);
  101. break;
  102. case "name":
  103. System.out.println("Enter new name:");
  104. String newName = readerString.nextLine();
  105. pet.setName(newName);
  106. break;
  107. }
  108.  
  109. }
  110. }
  111. }
  112.  
  113. public static void showAnimalStatus() {
  114. for (AnimalClass pet: animalArray) {
  115. System.out.println("id: " + pet.getId() + " Age: " + pet.getAge() + " Acceptance date: " +
  116. pet.getAcceptanceDate() + " Type: " + pet.getType() + " Name: " + pet.getName());
  117. }
  118.  
  119. }
  120.  
  121. public static void info() {
  122. System.out.println("Enter animal id");
  123. int infoID = readerInt.nextInt();
  124. for (AnimalClass pet: animalArray) {
  125. if(infoID==pet.getId()){
  126. System.out.println("id: " + pet.getId() + " Age: " + pet.getAge() + " Acceptance date: " +
  127. pet.getAcceptanceDate() + " Type: " + pet.getType() + " Name: " + pet.getName());
  128. } /*else {
  129. System.out.println("There is no animal with this id.");
  130. }*/
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement