I am attempting to read from a .csv file for my program but we have never read from a .csv file before in my class. I'm not quite sure how to go about it, but this is my attempt so far. I imagine that I am missing some kind of loop that loops through every line of the file but I am not sure how to go about doing that.
Bank bank = new Bank();
Scanner infile = new Scanner("C:/Users/Josh/Desktop/prog5input.csv");
Scanner s2 = new Scanner(infile.nextLine());
int accountType = 0;
String accountHolder = "";
double accountInitial = 0.0;
double accountRate = 0.0;
System.out.println("Program 5, Josh Correia, cssc0491");
System.out.println("Creating accounts...");
s2.useDelimiter(",");
if (s2.hasNextInt()) accountType = s2.nextInt();
if (s2.hasNext()) accountHolder = s2.next();
if (s2.hasNextDouble()) accountInitial = s2.nextDouble();
if (s2.hasNextDouble()) accountRate = s2.nextDouble();
bank.addNewAccount(new SavingsAccount(accountHolder, accountInitial, accountRate));
This is the file that I am reading from:
1,Waterford Ellingsworth, 4350.0, 0.002
2,Bethanie Treadwell, 500.0, 0.35
3,Ira Standish, 50000, 0.1, 59, 0.1
4,Debi Cardashian, 5100, 0.0