Hi all,
If someone please could explain this task. note that I already found the solution to the problem.
since the the covertClassToUsd is static, why do I still need to create an Object to call the method? Thanks in advance.
Static
Resolved
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
8 April 2020, 20:12
Can you paste your Solution program code here? I would like to see that object you're talking about.
((In my solution i just used the converting method by passed values.))
0
Lawrence Babay
9 April 2020, 00:57
Hi Gallert,
Thanks for your reply. Please see below.
package com.codegym.task.task03.task0303;
/*
Currency exchange
*/
public class Solution {
public static void main(String[] args) {
//write your code here
Solution solution = new Solution();
System.out.println(solution.convertEurToUsd(5, 2.5));
System.out.println(solution.convertEurToUsd(4, 2.5));
}
public static double convertEurToUsd(int eur, double exchangeRate) {
//write your code here
double usDollars = eur * exchangeRate;
return usDollars;
}
}
Thanks in advance!
0
Gellert Varga
9 April 2020, 01:56solution
I think you don't need to create any object.
Comment out that line.
Try this way:
// Solution solution = new Solution();
System.out.println(convertEurToUsd(5, 2.5));
System.out.println(convertEurToUsd(4, 2.5));
and the program will work well. (To call the converting method works this way too.)
(Here you can try out a lot of versions of your programs:
https://www.jdoodle.com/online-java-compiler/ )
+3
Lawrence Babay
9 April 2020, 02:49
Thanks Gallert. I initially tried that but it was no avail. I believe it's because how the task is design. Thanks again.
0
Pavlo Plynko Java Developer at CodeGym
9 April 2020, 13:12
Apparently, you tried something differently, since the Gellert's variant accepted by the validator.
+2
Lawrence Babay
9 April 2020, 13:49
Hi Eren,
Would you please point out what I did differently in the code that I posted? Thanks.
0
Gellert Varga
9 April 2020, 14:34
Hi Lawrence!
I don't know if the code with object was accepted by the verifier or not.
But i think the program worked well that way too. I tested it.
I just wanted to say that it is not necessary to create an object for the program to work.
And that it works very well with this simpler solution as well.
And if you still have questions, feel free to write:)
+3
Pavlo Plynko Java Developer at CodeGym
10 April 2020, 02:42
I didn’t mean the code that you posted, but the one you wrote about here:
+2
Lawrence Babay
11 April 2020, 17:11
Hi Gallert,
Thanks for your awesome response I also tried running it in the console w/o creating the objects and I received an output. Like I said before it's maybe how the task was designed. Thanks again I appreciate your explanations. Cheers!
0
Gellert Varga
11 April 2020, 20:35
Not at all!:)
0