Small java challenge - Sajha Mobile
SAJHA MOBILE
Small java challenge
Posts 7 · Viewed 6403 · Go to Last Post
zeePa
· Snapshot
Like · Likedby · 0
This is small java challenge to all java beginners, and pros. Well i am trying to do it and not yet being able to work it out!

Let me see if you can get it to work...

 "Write overloaded Java methods that return the difference of two parameters. Your methods should contain the logic to return the difference of the larger parameter – smaller parameter, regardless of parameter order. Provide enough test code to ensure your methods are logically correct. The following table displays the required method parameter variations.

 
Parm 1 Type              Parm 2 Type                           Return Type
int                                      int                                         Int
double                            double                                    double
int                                   double                                    double
double                                int                                       double

Continue to properly document your source code."

 



KillEmAll
· Snapshot
Like · Liked by · 0
what part r u stuck @? what does your pseudo code look like?
yellow
· Snapshot
Like · Liked by · 0
I am new to java myself, not Sure if it has templetes.

If it was C++ you can make one Templete instad of overloading function with variaty of parameters.
If you start writing functions ( or methods) the possible combinations of parameters can be quite high, and redundant.

I like the cast but then again the question asks for difference, ( which might get messed up because of loss of data). Hope someone can come up with solution.

P.S If its just int and double, there are only four Methods to be written, which should be a no brainier.
sathi_mero
· Snapshot
Like · Liked by · 0
Its better to post ur queries related to java in java forum... the url is java-forums.org.. u'll get perfect guidance...
techGuy
· Snapshot
Like · Liked by · 0
Hope you know what function overloading is. Here are the declarations for overloaded method diff().  This is just to give you a start. Define these functions, test the defined functions from the main with different parameters.
public int diff(int a , int b, int c);
public double diff(double a, double b, double c);
public double diff(int a, double b, double c);
public double diff(double a, int b, double c);



Post your code. If you are stuck somewhere.

PS: Use some IDE like Eclipse or Netbeans  that will save ur time.
Last edited: 13-Oct-08 05:50 PM
yellow
· Snapshot
Like · Liked by · 0
Thanks Suike for the info on Generics. I will do  some more research.. but why do you say careful with login ID ?

Also, why dont people Google for stuffs. and with all due respect, I don't think our fellow Nepalis know about other forums besides Sajha
yellow
· Snapshot
Like · Liked by · 0
Suike you are scaring me dude, I have hardly had 20 posts in Sajha, and this nick yellow. I have not used anywhere. and yet you know who I am.

Not just programing skills, you have some serious social engineering skillz.

*bows*

Now How do I find out who you are. ( how to send Msg in this forum)
Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 9 · Viewed 12535 · Likes 1
· Posts 7 · Viewed 3920 · Likes 1
· Posts 1 · Viewed 1082
· Posts 1 · Viewed 1060
· Posts 1 · Viewed 967
· Posts 1 · Viewed 1062
· Posts 1 · Viewed 1034
· Posts 21 · Viewed 9888 · Likes 1
· Posts 3 · Viewed 2541
· Posts 5 · Viewed 7747 · Likes 1



Your Banner Here
Travel Partners
Travel House Nepal