Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   How to use an arrayList and array in a method (http://www.go4expert.com/forums/arraylist-array-method-t24884/)

nippyeyes 7Feb2011 23:34

How to use an arrayList and array in a method
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.


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;
            else {
                System.out.println("Registration is not valid");

All times are GMT +5.5. The time now is 14:21.