My System.out.println(info); line gives back "Model_X_Sale_2014.txt" instead of the information in the file. The first line being: "Jan 3128 1.59 3421 1.79" I'm new to splitting a string, but this problem is occuring before the string is even splitting.
Any idea what may be causing this? Thanks for the time either way. Also, is there a particular reason Eclipse wont let me use a try catch around the file stuff?
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("What year would you like to review?");
int year = Integer.parseInt(keyboard.nextLine());
String fileName= "Model_X_Sale_" + year + ".txt";
Scanner scanner = new Scanner(fileName);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();//read one line at a time
MonthlySale_Baumbach input = new MonthlySale_Baumbach(line);
System.out.printf("\n%s %15.2f %s15.2f", input.getMonth(), input.getProfitX310(), input.getProfitX410());
}
scanner.close();
}
public class MonthlySale_Baumbach {
//variables
String month;
int X310_Units, X410_Units;
double X310_uPrice, X410_uPrice;
public MonthlySale_Baumbach(){}
public MonthlySale_Baumbach(String info){
System.out.println(info);
String[] st = info.split("\\s");
month = st[0];
X310_Units = Integer.parseInt(st[1]);
X310_uPrice = Double.parseDouble(st[2]);
X410_Units = Integer.parseInt(st[3]);
X410_uPrice = Double.parseDouble(st[4]);
}//end of constructor
}