File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Classes and methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classes and methods" Watch "Classes and methods" New topic

Classes and methods

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
Hi all,

I have posted this topic before ,but nobody helped me out. Please help me out...........
I am not sure how to go about . Can anyone please explain me how go with the convertYards() method.SO tht the value passed is converted to type Distances(newyard).

Q : Convert a feet variable of type Test. For example ,6002 feet is converted to 2feet,240 yards,1mile.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I think you will want to add setters and getters to set and get the feet, yards and miles, because when you pass a Distances class, you will not be able to see those instance variables.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
marc weber

Joined: Aug 31, 2004
Posts: 11343

Note: The getter and setter methods that Mark suggested are public methods that access private fields. For example...

(Search the forums for "encapsulation.")

You might also want a constructor that accepts these parameters. That is, Distance(int mi, int yd, int ft){...}.

Now, to be clear... Are you looking for a method that will take yards as input, and return (a reference to) a new instance of Distance that will have the input value expressed as miles, yards, and feet? For example, you call convertYards(1770L); and it returns a new Distance object in which miles = 1, yards = 3, and feet = 1?

If so, then this should get you started: The method will need to divide the long argument by YARDS_IN_MILE and truncate to get miles as an int. Then take the remainder of that division and...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: Classes and methods
It's not a secret anymore!