Java Passing User input into array

Anonymous
timer Asked: Jul 28th, 2013
account_balance_wallet $5

Question Description

I want to take the user data thats inputted and put into an array.

I wish there was a way for me to upload the files.

class PetrolStation
{

public static void main(String[] arg)

{
  String [] COUNTIES = {"Broward", "Miami-Dade", "Palm Beach", "Average"};
   String [] PETROL_TYPE = {"Regular", "Plus-2", "Supreme", "Diesel", "Average"};
   double petrol_price[][] = new double[PETROL_TYPE.length][COUNTIES.length];
   load(petrol_price, COUNTIES, PETROL_TYPE);
   PetrolPrice s = new PetrolPrice(petrol_price, COUNTIES, PETROL_TYPE);
  System.out.println("\n.... Price for each type of petrol per county.....");
   s.display();


}

   static void load(double price[][], String COUNTY[], String[] TYPE) {
//    Complete the definition for reading the data and storing them in the array called price
   
   for (int i = 0; i < price.length - 1; i++)
   {
   String s =  TYPE[i]; //Extract petrol type to prompt user
   for (int j = 0; j < price[i].length - 1; j++)
   {
   String t = COUNTY[j];  // Extract county to prompt user
   price[i][j] = GetData.getDouble(t + " \n"+ s);
   }
   }


}
}

-------------

public class PetrolPrice
{
  double petrol_price[][];
  String PETROL_TYPE[];
  String COUNTIES[];
   
  String s;
   
  //constructor
  PetrolPrice(double price[][], String county[], String type[])
  {
  petrol_price = price;
  COUNTIES = county;
  PETROL_TYPE = type;
   
  s = "";
  }

   
  //method to display prices
  public void display(double price[][],String county[],String type[])
  {
  for(int row = 0; row < price.length; row++)
  {
  for(int column = 0; column < price[row].length; column++)
  {
  System.out.println();
  System.out.println(price[row][column]+ "\t");
//  s = s + petrol_price[row][column]+ "\t";
  }
  System.out.println();
  }
//  return s;
  }
}
   
//  //method to average the three counties - columns
//  public double column_averages()
//  {
//  double sum = 0;
//   
//  for(int i = 0; i < price.length; i++)
//  {}
//  }
//   
//  //method to average the four gas types - rows
//  public double row_averages()
//   
//  {
//  double sum = 0;
//   
//  for (int i = 0;  i < price.length; i++)
//  {
//  double num = price[i];
//  sum = sum + num;
//  }
//   
//  return sum / (price.length);
//   
//  }
//   
//  //
//}

This question has not been answered.

Create a free account to get help with this and any other question!

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors