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
calculateTax(int price, double rate): Calculate tax amount and return as int (truncate decimals)addTax(int price, int tax): Return the tax-inclusive priceformatPrice(int price): Return a string in formatPrice: <price> yen- Read base price (int) and tax rate (double) from Scanner in main
- 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