Hi, So i'm trying to write a program that will work like a credit card database. The instructions say to add a file with 10,000 names that was given to us and add it to our project file. a scanner is suppossed to read through that file and add each line to an ArrayList I'm calling database. I've written a class called Customer() and a class called CustomerDatabase(), I need to call methods from Customer() to use in CustomerDatabase and the program is saying that I cannot call a nonstatic method into a static one. So I made an instance of Customer(), and now its saying that it can't find the cunstructor for Customer(). If anyone has any ideas, that would be great, thanks. The method i'm working on now where it wont let me call a method is
"public int countCustomers(int zip)"
if anyone can see a way for me to use this method that would be wonderful, Thank you!
CUSTOMER CLASS:
/**
* Maintains minimum information about customers such as, gender, name, and date of birth, address,
* city, state, zipcode, credit card brand and current balance.
*
* @LindseyScribner
* @3/16/13
*/
public class Customer
{
private boolean gender, female;
private String firstName, lastName, address, city, state, cardBrand;
private int birthDay, birthYear, birthMonth, zipcode;
private double currentBalance;
//initializes all instand variables and sets them to appropriate values.
public Customer(String info)
{
// Split the info string into multiple pieces separated by ‘,’ or ‘/’
String [] tokens = info.split(",|/");
if (tokens[0].trim() == "female")
{
gender = true;
}
else
{
gender = false;
}
firstName = tokens[1].trim();
lastName = tokens[2].trim();
birthDay = Integer.parseInt(tokens[3].trim());
birthMonth = Integer.parseInt(tokens[4].trim());
birthYear = Integer.parseInt(tokens[5].trim());
address = tokens[6].trim();
city = tokens[7].trim();
state = tokens[8].trim();
zipcode = Integer.parseInt(tokens[9].trim());
cardBrand = tokens[10].trim();
currentBalance = Double.parseDouble(tokens[11].trim());
}
//returns true if gender is female and false if gender is male.
public boolean isFemale()
{
if (gender == true)
{
return true;
}
else
{
return false;
}
}
//returns first name of customer
public String getFirst()
{
return firstName;
}
//returns last name of customer
public String getLast()
{
return lastName;
}
//
public String getAddress()
{
return address;
}
public String getCity()
{
return city;
}
public String getState()
{
return state;
}
public String getCreditCard()
{
return cardBrand;
}
public int getZip()
{
return zipcode;
}
public int getDay()
{
return birthDay;
}
public int getMonth()
{
return birthMonth;
}
public int getYear()
{
return birthYear;
}
public double getBalance()
{
return currentBalance;
}
public String toString ()
{
String result = getFirst() + getLast() + getAddress() + getCity() + getState()+ getZip();
return result;
}
CUSTOMERDATABASE CLASS
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
import java.util.Date;
/**
* Write a description of class CustomerDatabase here.
*
* @Lindsey Scribner
* @March 28, 2013
*/
public class CustomerDatabase
{
// instance variables
private ArrayList <Customer> database;
private Customer c;
public CustomerDatabase()
{
database = new ArrayList<Customer>();
c = new 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 = 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;
for (count = 0; count < database.size(); count++)
{
if (c.getZip() == zip)
{
count ++;
}
}
return count;
}
public int countDebtFree()
{
int count;
for (count = 0; count <database.size(); count++)
{
if (c.getBalance() == 0)
{
count ++;
}
}
return count;
}
public Customer getHighestDebt ( )
{
int count;
for (Customer c: database)
{
}
return c;
}
public Customer getYoungestCardholder ( )
{
for (Customer c: database)
{
Date Todaysdate = new Date();
}
return c;
}
}