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 8697359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:30:17+00:00 2026-06-13T01:30:17+00:00

So for an assignment I have to read from a input file that is

  • 0

So for an assignment I have to read from a input file that is formated as so:
Miller <— last name
William <—first name
00001 <— account ID
891692 06 <— account balance

These four lines represent an “account”. From a main method I have to call from another class called account and run a method in that class called toString()
toString() is supposed to print out those four lines in this format:
00001, Miller, William, $891692.06

Here’s what I have in my main method so far:

 int count = 1;
    while(read.hasNextLine()) {
        String nextLine = read.nextLine();
            account.toString(nextLine);
        if(count %4==0) {
            vector.addAccount(nextLine);
        }
        count++;
    } 

And this is whats in my toString method:

public String toString(String line) {
 for(int i = 0; i < position; i++){
  line = info[i]; 
    position++;
     }
     return System.out.println(info[2]+", "+info[0]+", "+info[1]+", "+info[3]);
}

In toString I’m getting an error with the return statement and also I need to format info[3](which should end up being the account balance) so that it will be in dollar notation when it prints like: $00.00

Any help is much appreciated! Thanks!

  • 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-13T01:30:18+00:00Added an answer on June 13, 2026 at 1:30 am

    Incorporating Nambari’s tip, you should try it as the following code:

    int count = 1;
    while(read.hasNextLine()) {
        String nextLine = read.nextLine();
            System.out.println(account.toString(nextLine));
        if(count %4==0) {
            vector.addAccount(nextLine);
        }
        count++;
    } 
    

    And the toString method:

    public String toString(String line) {
       for(int i = 0; i < position; i++){
          line = info[i]; 
          position++;
       }
       return info[2]+", "+info[0]+", "+info[1]+", "+info[3];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to read data from a file for an assignment unfortunately instead of
I have been given an assignment for university where i have to read from
I have an assignment to read a file and output the average test scores.
I have got this read file code from microsoft @C:\Users\computing\Documents\mikec\assignment2\task_2.txt That works fine when
I have a class with a member Address that I read from an XML
I am working on a homework assignment, beginning C#. Have to accept input from
Hello is have a question for a school assignment i need to : Read
I have read Nonblocking Assignments in Verilog Synthesis, Coding Styles that Kill! by Clifford
I have read Nonblocking Assignments in Verilog Synthesis, Coding Styles that Kill! by Clifford
In my assignment i have a problem with reading a file. See the following

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.