Skip to content

Instantly share code, notes, and snippets.

Created April 26, 2013 08:55
Show Gist options
  • Save anonymous/5465858 to your computer and use it in GitHub Desktop.
Save anonymous/5465858 to your computer and use it in GitHub Desktop.
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