Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classes and methods

 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Mark
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic