I have tried many different things and nothing has worked. I am receiving an error "The local Variable line may not have been initialized Java(536870963) [Ln 44, Col15]" How do I fix this? I'm not finding anything that has help me understand the error of my ways. Please help.
import java.util.Scanner;
import java.util.Arrays;
public class A8johnston<close> {
public static String [][] data = new String[33][5];
public static void main(String[] args){
// Calling methods to use
initializeTable();
loadHistoricalData();
currencyLookup();
for (int i = 0; i < data.length; i++)
System.out.println(Arrays.toString(data[i]));
}
// Definde method intializeTable
private static void initializeTable(){
for (int i=1; i<data.length;i++){
data[i][0]= Integer.toString(i);
for (int j=1;j<data[0].length; j++){
data[i][j]="Unavailable";
}
}
}
// Definde method currencyLookup
private static void currencyLookup() {
String currency;
String[] row=null;
int day;
boolean isCurrencyFound = false;
double amount,convertedAmount;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Currency Loopup data (Currency, Date of Month, Amount): ");
while (true){
convertedAmount=0;
isCurrencyFound=false;
String line;
row = line.split(",",-1);
currency=row[0];
day=Integer.parseInt (row[2]);
amount=Double.parseDouble(row[2]);
if(currency==null || currency.trim()=="" || currency.trim().length()==0){
break;
}
//Calculate the Amount
int i;
for (i=1;i<data[0].length;i++){
if(data[0][i].equalsIgnoreCase(currency)){
isCurrencyFound=true;
if(("Unavailable").equalsIgnoreCase(data[day][i])){
System.out.println("Data not available");
break;
}
convertedAmount=amount * Double.parseDouble(data[day][i]);
break;
}
}
// What to do if curency is found
if(isCurrencyFound)
System.out.println("Allowed Currency;"+Arrays.toString(data[0]));
System.out.println("Enter Currency Loopup Data (Currency, Date of Month, Amount): ");
line=scanner.next();
}
}
// Gather historical Data and store it in the array
private static void loadHistoricalData() {
String line = null,rate,currency;
boolean isCurrencyAllowed=false;
int day;
String[] row;
Scanner scanner =new Scanner(System.in);
System.out.println("Enter Historical Data (Currency, Date of Month, Rate): ");
line =scanner.next();
while(true){
isCurrencyAllowed=false;
row =line.split(",", -1);
currency=row[0];
day=Integer.parseInt(row[1]);
rate=row[2];
if(currency ==null || currency.trim() =="" || currency.trim().length()==0){
break;
}
for(int i=1;i<data[0].length;i++){
if(data[0][i] =="" || data[0][i] ==null){
data[0][i] =currency;
data[day][i]=rate;
isCurrencyAllowed=true;
break;
}
if(currency.equalsIgnoreCase(data[0][i])){
data[day][i] =rate;
isCurrencyAllowed=true;
break;
}
}
if (isCurrencyAllowed) System.out.println("Only 3 Currency Allowed:"+Arrays.toString(data[0]));
System.out.println("Enter Historial Data (Currency, Date of Month, Rate): ");
line =scanner.next();
}
System.out.println("Data Loading Done");
}
close scanner;
}
Its not working for me. Please help.