package com.codegym.task.task15.task1521;
import java.math.BigDecimal;
/*
OOP: Method overloading
1. The Tree class must implement the info(Object s) method.
2. The Tree class must implement the info(Number s) method.
3. The Tree class must implement the info(String s) method.
4. The info(Number s) method should display a line similar to the line for the info(Object s) method, replacing only "Object method" with "Number method".
5. The info(String s) method should display a line similar to the line for the info(Object s) method, replacing only "Object method" with "String method".
*/
public class Solution {
public static void main(String[] args) {
// Block 2.
// Call for Objects
new Tree().info((Object)new Integer("4"));
new Tree().info((Object)new Short("4"));
new Tree().info((Object)new BigDecimal("4"));
// Block 3.
// Call for Numbers
new Tree().info(new Integer("4"));
new Tree().info(new Short("4"));
new Tree().info(new BigDecimal("4"));
// Block 4.
// Call for Strings
new Tree().info(new String("4"));
new Tree().info(new Integer("4").toString());
new Tree().info(new Short("4").toString());
new Tree().info(new BigDecimal("4").toString());
}
}
Andrea
Level 20
Not sure why validation is not being met
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Dhiraj
7 August 2020, 18:52
It should be as given below :-
public class Tree {
public static int globalNumber;
public int number;
public Tree() {
this.number = ++globalNumber;
}
public void info(Object s) {
System.out.println(String.format("Tree No. %d , Object method, parameter: %s", number, s.getClass().getSimpleName()));
}
public void info(String s) {
System.out.println(String.format("Tree No. %d , String method, parameter: %s", number, s.getClass().getSimpleName()));
}
public void info(Number s) {
System.out.println(String.format("Tree No. %d , Number method, parameter: %s", number, s.getClass().getSimpleName()));
}
}
0
Andrea
12 October 2019, 03:01
Hmm, I did a reset of the task and re-did it, this time adding the two methods to the Tree class similar to how the info (Object s) is created:
public void info(String s) {
System.out.println(String.format("Tree No. %d, String method, parameter: %s",number, s.getClass().getSimpleName()));
}
public void info(Number s) {
System.out.println(String.format("Tree No. %d, Number method, parameter: %s",number, s.getClass().getSimpleName()));
}
Re-run it and get the expected output:
Tree No. 1 , Object method, parameter: Integer
Tree No. 2 , Object method, parameter: Short
Tree No. 3 , Object method, parameter: BigDecimal
Tree No. 4, Number method, parameter: Integer
Tree No. 5, Number method, parameter: Short
Tree No. 6, Number method, parameter: BigDecimal
Tree No. 7, String method, parameter: String
Tree No. 8, String method, parameter: String
Tree No. 9, String method, parameter: String
Tree No. 10, String method, parameter: String
However the Validation still fails on the last two requirements, so I'm suspecting there's an issue with how this validation is working.
0
Guadalupe Gagnon
11 October 2019, 01:48
Maybe something that you copied and pasted on is messing up the verification system. Sometimes this happens to me and just resetting the task and redoing it works.
0