- 
	
	
		
			
			
				Junior Member
			
			
			
			
				
					
						  
 
					    
				 
 
			
				
				
				
					Create an array of object
				
					
						
							Hi I am MCM Student
 
 I want to create an array of object which will accepts the more than one record I tried following code but its giving nullpointer Exception. Please tell me how should i solve this problem
 
 import java.io.*;
 
 
 class Account
 {
 private String name;
 private int ano;
 private int atype;
 private double abal;
 
 public void getdata(String n, int no, int type, double bal)
 {
 name = n;
 ano = no;
 atype = type;
 abal = bal;
 }
 
 public void display()
 {
 
 
 System.out.println("Account No: " + ano);
 System.out.println("Customer Name: " + name);
 if (atype == 1)
 {
 System.out.println("Account type: Saving A/C");
 System.out.println("Facilty: Withdrawal");
 }
 else
 {
 System.out.println("Account type : Current A/C");
 System.out.println("Facility : Cheque Book");
 }
 
 System.out.println("Account balance : " + abal);
 }
 
 }
 
 class Acc_demo
 {
 private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
 public static void main(String arg[]) throws IOException
 {
 Account a[] = new Account[2];
 
 System.out.println("Enter records: ");
 
 for (int i = 0; i < 2; i++)
 {
 System.out.println("Enter Customer Name: ");
 String nm = br.readLine();
 
 System.out.println("Enter A/C No: ");
 int no = Integer.parseInt(br.readLine());
 
 System.out.println("Enter Account type:");
 System.out.println("1 - Saving Account");
 System.out.println("2- current Account");
 int at = Integer.parseInt(br.readLine());
 
 System.out.println("Enter your last balance: ");
 int bal = Integer.parseInt(br.readLine());
 
 a[i].getdata(nm,no,at,bal);
 a[i].display();
 }
 }
 
 
 
 
 
 
 
 
 
 
	
	
	
	
	
	
	
	
	
	
	
	
		
		
			
				 Posting Permissions
				Posting Permissions
			
			
				
	
		- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-  
Forum Rules