Results 1 to 2 of 2
  1. #1
    manga is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default 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?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default 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.

Similar Threads

  1. Power Station Problem
    By sthack99 in forum New To Java
    Replies: 2
    Last Post: 01-04-2011, 08:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •