Results 1 to 6 of 6
  1. #1
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Confusion over arrays

    I am relatively new to java and my understanding of arrays

    I am in the middle of a project that calculates the bmi, everything works so far apart from I want to limit the amount of records that can be added, unfortunately I think im misunderstanding the following:

    Java Code:
    int maxarray=12;
    Now as I understand it that is telling me that the array will only handle 12 records......as this doesnt work maybe someone would be kind enough to let me know what it is telling me.

    I have a text file that I want to add the records but I want it to flag up an error once I have reached the limit, in this instance I thought setting it at 12 would allow for a quick test as the figure will be 250.

    Thanks in advance if someone can answer either or both questions

    :confused:

  2. #2
    timkd127 is offline Member
    Join Date
    Dec 2008
    Posts
    41
    Rep Power
    0

    Default

    int maxarray=12; is just making an int data type that is initialized with a value 12. To use this where u declare your array you should have a line like this.
    Java Code:
    dateType[] array= new dataType[maxarray];

  3. #3
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    So I am looking in the wrong place then, I should be setting a limit on the records that I can input into my .txt file then?

  4. #4
    timkd127 is offline Member
    Join Date
    Dec 2008
    Posts
    41
    Rep Power
    0

    Default

    you could use a loop that iterates 12 times. if you wouldnt mind i could help you a little better if you posted all the code.

  5. #5
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    I would be grateful for your help, however the code is a total of 1291 lines so just to check so you only get the code you need to look at

    I have several buttons on the gui at the moment

    Search, add, next, update, new file, first record.

    I am close to being able to get rid of the next button however where would this loop go.

    The app calculates a persons bmi using either metric or imperial measurements, generates a file where members details are stored, I want to set the loop for 25 and then i want the optionPane to kick in to advise file full, EOF.

    So which button would you say the loop needs to go in? or does it need to go in the public class?

  6. #6
    timkd127 is offline Member
    Join Date
    Dec 2008
    Posts
    41
    Rep Power
    0

    Default

    What you could do is write a while loop in the main method that gets the information from the user. declare a global array of BMI obects and store the new object in the array at the end of the loop. As for the EOF you could use a similar loop to write the objects to a file and when u reach the limit that you want throw an EOF Exception. let me kno if im on the right track for what u want the program to accomplish.

Similar Threads

  1. [SOLVED] calling a boolean method, confusion!!
    By AngrYkIdzrUlE in forum New To Java
    Replies: 18
    Last Post: 03-15-2009, 11:23 AM
  2. [SOLVED] Confusion with classes (Please Help!)
    By kbullard516 in forum New To Java
    Replies: 8
    Last Post: 02-24-2009, 04:50 AM
  3. JList A real confusion.
    By darshak_patel in forum AWT / Swing
    Replies: 8
    Last Post: 02-07-2009, 01:17 AM
  4. System.in.read() confusion
    By ankurdh in forum New To Java
    Replies: 5
    Last Post: 01-08-2009, 09:28 AM
  5. bracket confusion...?
    By gallimaufry in forum New To Java
    Replies: 4
    Last Post: 10-28-2008, 12:17 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
  •