• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Else without if error

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the following error: c:\Projects>javac PayrollProgram2.java
PayrollProgram2.java:30: 'else' without 'if'
else

This payroll program has to be modified so it continues to request employee information until the user enters stop as the employee name. I also have to program the application to check that the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, the application should prompt the user to enter a positive amount.



I just do not understand why I am getting this error. Can you please help?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have an extra semi-colon on line 24.

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I remove the semi colon from line 24, I now have 8 errors, which are the following:

PayrollProgram2.java:20: package system does not exist
system.out.println ( "Enter the employee's full name: " ); // prompt
^
PayrollProgram2.java:22: cannot find symbol
symbol : variable Payroll
location: class PayrollProgram2
Payroll.setEmployeeName( theName ); // set the employee name
^
PayrollProgram2.java:26: package system does not exist
system.out.println( "Enter total hours employee worked: " ); // prompt
^
PayrollProgram2.java:31: package system does not exist
system.out.println( "Re-enter employee's full name: "); //prompt
^
PayrollProgram2.java:35: package system does not exist
system.out.println( "Enter hourly pay rate: " ); // prompt
^
PayrollProgram2.java:40: package system does not exist
system.out.println( "Please enter a positive number: ");// prompt
^
PayrollProgram2.java:47: package system does not exist
system.out.println( "Employee Name:,Weekly pay is $ %d\n", sum );
^
PayrollProgram2.java:53: package system does not exist
system.out.println("Enter a positive number: ");// prompt
^
8 errors
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin:

You may be looking for the System class. Remember that in Java case matters.

John.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I remove the semi colon from line 24, I now have 8 errors, which are the following:

PayrollProgram2.java:20: package system does not exist



Also, this isn't a case of -- you cause those errors when you removed the semicolon. What happened is that the semicolon cause an error that obfuscated the other errors. So, when you fixed the semicolon error, the other errors showed up.

Fixing the semicolon was correct. Now you need to fix the rest.

Henry
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am getting more errors:

PayrollProgram2.java:22: cannot find symbol
symbol : variable Payroll
location: class PayrollProgram2
Payroll.setEmployeeName( theName ); // set the employee name
^
PayrollProgram2.java:47: cannot find symbol
symbol : method println(java.lang.String,int)
location: class java.io.PrintStream
System.out.println( "Employee Name:,Weekly pay is $ %d\n", sum );
^
2 errors

Am I putting in the wrong symbols here? My text book seems the same.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin:

For the second error, the println() method does not behave like C/C++'s printf(). Check the API for PrintStream (System.out is an object of class PrintStream) for a very similar method. For the first error, you may need to do an import, or check the method signature to get that to work.

John.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure what I am supposed to do here.

For the first error, what am I supposed to import?

For the second error, I am not following what you are saying.

I am assuming by the way you are responding that this is not a simple problem?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For the first error, what am I supposed to import?



You have to tell us. The compiler doesn't know what to do with "Payroll". What is that? Is it a variable? If it is, then you need to declare it somewhere. Is it another class? If it is, then you have to import it. We can't tell you exactly what to do, since we don't know what you are trying to use.


For the second error, I am not following what you are saying.



Basically, there is no such a thing as a println() method that takes a string and an int. Perhaps you want to use the printf() method?

Henry
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Quarles wrote:I am not sure what I am supposed to do here.
For the first error, what am I supposed to import?
For the second error, I am not following what you are saying.
I am assuming by the way you are responding that this is not a simple problem?



If you wrote the code, I suggest writing a little at a time and resolving errors as you see them. That's better than typing a lot of code, and dealing with many errors at a time. Whether or not you wrote it, it looks like you should start out with something simpler.

As far as your errors go, just take them one at a time. For example, "cannot find symbol... Payroll" means the compiler encountered the symbol "Payroll" but couldn't find where it was declared. What is Payroll? If it's another class you've defined, you either need to qualify that reference with its package name, or use the "import" keyword and specify the package there. The "package system does not exist" is probably caused by the dot notation in "system.out.println..." -- since there is no variable "system" in scope, I guess it's trying to interpret that as a package name. You probably mean to use "System.out.println..." -- "out" is a public field defined in class System, and its data type has a println() method.

But again, if you're trying to learn Java, I'd start with a simple "Hello World" example, and go from there.
 
Kevin Quarles
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I do an import, that would not be on that line, right?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Quarles wrote:If I do an import, that would not be on that line, right?


I'm not sure what you're asking here.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin:

Look at line 4 of the code you posted. That should help with import placement.

John.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first time the word "Payroll" appears in your program (and not as a comment) is on line 24. You have not declared it as a variable and it is not part of the Scanner class (which you DID import)...So the compiler has NO IDEA what that is. It can't figure it out.

Neither can we.

If this is a PayrollProgram2 , do you have a working PayrollProgram1 you could reference to see how it got a Payroll object?
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic