• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Classes and methods

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic