Time remaining:
Java Passing User input into array

Programming
Tutor: None Selected Time limit: 0 Hours

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);
//   
//  }
//   
//  //
//}

Jul 28th, 2013

You can pass arguments from commandline and from file too.

Commandline e.g.: java PetrolStation arg1 arg2 arg3 arg4 .....

You can use easy libraries like Apache commons lib: http://commons.apache.org/proper/commons-io/download_io.cgi

example of this lib is: List<String> lines = FileUtils.readLines(new File("filename"));

Then you can parse all lines using a loop.

Nov 10th, 2014

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Jul 28th, 2013
...
Jul 28th, 2013
Dec 9th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer