Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //2011 q1(e)
- class Distance{
- double mile; double yards=1760;
- Distance(){}//no args constructor (not needed because of line
- Distance(double mile1, double yard1){//all args constructor
- mile = mile1; yards = yard1;
- yard1 = 1760;
- }
- void getDistance(){
- System.out.println("Enter in miles: ");
- mile = Console.readDouble();
- yards = mile * yards;
- System.out.println((int)mile + " miles or " + ((int)yards) + " yards");
- }
- void toStrings(){
- if(yards%1760!=0){
- System.out.println((int)mile + " miles " + ((int)yards%1760) + " yards " );
- }
- }
- //void add(int addition){
- // int total = mile + yards + addition;
- //}
- public static void main (String [] args){
- 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!
- d.getDistance();//try taking the d away from these methods and see what difference it makes! :) x
- d.toStrings();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment