Java - Pets Inventory

Maintain an inventory of pets.

Pets Class (Source)

package model;

public abstract class Pet{
    String department;
    String species;
    Integer qty;
    Integer price;

    public Pet(String newDepartment, String newSpecies, int newQty, int newPrice){
        this.department = newDepartment;
        this.species = newSpecies;
        this.qty = newQty;
        this.price = newPrice;

    public String toString(){
        return "\nSpecies: " + species + "\nQuantity: " + qty + "\nPrice: $" + price;

Pets Class (Model)

//ArrayLists for class Pet and class Menu
ArrayList<Pet> pets = new ArrayList<>();
ArrayList<Menu> menu = new ArrayList<>();
private HashMap<String,Integer> priceList = new HashMap<>();

//Clients can call to pre-load pets into the pets ArrayList
public void loadPets(){
    pets.add(new Mammal("Mammal","Dog",10,300));
    pets.add(new Mammal("Mammal","Cat",15,100));
    pets.add(new Mammal("Mammal","Hamster",50,20));
    pets.add(new Mammal("Mammal","Guinea Pig",5,40));
    pets.add(new Mammal("Mammal","Elephant",6,1000000));
    pets.add(new Bird("Bird","Finch",12,150));
    pets.add(new Bird("Bird","Canary",8,120));
    pets.add(new Bird("Bird","Parrot",2,200));
    pets.add(new Bird("Bird","Cockatiel",0,180));
    pets.add(new Fish("Fish","Goldfish",150,10));
    pets.add(new Fish("Fish","Catfish",2,15));
    pets.add(new Fish("Fish","Guppy",75,20));
    pets.add(new Reptile("Reptile","Chameleon",3,80));
    pets.add(new Reptile("Reptile","Iguana",6,75));
    pets.add(new Reptile("Reptile","Anole",8,50));
    pets.add(new Reptile("Reptile","Gecko",12,60));

    //Put matching species and price in hashmap
    for(Pet p: pets){

Inventory Class (Model)

Inventory inventory = new Inventory();

/* Load the model.Menu for the program */
inventory.loadMenu("/add (petname)", "//increments pet by one");
inventory.loadMenu("/sell (petname)", "//decreases pet by one");
inventory.loadMenu("/get (petname)", "//displays pet price");
inventory.loadMenu("/set (petname) (price)", "//update price");
inventory.loadMenu("/list", "//displays all pets");
inventory.loadMenu("/help", "//displays the command list");
inventory.loadMenu("/exit", "//terminates the program");

Mammal, Bird, Reptile & Fish Class (Model)

package model;

public class Mammal extends Pet{
    public Mammal(String newDepartment, String newSpecies, int newQty, int newPrice){
        super(newDepartment, newSpecies, newQty, newPrice);

    public String toString( ){
        return "This doesn't matter because I prefer the pretty formating of Inventory.listPets()";

List Pets

//List all pets
public void listPets(){
    System.out.printf("%-1s %-20s %-17s %16s %20s \n"," ","Species","Department","Stock","Retail Price($)");
    for(Pet p : pets){
        System.out.printf("%-1s %-20s %-17s %16s %20s \n"," ",p.species,p.department,p.qty,p.price);

Add/Remove Pet

//Increment the specified pet by one
public void addPet(String newSpecies, Integer newAmount){
    Boolean doesExist = false;
    for(Pet p : pets){
            doesExist = true;
            Integer oldQty = p.qty;
            p.qty += newAmount;
            System.out.println("Stock has changed for " + p.species + " to " + p.qty + " from " + oldQty);
    if(doesExist == false){
        System.out.println("Error: Pet does not exist.");


Menu List

  Command                        Information                                    
  /add (petname)                 //increments pet by one                        
  /sell (petname)                //decreases pet by one                         
  /set (petname) (price)         //set or update price for pet                  
  /get (petname)                 //displays pet price                            
  /list                          //displays all pets                             
  /help                          //displays the command list                     
  /exit                          //terminates the program                       

List of Pets

  Species              Department                   Stock      Retail Price($)
  Dog                  Mammal                          10                  500
  Cat                  Mammal                          15                  100
  Hamster              Mammal                          50                   20
  Guinea Pig           Mammal                           5                   40
  Elephant             Mammal                           6              1000000
  Finch                Bird                            12                  150
  Canary               Bird                             8                  120
  Parrot               Bird                             2                  200
  Cockatiel            Bird                             0                  180
  Goldfish             Fish                           150                   10
  Catfish              Fish                             2                   15
  Guppy                Fish                            75                   20
  Chameleon            Reptile                          3                   80
  Iguana               Reptile                          6                   75
  Anole                Reptile                          8                   50
  Gecko                Reptile                         12                   60