# gas station project

• 10-10-2013, 02:09 AM
manga
gas station project
import java.util.Scanner;

class station{
public static void main(String[] args) {

Scanner writer = new Scanner(System.in);
double[] prices;
String[] stations;
prices = new double[4];
stations = new String[4];

System.out.println("What is the price per gallon of Shell?");
prices[0] = writer.nextInt();
System.out.println("What is the price per gallon of BP?");
prices[1] = writer.nextInt();
System.out.println("What is the price per gallon of Speedway?");
prices[2] = writer.nextInt();
System.out.println("What is the price per gallon of Marathon?");
prices[3]= writer.nextInt();

stations[0] = "Shell";
stations[1] = "BP";
stations[2] = "Speedway";
stations[3] = "Marathon";

}

public static void calculations(int[] prices, String[] stations) {
int times = 0;
double fuel = 25;
double tax = .93;
double[] total;
total = new double[3];
while (times < 4) {
total[times] = (prices[times] * fuel) * tax;
System.out.println("The price of " + stations[times] + " is " + total[times]);
times = times + 1;
}
}
}

The project is to have an array be populated with four gas stations. A user is then prompted to enter the price per a gallon for each station and have the values entered into an array. Then with 25 gallons being assumed as the amount bought, we are to create a void method that will output the total cost of gas for each gas station with a 7% sales tax included.

1) Did I do this correctly?
2) Why am I not receiving an output stating the prices for the stations?
• 10-10-2013, 02:29 AM
Junky
Re: gas station project
If you are not getting the correct output that answers your first question.
When does your code call the calculations method? It doesn't happen by magic.