Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import java.util.*;
class Customers
{

	private String name;
	private int accountno;
	private String status;
	private String type;
	private int currbal;
	private String Login;
	private int Pin;

	public Customers()
	{

		this.name 	= " ";
		this.accountno = accountno;
		this.currbal = currbal;	
	}
	public Customers( String name1, int A, int Bal)
	{
		name = name1;
		accountno = A;
		currbal = Bal;		
	}
	public Customers ( String name1,int accountno1, String status1, String type1, int curr, String Login1, int Pin1)
	{	
		name = name1;
		accountno = accountno1;
		status = status1;
		type = type1;
		currbal = curr;
		Login = Login1;
		Pin = Pin1;
	}
	public String getHolderName()
	{
		return name;
	}
	
}

class ATMmain
{
	public static void main( String [] args)
	{
		int count = 1;
		
		Customers [] Carray = new Customers [100];
		//Customers [] C1 = new Customers[1];
		//Customers [] C2 = new Customers[1];
		System.out.println(createNewAccount(count, Carray));
		System.out.println(createNewAccount(count, Carray));
	}
	 
	public static int createNewAccount( int count, Customers [] Carray)
	{
		//Customers [] Carray = new Customers[10];
		System.out.println("Enter account information");
		Scanner S = new Scanner (System.in); 
		System.out.println("Login:");
		String log = S.next();
		System.out.println("Pin Code:");
		int Pin = S.nextInt();
		System.out.println("Holder's name: ");
		String holderN = S.next();
		System.out.println("Type:" );
		String type = S.next();
		if (!type.equals("Savings") && !type.equals("Current"))
		{
			System.out.println("error type! please Re-enter");
			System.out.println("Type:" );
			type = S.next();
		}
		System.out.println("Starting Balance:");
		int SBal = S.nextInt();
		System.out.println("Status:");
		String Stat = S.next();
		Customers ACC = new Customers(holderN, count,Stat, type,SBal,log, Pin );
		Carray[count] = ACC;
		
		System.out.println("Account Successfully created!");
		System.out.println("account number is" +count);
		count++;
		return count; 
		
	}
	}
	
	/*public void DeleteExistingAcc(int count, Customers [] Carray )
	{
		System.out.println ("Enter Account Number: ");
		Scanner S = new Scanner(System.in);
		int acc = S.nextInt();
		
		System.out.print   ln("Are you sure you want to delete this Account:" +acc);
		Carray[acc].getHolderName();
		
	}
	*/
&
Posted
Comments
Richard MacCutchan 8-Nov-14 10:57am    
And what is the question?
HyperCyber10 8-Nov-14 16:01pm    
Well im not able to store the accounts that i create into the array, as count always begins from 1 and doesnt increment to next indexes to keep storing any accounts that form....how do i achieve that?
Richard MacCutchan 9-Nov-14 3:23am    
You should set the initial value of count to zero and you should increment it in your main method, not where you have it.

1 solution

Fisrt of all, change the name of Customers class. It may suggest that this object is a collection. Better use Customer for single object.
Secondly, rather than array, use ArrayList[^]. ArrayList is more flexible than array.
Java
public static void main( String [] args)
    {
        int count = 1;
        ArrayList<customer> Customers = new ArrayList<customer>();
        Customer cust = new Customer("Adam", 1, 0);
        Customers.Add(cust);
        Customer cust = new Customer("Maciej", 2, 0);
        Customers.Add(cust);
        //and so on...

    }


See:
Adding instances of a class to an Arraylist in java[^]
 
Share this answer
 
v2
Comments
Manas Bhardwaj 9-Nov-14 13:17pm    
yes +5
Maciej Los 9-Nov-14 15:40pm    
Thank you, Manas ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900