1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

Using arrays in Java

Discussion in 'BBS Hangout' started by clutchdream, Apr 30, 2002.

Tags:
  1. clutchdream

    clutchdream Member

    Joined:
    Jan 20, 2001
    Messages:
    137
    Likes Received:
    0
    I am trying to write a program and one of the class requires to have the following attributes.

    · String name for the bookstore name
    · A five element String array that will contain the list of books the store has:
    o War and Peace
    o Animal Farm
    o Watership Down
    o Emma
    o Introduction to Java
    · A five element double array that corresponds to the list above and had the price of each book.
    o $ 7
    o $ 8
    o $ 9
    o $ 10
    o $ 20

    I am still have trouble understanding arrays. Anybody know i site that could help me with Arrays and possibly constructors.
     
  2. movement

    movement Member

    Joined:
    Aug 9, 2001
    Messages:
    212
    Likes Received:
    0
    hey,

    check out:
    http://bbs.clutchcity.net/showthread.php?s=&threadid=31915

    its a small program that uses arrays in almost the same manner as your program.

    http://www.calicotech.org/prices/1.html

    if you didnt use arrays in your program, you would just make variables book1=War and Peace; book2=Animal Farm; etc...
    And then price1=7; price2=8;

    However when you show the display there is a lot of unnecessary code you will need to write inorder to show War and Peace = $8. Using arrays, you can display the whole output with a loop. Image, this code is showing the book for all of the store. It would take forever with the 1st method, but with arrays, it will still take you 3 lines to show 5 books or 5000 books.

    for (j=0; j(less than)nameofarray.length; j++)
    {
    document.write ("name of book" +book[j]+ " has a price of: " +price[j]+ "<br>");
    }
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now