Results 1 to 2 of 2
  1. #1
    slacoul is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default Car Simulation (Array)

    i have made a car simulation, using array. The code is as follows:

    Java Code:
    public class CarArray
    {
    
        public static void main( String[] args )
        {
            Car[] carArray = new Car[3];
            carArray[0] = new Car(4, "BMW");
            carArray[1] = new Car(6, "Toyota");
            carArray[2] = new Car(2, "Honda");
            for (Car eachCar: carArray){
               System.out.println(eachCar.getName());
               eachCar.wheels();
            }
    
        }
    }
    Java Code:
    public class Car
    {
    
        
        private String name;
        
        public Car(int i, String name)
        {
            this.name = name;
            }
    
        public String getName()
        {
            return name;
        }
    
        public void wheels()
        {
            System.out.println("Nice Wheels.");
        }
        
        
    
    }
    I got a Car collection by the help of arrays but my question is how can i add more cars or remove cars to my array. I want the output to ask me if i want to add or remove cars. How do I do that? It looks simple but I just need someone to show me the way. Thank you..

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default Re: Car Simulation (Array)

    You must create a new array or another way to use Collections framework.
    Skype: petrarsentev
    http://TrackStudio.com

Similar Threads

  1. BPA registration simulation again, Almost done
    By noahwhygodwhy in forum New To Java
    Replies: 3
    Last Post: 04-05-2011, 01:56 PM
  2. BPA registration simulation
    By noahwhygodwhy in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 01:47 AM
  3. hELP WITH A PROCESSOR SIMULATION
    By Quan567 in forum New To Java
    Replies: 18
    Last Post: 03-23-2011, 09:32 PM
  4. beehive simulation
    By BlueF4re in forum New To Java
    Replies: 2
    Last Post: 12-02-2009, 09:31 AM
  5. Pulley Simulation..HELP
    By dazza-s in forum Java 2D
    Replies: 2
    Last Post: 06-18-2008, 11:51 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
  •