CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Andrea
Level 20
  • 11.10.2019
  • 730views
  • 3comments

Not sure why validation is not being met

Question about the task OOP: Method overloading
Java Core,  Level 5,  Lesson 12
Under discussion

1. In the Tree class, overload the info(Object s) method twice to get three methods: info(Object s), info(Number s), and info(String s).
1.1. Study the info(Object s) method. Create similar functionality in the new methods.
1.2. For example, the result for the info(Number s) method might be "Tree No. 123, Number method, Short parameter".

Requirements:
  • The Tree class must implement the info(Object s) method.
  • The Tree class must implement the info(Number s) method.
  • The Tree class must implement the info(String s) method.
  • 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".
  • 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".
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()); } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Dhiraj
Level 17 , Brussels, Belgium
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
Level 20 , United States
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
Level 37 , Tampa, United States
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
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.