008-006-009

Passing Method Return Values as Arguments

Hard

Problem Description

Passing method Return Values as Arguments

In this problem, you will create a program that reads a base price and tax rate from Scanner, chains the return values of three methods (calculateTax, addTax, formatPrice) to calculate and display the tax-inclusive price to standard output.

Learning Objective: Understand the pattern of passing method return values directly as arguments to other methods

Overview

Create a program that calculates the tax-inclusive price from a base price and tax rate. Split each operation into methods and pass return values between them.

Specifications

  1. calculateTax(int price, double rate): Calculate tax amount and return as int (truncate decimals)
  2. addTax(int price, int tax): Return the tax-inclusive price
  3. formatPrice(int price): Return a string in format Price: <price> yen
  4. Read base price (int) and tax rate (double) from Scanner in main
  5. Chain the return values of all 3 methods to produce the final output

Input Example

1000
0.1

Output Format

Tax: 100
Price: 1100 yen

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