By GokiSoft.com| 15:06 26/06/2023|
Java Basic

Java Basic- OOP - Tổng hợp - Quản lý sở thú BT990

HỆ THỐNG QUẢN LÝ SỞ THÚ

1. Tạo lớp có tên Animal gồm các thuộc tính và phương thức:

· String name

· int age

· ​String description

· void display() //hiển thị tên, tuổi và mô tả của động vật

  void input() //THuc hien nhap thong tin cua Animal

· abstract void showSound()

  Tạo hàm tạo không đối và đầy đủ đối số

  Tạo getter/setter

2. Tạo các lớp Tiger, Dog, Cat theo các yêu cầu sau:

  • Thừa kế từ lớp Animal
  • Ghi đè phương thức showSound() để thể hiện những tiếng kêu đặc trưng của từng loài vật

3. Tạo lớp có tên Room gồm:

· int roomNo

· ​List<Animal> animalList

· void addAnimal() //thêm một con vật vào AnimalList

· void removeAnimal(String name) //xóa con vật có tên tương ứng khỏi AnimalList

  void display() -> Hiển thị thông tin mã chuồng + danh sách động vật

  void input() -> Nhập mã chuồng

  Hàm tạo ko đối và đầy đủ đối số

  Tạo getter/setter

  public Animal createAnimal() -> Cho phép khởi tạo 1 động vật bất kỳ Tiger, Dog, Cat. (Hỏi người dùng động vật cần khỏi tạo 1. Tạo Tiger, 2. Tạo Dog, Khác -> Tạo Cat)

4. Tạo lớp có tên Zoo gồm:

· List<Room> roomList

  Tạo hàm tạo không tối -> Thực hiện khởi tạo roomList = new ArrayList<>() trong hàm tạo này.

  void addAnimal() -> Thực hiện thêm động vật vào chuồng theo mã roomNo

  void removeAnimal() -> Thực hiện xóa động vật theo tên -> trong chuồng có mã roomNo

· void addRoom() //thêm chuồng vào roomList

· void removeRoom() //xóa chuồng có mã tương ứng khỏi roomList

  void display() -> Hiển thị thông tin toàn bộ room được quản lý trong Zoo.

5. Tạo lớp có tên TestZoo chứa phương thức main() để quản lý sở thú theo dạng Menu như sau:

  1. Thêm chuồng
  2. Xóa chuồng
  3. Thêm con vật
  4. Xóa con vật
  5. Xem tất cả các con vật
  6. Thoát

6. Khi người dùng lựa chọn 3 yêu cầu người dùng nhập vào mã chuồng (roomNo) muốn thêm động vật. Và thực hiện thêm 1 động vật (Tiger, Dog, hoặc Cat) vào chuồng với roomNo vừa nhập

7. Khi người dùng lựa chọn 3 yêu cầu người dùng nhập vào mã chuồng (roomNo) muốn xóa động vật. Sau đó yêu cầu người dùng nhập tên động vật cần xóa -> Thực hiện xóa động vật đi.

8. Khi người dùng chọn 5 thì hiển thị thông tin cùng tiếng kêu của từng con vật trong sở thú.

Liên kết rút gọn:

https://gokisoft.com/990

Bình luận

avatar
GokiSoft.com [Teacher]
2021-07-14 02:22:07


#Zoo.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Zoo {
    ArrayList<Room> roomList;
    
    public Zoo() {
        roomList = new ArrayList<>();
    }
    
    public void addRoom(Room r) {
        roomList.add(r);
    }
    
    public void removeRoom(int roomNo) {
        for (int i = 0; i < roomList.size(); i++) {
            if(roomList.get(i).getRoomNo() == roomNo) {
                roomList.remove(i);
                i--;
            }
        }
    }
    
    public void addAnimal(int roomNo, Animal a) {
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.addAnimal(a);
            }
        }
    }
    
    public void addAnimal() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ma chuong can them dong vat: ");
        int roomNo = Integer.parseInt(scan.nextLine());
        
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.addAnimal();
            }
        }
    }
    
    public void removeAnimal(int roomNo, String name) {
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.removeAnimal(name);
            }
        }
    }
    
    public void removeAniamal() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ma chuong can xoa dong vat: ");
        int roomNo = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap ten dong vat can xoa: ");
        String name = scan.nextLine();
        
        removeAnimal(roomNo, name);
    }
    
    public void display() {
        for (Room room : roomList) {
            room.display();
        }
    }
}


#Tiger.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Tiger extends Animal{

    @Override
    public void showSound() {
        System.out.println("Tiger ...");
    }
    
}


#TestZoo.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class TestZoo {
    public static void main(String[] args) {
        Zoo zoo = new Zoo();
        Scanner scan = new Scanner(System.in);
        int choose;
        
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    Room room = new Room();
                    room.input();
                    
                    zoo.addRoom(room);
                    break;
                case 2:
                    System.out.println("Nhap ma chuong can xoa: ");
                    int roomNo = Integer.parseInt(scan.nextLine());
                    
                    zoo.removeRoom(roomNo);
                    break;
                case 3:
                    zoo.addAnimal();
                    break;
                case 4:
                    zoo.removeAniamal();
                    break;
                case 5:
                    zoo.display();
                    break;
                case 6:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 6);
    }
    
    static void showMenu() {
        System.out.println("1. Them chuong");
        System.out.println("2. Xoa chuong");
        System.out.println("3. Them dong vat");
        System.out.println("4. Xoa dong vat");
        System.out.println("5. Xem tat ca dong vat");
        System.out.println("6. Thoat");
        System.out.println("Chon: ");
    }
}


#Room.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Room {
    int roomNo;
    ArrayList<Animal> animalList;
    
    public Room() {
        animalList = new ArrayList<>();
    }

    public int getRoomNo() {
        return roomNo;
    }

    public void setRoomNo(int roomNo) {
        this.roomNo = roomNo;
    }

    public ArrayList<Animal> getAnimalList() {
        return animalList;
    }

    public void setAnimalList(ArrayList<Animal> animalList) {
        this.animalList = animalList;
    }
    
    public void addAnimal(Animal a) {
        animalList.add(a);
    }
    
    public void addAnimal() {
        Animal animal = createAnimal();
        
        animalList.add(animal);
    }
    
    /**
     * TH1: name se la duy nhat
     * TH2: name dong co the trung ten -> code theo cach nay.
     * @param name 
     */
    public void removeAnimal(String name) {
        for (int i = 0; i < animalList.size(); i++) {
            if(animalList.get(i).getName().equalsIgnoreCase(name)) {
                animalList.remove(i);
                //1, 2, 3, 4, 5, 6: length = 6, index = 0 -> 5
                //Xoa di index = 2 (gia tri 3)-> Vi du xu ly dong 50
                //1, 2, 4, 5, 6: Length = 5, index = 0 -> 4
                //index = 2 (gia tri 3 truoc) -> index = 2 (gia tri 4)
                i--;
            }
        }
    }
    
    public void display() {
        System.out.println("Ma Chuong: " + roomNo);
        for (Animal animal : animalList) {
            animal.showSound();
            animal.display();
        }
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ma chuong: ");
        roomNo = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap so dong vat");
        int n = Integer.parseInt(scan.nextLine());
        
        for (int i = 0; i < n; i++) {
            Animal animal = createAnimal();
            animalList.add(animal);
        }
    }
    
    public Animal createAnimal() {
        Scanner scan = new Scanner(System.in);
        Animal animal;
        
        System.out.println("1. Tao Tiger");
        System.out.println("2. Tao Dog");
        System.out.println("Khac. Tao Cat");
        System.out.println("Chon: ");
        int choose = Integer.parseInt(scan.nextLine());
        
        switch(choose) {
            case 1:
                animal = new Tiger();
                break;
            case 2:
                animal = new Dog();
                break;
            default:
                animal = new Cat();
                break;
        }
        animal.input();
        
        return animal;
    }
}


#Dog.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Dog extends Animal{

    @Override
    public void showSound() {
        System.out.println("Dog ...");
    }
    
}


#Cat.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Cat extends Animal{

    @Override
    public void showSound() {
        System.out.println("Cat ...");
    }
    
}


#Animal.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public abstract class Animal {
    String name, description;
    int age;

    public Animal() {
    }

    public Animal(String name, String description, int age) {
        this.name = name;
        this.description = description;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten: ");
        name = scan.nextLine();
        
        System.out.println("Nhap mo ta: ");
        description = scan.nextLine();
        
        System.out.println("Nhap tuoi: ");
        age = Integer.parseInt(scan.nextLine());
    }
    
    public void display() {
        System.out.format("\nTen: %s, tuoi: %d, mo ta: %s\n", name, age, description);
    }
    
    public abstract void showSound();
}


avatar
GokiSoft.com [Teacher]
2021-07-10 12:59:52


#Zoo.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.ArrayList;

/**
 *
 * @author Diep.Tran
 */
public class Zoo {
    ArrayList<Room> roomList;
    
    public Zoo() {
        roomList = new ArrayList<>();
    }
    
    public void addAnimal(int roomNo, Animal animal) {
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.addAnimal(animal);
            }
        }
    }
    
    public void addAnimal(int roomNo) {
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.addAnimal();
            }
        }
    }
    
    public void removeAnimal(int roomNo, String name) {
        for (Room room : roomList) {
            if(room.getRoomNo() == roomNo) {
                room.removeAnimal(name);
            }
        }
    }
    
    public void addRoom(Room room) {
        roomList.add(room);
    }
    
    public void removeRoom(int roomNo) {
        for (int i = 0; i < roomList.size(); i++) {
            if(roomList.get(i).getRoomNo() == roomNo) {
                roomList.remove(i);
                break;//i--;
            }
        }
    }
    
    public void display() {
        for (Room room : roomList) {
            room.display();
        }
    }
    
    public void showSound() {
        for (Room room : roomList) {
            room.showSound();
        }
    }
}


#Tiger.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Tiger extends Animal{

    @Override
    public void showSound() {
        System.out.println("Tiger sound ...");
    }
    
}


#Room.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Room {
    int roomNo;
    ArrayList<Animal> animalList;

    public Room() {
        animalList = new ArrayList<>();
    }
    
    public void addAnimal(Animal a) {
        animalList.add(a);
    }
    
    public void addAnimal() {
        Animal animal = createAnimal();
        animalList.add(animal);
    }
    
    /**
     * Xoa theo name -> Co truong name trung nhau cua Dong Vat
     * @param name 
     */
    public void removeAnimal(String name) {
        for (int i = 0; i < animalList.size(); i++) {
            if(animalList.get(i).getName().equalsIgnoreCase(name)) {
                animalList.remove(i);
                i--;
            }
        }
    }
    
    public void display() {
        System.out.println("RoomNo: " + roomNo);
        for (Animal animal : animalList) {
            animal.display();
        }
    }
    
    public void showSound() {
        System.out.println("RoomNo: " + roomNo);
        for (Animal animal : animalList) {
            animal.showSound();
        }
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ma chuong: ");
        roomNo = Integer.parseInt(scan.nextLine());
        
        System.out.println("Nhap so dong vat can them: ");
        int n = Integer.parseInt(scan.nextLine());
        
        for (int i = 0; i < n; i++) {
            Animal animal = createAnimal();
            animalList.add(animal);
        }
    }
    
    public Animal createAnimal() {
        Animal animal;
        System.out.println("1. Create Tiger");
        System.out.println("2. Create Dog");
        System.out.println("Other. Create Cat");
        System.out.println("Choose: ");
        Scanner scan = new Scanner(System.in);
        int choose = Integer.parseInt(scan.nextLine());
        
        switch(choose) {
            case 1:
                animal = new Tiger();
                break;
            case 2:
                animal = new Dog();
                break;
            default:
                animal = new Cat();
        }
        animal.input();
        
        return animal;
    }

    public int getRoomNo() {
        return roomNo;
    }

    public void setRoomNo(int roomNo) {
        this.roomNo = roomNo;
    }
    
    
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        Zoo zoo = new Zoo();
        Scanner scan = new Scanner(System.in);
        int choose, roomNo;
        
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    Room room = new Room();
                    room.input();
                    zoo.addRoom(room);
                    break;
                case 2:
                    System.out.println("Nhap roomNo can xoa: ");
                    roomNo = Integer.parseInt(scan.nextLine());
                    zoo.removeRoom(roomNo);
                    break;
                case 3:
                    System.out.println("Nhap roomNo can them dong vat: ");
                    roomNo = Integer.parseInt(scan.nextLine());
                    zoo.addAnimal(roomNo);
                    break;
                case 4:
                    System.out.println("Nhap roomNo can xoa: ");
                    roomNo = Integer.parseInt(scan.nextLine());
                    System.out.println("Nhap ten dong vat can xoa: ");
                    String name = scan.nextLine();
                    
                    zoo.removeAnimal(roomNo, name);
                    break;
                case 5:
                    zoo.showSound();
                    break;
                case 6:
                    System.out.println("Thoat!!!");
                    break;
                default:
                    System.out.println("Nhap lai!!!");
            }
        } while(choose != 6);
    }
    
    static void showMenu() {
        System.out.println("1. Them room");
        System.out.println("2. Xoa room");
        System.out.println("3. Them animal");
        System.out.println("4. Xoa animal");
        System.out.println("5. Xem");
        System.out.println("6. Thoat");
        System.out.println("Chon: ");
    }
}


#Dog.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Dog extends Animal{

    @Override
    public void showSound() {
        System.out.println("Dog sound ...");
    }
    
}


#Cat.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

/**
 *
 * @author Diep.Tran
 */
public class Cat extends Animal{

    @Override
    public void showSound() {
        System.out.println("Cat sound ...");
    }
    
}


#Animal.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson05.bt990;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public abstract class Animal {
    String name, description;
    int age;

    public Animal() {
    }

    public Animal(String name, String description, int age) {
        this.name = name;
        this.description = description;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getAge() {
        return age;
    }

    public boolean setAge(int age) {
        if(age >= 0) {
            this.age = age;
            return true;
        } else {
            System.out.println("Yeu cau age >= 0");
        }
        return false;
    }
    
    public void input() {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap ten: ");
        name = scan.nextLine();
        
        System.out.println("Nhap mo ta: ");
        description = scan.nextLine();
        
        System.out.println("Nhap tuoi: ");
        while(!setAge(Integer.parseInt(scan.nextLine()))) {
            System.out.println("Yeu cau nhap lai!!!");
        }
    }
    
    public void display() {
        System.out.printf("\nTen: %s, mo ta: %s, tuoi: %d", name, description, age);
    }
    
    public abstract void showSound();
}


avatar
Do Trung Duc [T2008A]
2021-02-28 08:56:48



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CatManager;

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class Cat {
    String name;

    public Cat() {
    }

    public Cat(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public void NhapthongtinCat(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ten meo: ");
        name = scan.nextLine();
    }
    
    public void HienthiCat(){
        System.out.println("Ten: "+ name);
    }
}


avatar
Do Trung Duc [T2008A]
2021-02-28 08:56:39



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CatManager;

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class CatDetail extends Cat {

    String type;
    String color;
    String lifeAction;

    public CatDetail() {

    }

    public CatDetail(String type, String color, String lifeAction, String name) {
        super(name);
        this.type = type;
        this.color = color;
        this.lifeAction = lifeAction;
    }

    @Override
    public void NhapthongtinCat() {
        Scanner scan = new Scanner(System.in);
        super.NhapthongtinCat();
        System.out.println("Nhap chung loai meo: ");
        type = scan.nextLine();

        System.out.println("Nhap mau sac meo: ");
        color = scan.nextLine();
        
        for(String color: ColorManager.colorList){
            if(this.color.equalsIgnoreCase(color)){
                return;
        }else{
                 System.out.println("Mau vua nhap khong co trong bang mau,Nhap lai mau sac meo: ");
                 this.color = scan.nextLine();
            }
        }

        System.out.println("Nhap tap tinh meo: ");
        lifeAction = scan.nextLine();
    }

    @Override
    public void HienthiCat() {
        super.HienthiCat();
        System.out.println("Loai: " + type);
        System.out.println("Mau sac: " + color);
        System.out.println("Tap tinh: " + lifeAction);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getLifeAction() {
        return lifeAction;
    }

    public void setLifeAction(String lifeAction) {
        this.lifeAction = lifeAction;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }
    
    

}


avatar
Do Trung Duc [T2008A]
2021-02-28 08:56:29



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CatManager;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class ColorManager {

    String colorNo;
    static ArrayList<String> colorList;

    public ColorManager() {
        this.colorList = new ArrayList<>();
    }

    public ColorManager(String colorNo, ArrayList<String> colorList) {
        this.colorNo = colorNo;
       
        this.colorList = colorList;
    }

    public String getColorNo() {
        return colorNo;
    }

    public void setColorNo(String colorNo) {
        this.colorNo = colorNo;
    }

    public ArrayList<String> getColorList() {
        return colorList;
    }

    public void setColorList(ArrayList<String> colorList) {
        this.colorList = colorList;
    }

    public void inputColor(String color) {
        colorList.add(color);
    }
}


avatar
Do Trung Duc [T2008A]
2021-02-28 08:56:17



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CatManager;

import java.util.ArrayList;

/**
 *
 * @author TrungDuc
 */
public class ManagerCat {

    ArrayList<CatDetail> catList;

    public ManagerCat() {
        this.catList = new ArrayList<>();
    }

    public void addCat(CatDetail cat) {
        catList.add(cat);
    }

    public void DisplayallCat() {
        for (int i = 0; i < catList.size(); i++) {
            System.out.format("Con meo thu %d : \n", (i + 1));
            catList.get(i).HienthiCat();
        }
    }

    public void DisplayallCatByColor(String color) {
        for (CatDetail cat : catList) {
            if (cat.getColor().equalsIgnoreCase(color)) {
                cat.HienthiCat();
            }
        }
    }
    
        public void DisplayallCatByType(String type) {
        for (CatDetail cat : catList) {
            if (cat.getType().equalsIgnoreCase(type)) {
                cat.HienthiCat();
            }
        }
    }

}


avatar
Do Trung Duc [T2008A]
2021-02-28 08:56:03



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package CatManager;

import java.util.Scanner;

/**
 *
 * @author TrungDuc
 */
public class UsingManagerCat {

    public static void main(String[] agrs) {

        int choose;
        ManagerCat managerCat = new ManagerCat();
        ColorManager colorManager = new ColorManager();

        do {
            Menu();
            Scanner scan = new Scanner(System.in);
            System.out.println("Nhap lua chon choose = ");
            choose = Integer.parseInt(scan.nextLine());

            switch (choose) {

                case 0:
                    System.out.println("Nhap  mau sac: ");
                    String color = scan.nextLine();
                    colorManager.inputColor(color);
                    break;

                case 1:
                    System.out.println("Nhap so luong meo muon nhap N = ");
                    int N = Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < N; i++) {
                        CatDetail newCat = new CatDetail();
                        newCat.NhapthongtinCat();
                        managerCat.addCat(newCat);
                    }

                    break;

                case 2:
                    managerCat.DisplayallCat();
                    break;

                case 3:
                    System.out.println("Nhap mau sac ban muon tim = ");
                    String colorFind = scan.nextLine();
                    managerCat.DisplayallCatByColor(colorFind);
                    break;

                case 4:
                    System.out.println("Nhap chung loai ban muon tim = ");
                    String typeFind = scan.nextLine();
                    managerCat.DisplayallCatByColor(typeFind);
                    break;

                case 5:
                    for (String onecolor : colorManager.colorList) {
                        for (CatDetail cat : managerCat.catList) {
                            if (cat.getColor().equalsIgnoreCase(onecolor)) {
                                cat.HienthiCat();
                            }
                        }
                    }
                    break;

                case 6:
                    System.out.println("THoat");
                    break;
            }

        } while (choose != 6);

    }

    public static void Menu() {
        System.out.println("0.Nhập danh sách mã màu");
        System.out.println("1.Nhập thông tin của n con mèo");
        System.out.println("2.Hiển thị thông tin");
        System.out.println("3.Sắp xếp danh sách theo mau");
        System.out.println("4.Tìm kiếm thông tin theo loai");
        System.out.println("5. Sắp xếp danh sách màu theo bảng màu trong lớp ColorManager");
        System.out.println("6. Thoát");
    }

}


avatar
Do Trung Duc [T2008A]
2021-02-28 02:29:17



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package zoomanager;

/**
 *
 * @author TrungDuc
 */
public class Tiger extends Animal{
    
}


avatar
Do Trung Duc [T2008A]
2021-02-28 02:29:03



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package zoomanager;

/**
 *
 * @author TrungDuc
 */
public class Lion extends Animal {
    
}


avatar
Do Trung Duc [T2008A]
2021-02-28 02:28:53



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package zoomanager;

/**
 *
 * @author TrungDuc
 */
public class Dog extends Animal{
    
}