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

  • Home
  • SEARCH
  • 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 7532443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:27:17+00:00 2026-05-30T05:27:17+00:00

I am working on a project where I return back the values of a

  • 0

I am working on a project where I return back the values of a sequence of Java methods so that I can spew out the results. But it is being printed out, out of sync. It should come out as the following:

return
"Name:          " + getFirstName() + " " + getLastName() + "\n" + 
"Id:            " + getEmployeeId() + "\n" +   
"Hourly Rate:   $" + getHourlyRate() + "\n" +
timeCard.toString()  +
"Weekly Pay:    $" + getWeeklyPay();

But the calling of the timeCard.toString() keeps rising to the top when it should be number 4 in the output. Here is the timeCard.toString() method below:
public String toString()
{

System.out.println("Weekly Hours:   " + getWeeklyHours());
for(int i = 0; i < NUMDAYS; i++ )
{
System.out.println("        Day "  + (i + 1) + ": " + getHoursByDay(i));
}
return "";//I had to place this hack here so the toString() format is valid. 
}

Is there an adhered to order of operations as far as the output using the return keyword is concerned? Or is my code causing it to come in out of order? Please offer your guidance on why this code is coming in out of order? How can I fix it?

Here is the output I am getting:

Employee Id:

1001
Employee Hourly Rate:

56

Enter Hours for day 1:

8

Enter Hours for day 2:

8

Enter Hours for day 3:

8

Enter Hours for day 4:

8

Enter Hours for day 5:

8

Employee:


Weekly Hours: 40

    Day 1: 8

    Day 2: 8

    Day 3: 8

    Day 4: 8

    Day 5: 8

Name: Stanford Marceles

Id: 1001

Hourly Rate: $56.0

Weekly Pay: $2240

BUILD SUCCESSFUL (total time: 29 seconds)

Cheers,

  • 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-05-30T05:27:19+00:00Added an answer on May 30, 2026 at 5:27 am

    You can use StringBuilder to create a String, as in the following:

    public String toString() {
      StringBuilder builder = new StringBuilder();
      builder.append("Weekly Hours:   " + getWeeklyHours()));
      for(int i = 0; i < NUMDAYS; i++ ) {
        builder.append("        Day "  + (i + 1) + ": " + getHoursByDay(i)));
      }
      return builder.toString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, the infamous error is back. The project is complaining that it can't find
I'm working on a project with a friend and I want to return to
For a current project I am working I need to return an aggregate report
I am working a project that does not have a trunk / branches /
I'm working on project that lets users choose some scientific authors and columnists and
I am working a project with many NUnit tests, that were already written long
I'm currently working on a C++ project that needs to have as few external
I am working on a project and I wrote two C programs that convert
I'm working on a homework project where we implement sessions (can't use HTTPSession) using
I am working on a project that I want to implement AJAX, and I

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.