010-001-009
Overloading Basics: Print Methods
Hard
Problem Description
Overloading Basics: Print Methods
In this problem, you will create a program that implements three overloaded print methods for int, String, and boolean types, reads values from standard input, and displays each value in the appropriate format to standard output.
Learning Objective: Understand how to implement multiple print methods using overloading to accept different argument types
Overview
Define three print methods in the Printer class using overloading: for int, String, and boolean types. In the Main class, read an integer, string, and boolean from standard input, then call the corresponding print method for each.
Specifications
- Define following three print methods in Printer class
public void print(int value)- output "Integer: value"public void print(String value)- output "String: value"public void print(boolean value)- output "Boolean: value"
- Use Scanner in main method to read from standard input:
- Line 1: int value
- Line 2: String value (no spaces)
- Line 3: boolean value (true or false)
- Pass each read value to the corresponding print method
Input Format
integer_value
string_value
boolean_value
Output Format
Integer: integer_value
String: string_value
Boolean: boolean_value
Sample Input/Output
Input:
42
Hello
true
Output:
Integer: 42
String: Hello
Boolean: true
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