Untitled

 avatar
unknown
java
4 years ago
1.5 kB
6
Indexable
public class Library {

    private int countOfChairs;
    private int countOfTables;
    private int countOfBooks;


    private boolean validateDecrease(int modifiedValue, int count){
        return modifiedValue >= count;
    }

    public void addChairs(int count){
        this.countOfChairs += count;
    }
    public void addTables(int count){
        this.countOfTables += count;
    }
    public void addBooks(int count){
        this.countOfBooks += count;
    }

    public void removeChairs(int count){
        if (validateDecrease(this.countOfChairs, count))
            this.countOfChairs -= count;
        else throw new IllegalArgumentException("There are no so many chairs in library");
    }
    public void removeTables(int count){
        if (validateDecrease(this.countOfTables, count))
            this.countOfTables -= count;
        else throw new IllegalArgumentException("There are no so many tables in library");
    }
    public void removeBooks(int count){
        if (validateDecrease(this.countOfBooks, count))
            this.countOfBooks -= count;
        else throw new IllegalArgumentException("There are no so many books in library");
    }

    public void addChairsAndTablesAndBooks(int countOfChairs, int countOfTables, int countOfBooks){
        this.countOfChairs += countOfChairs;
        this.countOfTables += countOfTables;
        this.countOfBooks += countOfBooks;
    }
    public void addChairsAndTablesAndBooks(){
        countOfBooks++;
        countOfChairs++;
        countOfTables++;
    }
}