6 Replies - 1035 Views - Last Post: 10 October 2010 - 02:43 AM Rate Topic: -----

#1 makaylaa21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 09-October 10

Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 07:56 PM

Hey, I am taking a Java programming course and I am supposed to write a payroll program. I am so lost, I have gotten to the point that the program will compile but it will not run. It spits out this error:
"Enter the Employees Name.Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at payrollp1.main(payrollp1.java:20)

Tool completed with exit code 1
"

And I am so lost at what I am to do with that type of error...Can someone help please?

here is my code...

import java.util.Scanner; //program uses the class scanner

public class payrollp1
{
	// main method begins
	public static void main(String args[] )
	{

		// creates scanner to obtain the input necessary to execute the program
		java.util.Scanner input= new Scanner(System.in);

		String Name		
                double Rate;
		double Worked;

			// allows the user to enter the employees name
			System.out.print( "Enter the Employees Name." );

			// sets the employees name
			Name = input.nextLine();

			// gives the user a chance to enter the hours the employee worked
			System.out.print( "Enter the number of hours the employee worked." );

			//sets the number of hours the employee worked
			Worked = input.nextDouble();

			// gets the hourly rate at which the employee will gain
			System.out.print( "Enter the pay in which the employee will receive per hour." );

			// sets the hourly rate the employee will earn
			Rate = input.nextDouble();


		System.out.printf("Employee" +Name+ "\n");
		System.out.printf("Pay:$%.2f", Rate*Worked);

	} // end main method
} // end Class payrollp1




What would be the easiest way to change this error message without running into creating more errors? Please help. :)

This post has been edited by makaylaa21: 09 October 2010 - 08:54 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Payroll Program Pt 1 Error Code help

#2 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,276
  • Joined: 01-June 09

Re: Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 09:35 PM

Well the only thing I'm noticing is that in the code you posted you forgot to put a semicolon on line 12:
String Name//should have a ; here



Also, you really shouldn't have a variable name start with a capital letter. It's a convention to have them start with lower case letters.

I fixed the semicolon problem though, and your code works fine when I run it. See if you can get the same results.

Also, on line 10 you say:
java.util.Scanner input= new Scanner(System.in);


You don't need the whole path. You'd be fine just saying:
Scanner input = ...


This is because you already imported java.util.Scanner at the top.

Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#3 makaylaa21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 09-October 10

Re: Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 09:46 PM

Hello eZacke,
I have taken your advice putting the semi-colon in that spot and removed the excess java.util.Scanner I had. And I am still coming up with the same error as before.

Enter the Employees Name.Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at payrollp1.main(payrollp1.java:20)

Tool completed with exit code 1

Thank you for your help, I have added onto my variables to create a lower case letter in front. I did not know that you had to have that. hehe

Oh I did forget to say, I am using TextPad. Not sure if there is anything that I need to do that would not allow my program to run?
Was This Post Helpful? 0
  • +
  • -

#4 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,276
  • Joined: 01-June 09

Re: Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 09:52 PM

View Postmakaylaa21, on 10 October 2010 - 12:46 AM, said:

Thank you for your help, I have added onto my variables to create a lower case letter in front. I did not know that you had to have that. hehe


Well you don't NEED to, but it's convention and you really should try to follow it. It just makes it easier for people to read your code.

I'm not having any trouble with your code though. You said this was a runtime error? When exactly is this occurring?

Here's a test run of your code on my computer:
Enter the Employees Name.This works
Enter the number of hours the employee worked.1337
Enter the pay in which the employee will receive per hour.15
EmployeeThis works
Pay:$20055.00
Was This Post Helpful? 0
  • +
  • -

#5 makaylaa21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 09-October 10

Re: Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 10:01 PM

I am getting the code even before I start to run the program. Once it is compiled, and after I hit the run button it spits out that code. I don't know whats wrong. The TextPad program might have some preferences all messed up or something, because I try to run the program, same code in Eclipse and it works just fine. I am going to scream. But thank you again:)
Was This Post Helpful? 0
  • +
  • -

#6 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,276
  • Joined: 01-June 09

Re: Payroll Program Pt 1 Error Code help

Posted 09 October 2010 - 10:04 PM

Hmm, very strange. But as far as I can tell this program does work correctly.

I don't see why it would work in one environment and not in the other.

But anyway, glad I could help. Feel free to ask if you have any other questions!
Was This Post Helpful? 0
  • +
  • -

#7 makaylaa21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 09-October 10

Re: Payroll Program Pt 1 Error Code help

Posted 10 October 2010 - 02:43 AM

Thanks! Have a wonderful night!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1