Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
0
Indexable
Never
import java.util.Scanner;

public class AbleCounterApp {
    public static void main(String[] args) {
        AbleCounter counter = new AbleCounter();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("1. Add Able");
            System.out.println("2. Remove Able");
            System.out.println("3. Get Total Able Count");
            System.out.println("4. Exit");
            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.print("Enter the count of able to add: ");
                    int addCount = scanner.nextInt();
                    counter.addAble(addCount);
                    break;
                case 2:
                    System.out.print("Enter the count of able to remove: ");
                    int removeCount = scanner.nextInt();
                    counter.removeAble(removeCount);
                    break;
                case 3:
                    System.out.println("Total Able Count: " + counter.getTotalAbleCount());
                    break;
                case 4:
                    System.exit(0);
                default:
                    System.out.println("Invalid choice. Please try again.");
            }
        }
    }
}

class AbleCounter {
    private int totalAbleCount;

    public AbleCounter() {
        this.totalAbleCount = 0;
    }

    public void addAble(int count) {
        totalAbleCount += count;
    }

    public void removeAble(int count) {
        if (totalAbleCount >= count) {
            totalAbleCount -= count;
        } else {
            System.out.println("Insufficient able count.");
        }
    }

    public int getTotalAbleCount() {
        return totalAbleCount;
    }
}