Created
April 26, 2013 08:55
-
-
Save anonymous/5465858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class NewCar | |
{ | |
//instance variables | |
double start, end, galls; | |
//constructor | |
NewCar(double start) | |
{ | |
this.start=start; | |
} | |
//methods | |
void fillUp(double miles, double galls) | |
{ | |
this.galls=galls; | |
//bla | |
//bla | |
} | |
double mpg() | |
{ | |
return (end-start)/galls; | |
} | |
} | |
class thirtyone2 | |
{ | |
public static void main (String[] args) | |
{ | |
//get data, construct car | |
Scanner keyboard=new Scanner(System.in); | |
System.out.println("New car odometer reading:"); | |
double start=keyboard.nextDouble(); | |
NewCar car=new NewCar(start); | |
//2 gas station visits | |
for(int i=1; i<=2; i++) | |
{ | |
System.out.println(); | |
System.out.println("Filling Station Visit"); | |
System.out.println("odometer reading:"); | |
double miles=keyboard.nextDouble(); | |
System.out.println("Gallons to fill tank:"); | |
double galls=keyboard.nextDouble(); | |
car.fillUp(miles,galls) | |
System.out.println("Miles per gallons: "+car.mpg()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment