Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:15:41+00:00 2026-06-12T12:15:41+00:00

The actual code works to encode values to the properties of each object within

  • 0

The actual code works to encode values to the properties of each object within the array.
However, it’s using the information from the last line only to populate each value.

Scanner data = new Scanner(new DataInputStream(new FileInputStream("trucklist.txt")));
for (int i = 0; i < maxSize; i++) 
{   for(;data.hasNext();)
    {
        t[i].setVin(data.next());
        t[i].setMake(data.next());
        t[i].setModel(data.next());
        t[i].setColor(data.next());
        t[i].setYear(data.next());
        t[i].setBaySize(data.nextDouble());
        t[i].setCabSize(data.nextDouble());

        addElement(t[i]);
    }
}

where trucklist.txt is :

12x4578w Ford F-150 Black 2005 17.2 6.8
12x4589w Ford F-150 Blue 2005 17.2 6.8
12x4587f Ford F-250 Black 2007 60.8 9.5
12x4589z Ford F-150x White 2005 15.4 10.2

The array elements are only being populated by the last set of properties for each element. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:15:43+00:00Added an answer on June 12, 2026 at 12:15 pm

    As this is currently written, i won’t increment while there is still data to be read. Try this instead:

    for (int i = 0; i < maxSize && data.hasNext(); ++i) {
        // set attributes of t[i]
        addElement(t[i]);
    }
    

    As a side note, this routine is very dependent upon a correctly formatted data file, and will throw unchecked exceptions if the data is malformed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works perfectly except that it doesn't print the last 2 rows of
Here is my simple code, which works fine if called from php or any
Note, this isn't my code, or the actual code in the form. This is
I have never seen the usecase for pre-increment and post-increment in actual code. The
Is it normal to have tests that are way bigger than the actual code
Full disclosure: this is for an assignment, so please don't post actual code solutions!
I've created an example of the problem here: http://jsfiddle.net/JustinN/qWeLT/1/ My actual code is hooked
When I put <a href=#>Click</a> into slickgrid, I see the actual code <a href=#>Click</a>
I have the following code: The actual problem is the non-quoted code. I want
I want to see the actual commands sent to g++ during a Code::Blocks build.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.