ADoyle4

Untitled

May 15th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. //2011 q1(e)
  2. class Distance{
  3. double mile; double yards=1760;
  4.  
  5. Distance(){}//no args constructor (not needed because of line
  6.  
  7. Distance(double mile1, double yard1){//all args constructor
  8. mile = mile1; yards = yard1;
  9. yard1 = 1760;
  10. }
  11.  
  12.  
  13. void getDistance(){
  14. System.out.println("Enter in miles: ");
  15. mile = Console.readDouble();
  16. yards = mile * yards;
  17. System.out.println((int)mile + " miles or " + ((int)yards) + " yards");
  18.  
  19. }
  20. void toStrings(){
  21. if(yards%1760!=0){
  22. System.out.println((int)mile + " miles " + ((int)yards%1760) + " yards " );
  23. }
  24. }
  25. //void add(int addition){
  26. // int total = mile + yards + addition;
  27. //}
  28.  
  29. public static void main (String [] args){
  30. Distance d = new Distance();//THIS IS YOUR OBJECT 'd' and you have to have this in front of your methods that are in class distance otherwise it won't work!
  31. d.getDistance();//try taking the d away from these methods and see what difference it makes! :) x
  32. d.toStrings();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment