Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Menu {
- public static int id=0;
- public static ArrayList<AnimalClass> animalArray = new ArrayList<AnimalClass>();
- public static Scanner readerInt = new Scanner(System.in);
- public static Scanner readerString = new Scanner(System.in);
- public static void main(String[] args) {
- System.out.println("Welcome in to Animal Shelter Mnager");
- for(;;) {
- System.out.println("1.add animal");
- System.out.println("delete animal");
- System.out.println("edit anmial");
- System.out.println("show animal status");
- System.out.println("info");
- System.out.println("Type what you want to do");
- String choice = readerString.nextLine();
- switch (choice) {
- case "add animal":
- addAnimal();
- break;
- case "delete animal":
- deleteAnimal();
- break;
- case "edit animal":
- editAnimal();
- break;
- case "show status":
- showAnimalStatus();
- break;
- case "info":
- info();
- break;
- case "exit":
- System.exit(0);
- }
- }
- }
- public static void addAnimal() {
- id++;
- System.out.println("Age:");
- int age = readerInt.nextInt();
- System.out.println("Type:");
- String type = readerString.nextLine();
- System.out.println("Acceptance date:");
- int acceptanceDate = readerInt.nextInt();
- System.out.println("Name:");
- String name = readerString.nextLine();
- animalArray.add(new AnimalClass(id,age,acceptanceDate,type,name));
- }
- public static void deleteAnimal() {
- System.out.println("Id of animal:");
- int deleteId = readerInt.nextInt();
- for (AnimalClass pet: animalArray){
- if (pet.getId()==deleteId){
- animalArray.remove(deleteId);
- }
- }
- }
- public static void editAnimal() {
- System.out.println("Enter animal id");
- int editID = readerInt.nextInt();
- for (AnimalClass pet: animalArray) {
- if(editID==pet.getId()){
- System.out.println("Enter what you want to edit (age, acceptance date, type, name):");
- String editChoice = readerString.nextLine();
- switch (editChoice) {
- case "age":
- System.out.println("Enter new age:");
- int newAge = readerInt.nextInt();
- pet.setAge(newAge);
- break;
- case "acceptance date":
- System.out.println("Enter new date:");
- int newAccDate = readerInt.nextInt();
- pet.setAcceptanceDate(newAccDate);
- break;
- case "type":
- System.out.println("Enter new type:");
- String newType = readerString.nextLine();
- pet.setType(newType);
- break;
- case "name":
- System.out.println("Enter new name:");
- String newName = readerString.nextLine();
- pet.setName(newName);
- break;
- }
- }
- }
- }
- public static void showAnimalStatus() {
- for (AnimalClass pet: animalArray) {
- System.out.println("id: " + pet.getId() + " Age: " + pet.getAge() + " Acceptance date: " +
- pet.getAcceptanceDate() + " Type: " + pet.getType() + " Name: " + pet.getName());
- }
- }
- public static void info() {
- System.out.println("Enter animal id");
- int infoID = readerInt.nextInt();
- for (AnimalClass pet: animalArray) {
- if(infoID==pet.getId()){
- System.out.println("id: " + pet.getId() + " Age: " + pet.getAge() + " Acceptance date: " +
- pet.getAcceptanceDate() + " Type: " + pet.getType() + " Name: " + pet.getName());
- } /*else {
- System.out.println("There is no animal with this id.");
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement