Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please help me! I got error.... I'm a new programming learner

    PHP Code:
    import java.util.*;

    class 
    CustomerInfo{
        
    String nametype;
        
    int no;
        
    double balance;
    }

    public class 
    Customer_Account {
        
    int N 2;
        
    CustomerInfo[] student = new CustomerInfo[N];
        
        public static 
    void main (String[] args)
        {
         
    int N 2;
         
    int i;
         
    Customer_Account arr = new Customer_Account();
         
    CustomerInfo[] Std = new CustomerInfo[N];
         
    Std arr.InputData(); 
             
    arr.SelectOperation();
         
    arr.PrintInfo(Std); 
             
        }
    public 
    CustomerInfo[] InputData() {      
              
    int inum;
              
    double amounttotal;
              
    Scanner input = new Scanner (System.in);
          
    CustomerInfo[] customer = new CustomerInfo[N];
          
    System.out.println("\nEnter Customer Information ");
          
    System.out.println("___________________________ \n");
          for (
    0iNi++)
          {
           
    customer[i] = new CustomerInfo();
           
    System.out.print("Input customer name  : ");
           
    customer[i].name input.next();
           
    System.out.print("Input acct No        : ");
           
    customer[i].no input.nextInt();
               
    System.out.print("Input acct Type      : ");
           
    customer[i].type input.next();
           
    System.out.print("Input acct Balance   : ");
           
    customer[i].balance input.nextDouble();     
           
    System.out.println();
               }
             return 
    customer;
    }

    public 
    void SelectOperation (){
               
    int numi=N;
               
    double amounttotal;
               
    Scanner input = new Scanner (System.in);
               
    CustomerInfo[] customer = new CustomerInfo[N];
               
    Scanner choose = new Scanner (System.in);
               
    System.out.println("Please choose your operation (input either 1 or 2): ");
               
    System.out.println("1. Withdrawal");
               
    System.out.println("2. Deposit");
               
    System.out.println();
               
    System.out.print("You choose: ");
               
    num choose.nextInt();
               
    System.out.println();
        
        switch (
    num) {
            case 
    1:
               
                
    System.out.println("Withdrawal Operation:");
                
    System.out.println("___________________________ \n");
                
    System.out.print("Input acct munber:");
                
    customer[i].no input.nextInt();
                
    System.out.print("Input amount to withdraw:");
                
    amount input.nextInt();
                
    total= (customer[i].balance-amount);
                
    customer[i].balance total;
                
    System.out.println();
                break;
                
            case 
    2:
                
    Scanner output = new Scanner (System.in);
                
    System.out.println("Deposit Operation:");
                
    System.out.println("___________________________ \n");
                
    System.out.print("Input acct munber:");
                
    customer[i].no output.nextInt();
                
    System.out.print("Input amount to deposit:");
                
    amount output.nextInt();
                
    total= (amount+customer[i].balance);
                
    customer[i].balance=total;
                
    System.out.println();
                break;
        }
    }

    public 
    void PrintInfo(CustomerInfo[] Std)
    {
       
    int i;
       
    System.out.println();
       
    System.out.println("List of customers :\n");
        for (
    i=0;i<N;i++)
        {
          
    System.out.println("Customer "+(i+1) + "\n" 
                             
    "Customer Name           : " Std[i].name "\n" +  
                             
    "Customer Account Number : " Std[i].no "\n" 
                             
    "Customer Account Type   :" Std[i].type "\n" +
                             
    "Customer Account Balnce : " Std[i].balance "\n");
       }
     }

    The output:
    Enter Customer Information
    ___________________________

    Input customer name : Ali
    Input acct No : 1111
    Input acct Type : saving
    Input acct Balance : 2222

    Input customer name : Abu
    Input acct No : 2222
    Input acct Type : saving
    Input acct Balance : 3333

    Please choose your operation (input either 1 or 2):
    1. Withdrawal
    2. Deposit

    You choose: 1

    Withdrawal Operation:
    ___________________________

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at customer_account.Customer_Account.SelectOperation(Customer_Account.java:77)
    at customer_account.Customer_Account.main(Customer_Account.java:30)
    Input acct munber:Java Result: 1
    Last edited by VIPStephan; 08-07-2013 at 09:37 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •