PDA

View Full Version : Gas calculator



nmanpure
June 25th, 2010, 20:09
This will simply figure the price to fill your tank (from empty) or how much it will cost to travels a certain distance in miles.

Code:
Main.Java





package gascost;

import java.util.Scanner;
/**
*
* @author Noah Schweibinz
*/
public class Main
{


public static void main(String[] args)
{
Scanner keybd = new Scanner(System.in);

double cost=0.0;
double gallons=0, master, average, miles;
int task=0;

System.out.println("Enter price of gas per Gallon: ");
cost = keybd.nextDouble();
System.out.println("Would you like to find cost per tank fill or trip cost?\nsay 1 for tank or 2 for trip: ");
task = keybd.nextInt();

if(task == 1)
{
System.out.println("Enter how many Gallons your tank can hold: ");
gallons = keybd.nextDouble();
master = cost * gallons;
System.out.println("It will cost you "+ master * 1.0 + " To fill your Tank");
}else if(task == 2){

System.out.println("How many miles per gallon do you average: ");
average = keybd.nextDouble();
System.out.println("How many miles are you going to travel: ");
miles = keybd.nextDouble();
master = miles * cost / average;
System.out.println("Your trip will cost: "+master);
}
}

}

riches321
June 25th, 2010, 21:36
and where do u ptuthis lolz?

reese
June 26th, 2010, 00:29
and where do u ptuthis lolz?

What? This is the program >>
@Topic.
This is simple and good, Good use with math in Java it helps TONS. Goodjob, Repp+ if I could.

nmanpure
June 28th, 2010, 16:23
Ty i just started CS112 only 13 but no time to spare...... realy apraciate the coment.

\/\/\/\/\/\/ - Up - [Edit] - Down - /\/\/\/\/\/\/
Ty

Aaron
June 28th, 2010, 16:28
Nice job on the program.