I get this message when I try to compile may work. Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - inner classes cannot have static declarations
But I am so new at this that when I read your suggestion of fixing the problem, because there are two classes, I know what you are speaking of but I am not sure how to fix it.
This is the code, but I just don't what to do to fix it.
import java.util.ArrayList;
import java.util.*;
/**
*
* @author gail
*/
public class CashForMetals2
{
//welcome method for customers
public static void printWelcome()
{
System.out.println(
"*** ***");
System.out.println(
"*** Welcome to Cash for Metals Calculator!!! ***");
System.out.println(
"*** ***");
}
private class Customer
{
private long customerId;
private String customerName;
private String customerAddress;
private String customerHomePhone;
private String customerWorkPhone;
public Customer(String name)
{
customerName = name;
SetCustomerId();
}
public Customer()
{
SetCustomerId();
}
public void SetCustomerId()
{
customerId = (long)(Math.random() * 100000);
}
public long GetCustomerId()
{
return customerId ;
}
public String GetCustomerName()
{
return customerName;
}
public void setCustomerName(String name)
{
customerName = name;
}
public String GetCustomerAddress()
{
return customerAddress;
}
public void setCustomerAddress(String address)
{
customerAddress = address;
}
public String GetCustomerHomePhone()
{
return customerHomePhone;
}
public void setCustomerHomePhone(String HomePhone)
{
customerHomePhone = HomePhone;
}
public String GetCustomerWorkPhone()
{
return customerWorkPhone;
}
public void setCustomerWorkPhone(String WorkPhone)
{
customerWorkPhone = WorkPhone;
}
public String toString()
{
return
"Customer ID " + customerId + "\n" +
"Customer Name " + customerName+ "\n" +
"Customer Address " + customerAddress;
}
public static void main( String[] args )
{
//create new Customer ArrayList
int NumberOfCustomers = 0;
String EnterAnotherCustomer ="";
ArrayList<Customer> customerArray = new ArrayList<Customer> ();
Scanner input = new Scanner( System.in );
do
{
System.out.print ("Enter Customer Name : ");
String name = input.nextLine();
System.out.print("Enter Customer Address : ");
String address = input.nextLine();
Customer customer = new Customer();
customer.setCustomerAddress(address);
customerArray.add(customer);
NumberOfCustomers++;
System.out.print("Enter YES to enter another Customer ");
EnterAnotherCustomer = input.nextLine();
}
while(EnterAnotherCustomer.trim().equalsIgnoreCase("YES"));
System.out.print(NumberOfCustomers);
//end class arraylist
//enhanced for loop iterate through elements in arraylist and print
for(Customer c : customerArray)
{
System.out.println(c);
System.out.println("***********************************");
}
System.out.print(NumberOfCustomers);
}
}
}