So, polymorphism. You haven't forgotten about it, have you? Good. Then let's complete the following task: Read data from the console until the word "exit" is entered. For each value (except "exit"), call the print method. The correct print method depends on the value. For example, if the value contains a period, then use the print method for Double. If the value is a number between 0 and 128, then use the method for short.
Different methods for different types
- 16
Locked
Comments (8)
- Popular
- New
- Old
You must be signed in to leave a comment
Florin1
29 June 2022, 22:07
As a subtle hint for solving this problem:
The comma and the period have different meanings for different countries, when talking about numbers. Pay extra attention to the express, -albeit- mandatory, period requirement mentioned in the exercise.
0
Tasmoda Android Developer
23 June 2022, 15:36
After 3 good days of about 5 hours per day, I get it rightðŸ˜
We will always emerge victorious, every single time!
0
Ajani
9 May 2022, 21:49
well F. I spent a whole day learning regex and matching expressions. while working on a converted character string and the codegym answer cuts my code in half simply by embracing the errors thrown by incorrect casting. I came the long way on this one, and ill say even if your way is inefficient you should still follow through because you will learn more, and be more likely to remember the shorter way when you do look at it after you finish.
0
Jonaskinny Java Developer at Sandmedia
3 March 2022, 01:56
Good exercise for how to use exceptions and efficient logic
0
Justin Smith
19 August 2021, 14:56
When I first started CodeGym, I think it would often say something like "5700 people have completed this task" but now it's only 1274. People quitting?
Also, I feel kind of bad because at the beginning I was getting everything in one attempt and it was better than average. Now it takes me more tries than the average for most of these tasks. If it takes me more tries than average, is that a bad sign for becoming a java developer?
0
Jonaskinny Java Developer at Sandmedia
3 March 2022, 01:50
No, its a good sign. Its a sign you ...
a- are doing them yourself == learning
b- are OK with continuing to learn in the face of frustration
0
Aakankasha Sharma
13 March 2021, 16:53
If the number has all zeroes after the decimal it should be considered as a Double, and not Integer. (eg 22.000)
0
Oliver Heintz
20 January 2021, 00:26
I was so thrilled with my solution to this problem, and I wanted to see how I shaped up against the solution on CodeGym, so I downloaded their solution. What I did in 69 lines of code they did in only 53. Disappointing, but their logic was the same, they just had tighter code. For example, I had two try-catch blocks instead of just one, and three if-else statements, instead of just two. It was good to see how I could improve, and wish I had DLed more solutions in the past, now.
+2