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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:04:53+00:00 2026-06-04T06:04:53+00:00

I have some trouble regarding my lab assignment: When my program tries to prompt

  • 0

I have some trouble regarding my lab assignment:

When my program tries to prompt the user for input, the program outputs two questions on the same line and only takes the input for the second question.

The output of my program:

Please enter the name of the second employee:Please enter the number of the second employee:1

(They appear on the same line instead of separate lines)

Also the output for an array outputs like this:

0.00.00.00.00.00.00.00.00.00.0 

instead of like this:

0, 0, 0, 0, 0, 0, 0, 0, 0, 0

I’m not quite sure how to fix these two any help would be appreciated!

Here is my code:

Employee.java

//import java.util.*;

public class Employee
{
    private String empName;
    private int empNumber;
    private String empAddress;
    private double empSalary;

private double[] empBonus=new double[10];

public Employee(){}

public Employee(String empName_, int empNumber_, String empAddress_, double empSalary_, double[] empBonus_)
{
    this.empName=empName_;
    this.empNumber=empNumber_;
    this.empAddress=empAddress_;
    this.empSalary=empSalary_;

    this.empBonus=empBonus_;
}

public String getName()
{
    return this.empName;
}

public int getEmployeeNumber()
{
    return this.empNumber;
}

public String getAddress()
{
    return this.empAddress;
}

public double getSalary()
{
    return this.empSalary;
}

public String changeAddress(String chAddress)
{
    return empAddress=chAddress;
}

public double changeSalary(double chSalary)
{
    return empSalary=chSalary;
}

public String addBonus(double[] empBonus)
{
    String arrayBonus=new String("");

    for(int i=0; i<empBonus.length;i++)
    {
        arrayBonus+=empBonus[i];
    }

    return arrayBonus;
}

public String toString()
{
    return ("\nEmployee's name: "+empName+"\nEmployee's Number: "+empNumber+"\nEmployee's address: "+empAddress+
            "\nEmployee's original salary: "+empSalary+ "\nEmployee's bonuses: "+addBonus(empBonus)+"\n");
}
}

EmployeeTester.java

import java.util.*;

public class EmployeeTester
{
public static void main(String[] args)
{
    Scanner in1=new Scanner(System.in);
    Scanner in2=new Scanner(System.in);
    Scanner in3=new Scanner(System.in);

    Employee emp1;
    Employee emp2;

    emp1=read_input("first", in1, in2, in3);
    emp2=read_input("second", in1, in2, in3);

    System.out.println(emp1.toString());
    System.out.println(emp2.toString());

}

public static Employee read_input(String msg, Scanner scan1, Scanner scan2, Scanner scan3)
{
    String name, address;
    int num;
    double salary;
    double[] bonus=new double[10];

    System.out.print("\nPlease enter the name of the "+msg+" employee:");
    name=scan1.nextLine();

    System.out.print("Please enter the number of the "+msg+" employee:");
    num=scan2.nextInt();

    System.out.print("Please enter the address of the "+msg+" employee:");
    address=scan1.nextLine();

    System.out.print("Please enter the salary of the "+msg+" employee:");
    salary=scan3.nextDouble();

    System.out.print("Please add a bonus for the "+msg+" employee:");
    bonus[0]=scan3.nextDouble();

    System.out.print("Add more bonuses to the "+msg+"employee? (y/n) \nNote: Enter 0.0 if you would like to terminate adding more bonuses: ");

    if(scan1.next().startsWith("y"))
    {
        for(int i=1; i<bonus.length;i++)
        {
            System.out.print("Continue entering a bonus to "+msg+" employee:");
            bonus[i]=scan3.nextDouble();

            if(bonus[i]==0.0 || i==bonus.length)
            {
                break;
            }
        }
    }   

    return new Employee(name, num, address, salary, bonus);
}
}
  • 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-04T06:04:54+00:00Added an answer on June 4, 2026 at 6:04 am

    For your first problem just shift your Scanners inside your read_input method so they start fresh each time.

    public static void main(String[] args) {
        Employee emp1;
        Employee emp2;
    
        emp1 = read_input("first");
    
        emp2 = read_input("second");
    
        System.out.println(emp1.toString());
        System.out.println(emp2.toString());
    
    }
    
    public static Employee read_input(String msg) {
        Scanner scan1 = new Scanner(System.in);
        Scanner scan2 = new Scanner(System.in);
        Scanner scan3 = new Scanner(System.in);
        ...
    

    For your second problem, in your addBonus method where you build the output string you are not adding any spaces or commas. Also it is a lot more efficient if you use a StringBuilder for this type of looped concatenation rather than repeatedly creating new string objects.

    public String addBonus(double[] empBonus)
    {
        StringBuilder arrayBonus = new StringBuilder();
    
        for(int i=0; i<empBonus.length;i++)
        {
            arrayBonus.append(empBonus[i] + ", ");
        }
    
        return arrayBonus.toString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble with my lab assignment for my CMPT class... I
I have some trouble reading from an ini file using boost program options. The
I'm trying not to duplicate questions obviously as I have seen some questions/answers regarding
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
I am mlearning javascript and have some trouble creating an onject via prototype. I
Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
I have run into some trouble with the gd library's imagefilledpolygon() . For some

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.