JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
21 days ago4 views
👨‍💻Programming

import java.util.Scanner;


public class RunAmountDue {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        AmountDue due = new AmountDue();

        System.out.println("Press any of the following then enter values separated by spaces:");
        System.out.println("1 - Price only");
        System.out.println("2 - Price and quantity");
        System.out.println("3 - Price, quantity, and discount amount");

        int choice = input.nextInt();

        double amountDue;

        switch (choice) {
            case 1:
                double price = input.nextDouble();
                amountDue = due.computeAmountDue(price);
                break;

            case 2:
                price = input.nextDouble();
                int quantity = input.nextInt();
                amountDue = due.computeAmountDue(price, quantity);
                break;

            case 3:
                price = input.nextDouble();
                quantity = input.nextInt();
                double discount = input.nextDouble();
                amountDue = due.computeAmountDue(price, quantity, discount);
                break;

            default:
                System.out.println("Invalid choice.");
                input.close();
                return;
        }

        System.out.println("Amount due is " + amountDue);

        input.close();
    }
}


class AmountDue {

    public double computeAmountDue(double price) {
        return price + (price * 0.12);
    }

   
    public double computeAmountDue(double price, int quantity) {
        double total = price * quantity;
        return total + (total * 0.12);
    }


    public double computeAmountDue(double price, int quantity, double discount) {
        double total = (price * quantity) - discount;
        return total + (total * 0.12);
    }
}
← Back to timeline