1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to use an arrayList and array in a method

Discussion in 'Java' started by nippyeyes, Feb 7, 2011.

  1. nippyeyes

    nippyeyes New Member

    Hi, i am currently doing my university work but i am stuck on one thing. I have made an array to hold car sales for 9 years according to the registration plate and an array list to hold the registration and information of each car.

    I have made a method to add a cars details into the array list, but i also need to add the registration into the array of the car sales. I know how to put an arrayList into a method, but im not sure on how to put the array into the method aswell. Any help would be much appreciated.

    Code:
    public static void main (String[] args)
            {
                ArrayList<String> forSaleData = new ArrayList<String>();
         
                final int CAR_SALES = 9;
                int[] sales = new int[CAR_SALES];
                final int TOTAL_SALES = 200;
                int[] totalSalesValue = new int [TOTAL_SALES];
                double totalSales = 0;
    
    
    public static void addCar(ArrayList<String> forSaleData)
              
           
               {
                  Scanner in = new Scanner (System.in); 
                  System.out.print("Enter Car registration: ");
                  String reg = in.nextLine();
                  char c = reg.charAt(3);
                  if (Character.isDigit(c)){
                   System.out.print("enter other info");
                   String info = in.nextLine();
                   String carInfo = reg + info;
                   forSaleData.add(carInfo);
               }
                else {
                    System.out.println("Registration is not valid");
               }
     
    Last edited by a moderator: Feb 8, 2011

Share This Page