Hi, Im trying to write a program that uses a .txt file to fill an arrayList of type Customer (A class that I made.) and then using that ArrayList to perform other functions within my Customer Database class. when I test my method, nothing is being added to the ArrayList I created. If anyone could help me figure out why that would be great. We're trying to add into the ArrayList from "public void readCustomerData(String CustomerNames)"
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
import java.util.Date;
/**
* Uses the ArrayList Database and Customer() class to generate data from the customernames.txt file.
*
* @Lindsey Scribner
* @March 28, 2013
*/
public class CustomerDatabase
{
//instance variables
private ArrayList <Customer> database;
public CustomerDatabase()
{
database = new ArrayList<Customer>();
}
public void readCustomerData(String CustomerNames)
{
// Attempt to read the complete set of data from file.
try
{
File f = new File("CustomerNames.txt");
Scanner sc = new Scanner(f);
String logline;
//read header information first
logline = sc.nextLine();
while(sc.hasNext())
{
logline = sc.nextLine();
//remove this print statement after method works
System.out.println(logline);
Customer c;
c = new Customer(logline);
database.add(c);
}
sc.close();
}
catch (IOException e)
{
System.out.println("Failed to read the data file: " +
"CustomerNames.txt");
}
}
public void addCustomer(Customer c)
{
database.add(c);
}
public int countCustomers()
{
return database.size();
}
public int countCustomers(int zip)
{
int count = 0;
for (Customer c: database)
{
if (zip == c.getZip())
{
count ++;
}
}
return count;
}
public int countDebtFree()
{
int count = 0;
for (Customer c: database)
{
if (c.getBalance() == 0)
{
count ++;
}
}
return count;
}
public Customer getHighestDebt ( )
{
int count;
for (Customer c: database)
{
}
return;
}
public Customer getYoungestCardholder ( )
{
for (Customer c: database)
{
Date Todaysdate = new Date();
}
return c;
}
public String getCardSummary(String card)
{
}
public ArrayList <Customer> getMailingList(double low, double high)
{
}
public ArrayList <Customer> getMailingList(String keyword)
{
}
public static void main (String args[])
{
}
}