1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to use an arrayList and array in a method

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

  1. nippyeyes

    nippyeyes New Member

    Feb 7, 2011
    Likes Received:
    Trophy Points:
    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");
    Last edited by a moderator: Feb 8, 2011

Share This Page