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 ago2 views
👨‍💻Programming
public class AmountDue {

    // Price of one item + 12% tax
    public double computeAmountDue(double price) {
        return price * 1.12;
    }

    // Price × quantity + 12% tax
    public double computeAmountDue(double price, double quantity) {
        return (price * quantity) * 1.12;
    }

    // Price × quantity - discount + 12% tax
    public double computeAmountDue(double price, double quantity, double discount) {
        return (price * quantity - discount) * 1.12;
    }
 
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();
                double quantity = input.nextDouble();
                amountDue = due.computeAmountDue(price, quantity);
                break;

            case 3:
                price = input.nextDouble();
                quantity = input.nextDouble();
                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();
    }
}
← Back to timeline