010-002-006

Method Overloading: Tax Calculation

Easy

Problem Description

method overloading: Tax Calculation

In this problem, you will create a program that implements 3 overloaded calculateTax methods with different parameter counts, reads input values from standard input, and displays each calculated tax amount.

Learning Objective: Use method overloading with different parameter counts in practical scenarios

Create 3 types of calculateTax methods. Define a 1-parameter version (price only), a 2-parameter version (price × quantity), and a 3-parameter version (price × quantity − discount).

Method Definitions

  1. calculateTax(int price): Tax on single price (price × 0.1)
  2. calculateTax(int price, int quantity): Tax on total amount (price × quantity × 0.1)
  3. calculateTax(int price, int quantity, double discountRate): Tax after discount (price × quantity × (1 - discountRate) × 0.1)

Input

price1
price2 quantity2
price3 quantity3 discountRate3
  • Line 1: price for the 1-argument version (integer)
  • Line 2: price and quantity for the 2-argument version (integers, space-separated)
  • Line 3: price, quantity, and discount rate for the 3-argument version (int int double, space-separated)

Output

[tax1]
[tax2]
[tax3]

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up