Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Please help! Java ARRAYS

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Please help! Java ARRAYS

    I have a Car class, the objects are below:

    //The car description.
    private String carDescription;
    //The customer name.
    private String customer;
    //The required deposit amount.
    public int downPayment;
    //The number of days the car is to be rented for.
    public int rentalPeriod;
    //The daily rental rate of the car.
    public int rate;
    //The date the car is to hired.
    public String dateOfHire;
    //The date the car is due to be returned.
    public String dateOfReturn;
    //The total amount of rent due.
    public int totalRent;
    //Whether or not the car is currently on loan.
    public boolean onLoan;

    I now need to make a RentalCompany class with an attribute that is an array list of the Car class objects.

    Please help, how do I start this? I am using BlueJ


  2. #2
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    static List<Car> cars = new ArrayList<Car>();

    Or?

    Car[] cars;

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    Thanks for replying...
    I tried that and it returns an error message " cannot find symbole - class list"

  4. #4
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    import it.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    How? Sorry, I am very new to Java.

  6. #6
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Please help! Java ARRAYS

    You cannot use lists from the collection framework without importing the into the program. Just "import java.util.*; or just import ArrayList. Check out some tutorials on using arrays. Use google.

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Please help! Java ARRAYS

    Quote Originally Posted by imsuperman05 View Post
    static List<Car> cars = new ArrayList<Car>();

    Or?

    Car[] cars;
    The Problem with Spoon-feeding

  8. #8
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    660
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Please help! Java ARRAYS

    Quote Originally Posted by imsuperman05 View Post
    static List<Car> cars = new ArrayList<Car>();

    Or?

    Car[] cars;
    Psht... people need to get up-to-date with Java 7
    = new ArrayList<>();
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  9. #9
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Please help! Java ARRAYS

    Can you share what has been changed in the Java Collection Framework's List instead of rolling on the floor while others are drowning? Thanks

    For those who do not know the recent changes to the collection framework, you can read it online or remember this next time you create objects using the collection
    For example,
    Instead of saying List<String> lists = new ArrayList<String>()
    lists.add("stuff");

    You can do it this way like in Ruby language
    List<String> lists = ["stuff"];



    Anyway, you might want to read more about it because some of the updates might not be as commonly used as you might think.
    Last edited by elisha.java; January 14th, 2012 at 08:00 PM.

  10. #10
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    Quote Originally Posted by Mr.777 View Post
    Sorry, wasn't aware. I won't spoon-feed anymore.

  11. #11
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    Quote Originally Posted by newbie View Post
    Psht... people need to get up-to-date with Java 7
    = new ArrayList<>();
    Oh wow, didn't know that lol. Haven't touched Java 7 in a while, just opened on Eclipse 4.1 hehe.

  12. #12
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please help! Java ARRAYS

    Take into account that using "new" keyboard is very important since it is the way in which Java allocates variables efficiently in computer's memory. In other words: not using this declaration first : ArrayList<String> lists = new ArrayList<String>()
    could bring you issues in your program.

Similar Threads

  1. issue with arrays in Java
    By Sei783 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 9th, 2011, 01:19 AM
  2. help with deque implementation using arrays in java
    By twi in forum Java Theory & Questions
    Replies: 1
    Last Post: June 14th, 2011, 09:55 PM
  3. [SOLVED] Java assignment, concerning Arrays and Loops
    By trejorchest in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 17th, 2011, 12:59 PM
  4. New To Java (Help with arrays)
    By SilentPirate in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 16th, 2010, 05:48 AM
  5. Details about 'CopyTo' of Arrays in Java
    By Fendaril in forum Collections and Generics
    Replies: 18
    Last Post: November 13th, 2008, 07:31 AM