473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Java programming question

I am in a beginners Java programming class. So far I am doing ok in the class, although there are some things that I am sure will come in time. Right now we are doing an onging project that started with a basic payroll application. Every week we build on it. I am having some troubles with this week. The idea of the program is to continue to request the employees information until the user enters 'stop' as the employee name. I keep getting an error message when I compile it.

Here is what I have:

// Payroll22.java
// Payroll program that displays the weekly pay of employee.
import java.util.Scanner; // program uses class Scanner // Author: Nicki

public class Payroll22
{

// main method begins execution of Java application
public static void main( String args[] )

String name = input.next();
double rate = input.nextDouble();
double hours = input.nextDouble();

{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

// prompt for and input employee name
System.out.printf( "Enter the employee name:\n" );

while (!name.equalsIgnoreCase("stop"))
{

// Hourly Rate input
System.out.printf( "Enter the employee's hourly rate in dollars:\n" );

while ( rate < 0 )
{
System.out.printf( "Please enter a positive value:" );
rate = input.nextDouble( );
} // end while loop (pay rate)

// Hours Worked input
System.out.printf( "Enter the number of hours worked:\n" );

while ( hours < 0 )
{
System.out.printf( "Please enter a positive value:" );
hours = input.nextDouble( );
} // end while loop (hours worked)

// Output the result
System.out.printf( "Employee: " + name + "\n" );
System.out.printf( "Pay: $%.2f", rate*hours );

// prompt for and input employee name
System.out.printf( "Enter the employee name:" );

} // end while loop

} // end method main

} // end class Payroll22



The error that shows up has to do with line 9 and it says the following:

' ; ' expected public static void main ( String args[] )

The arrow is pointing to the space after the last parenthesis.

Any ideas what I could be doing wrong? I have a feeling it is something obvious that I keep overlooking because I have looked at it too long.

Thank you for your help!

Nicki
Jun 24 '08 #1
4 1813
BigDaddyLH
1,216 Expert 1GB
Your method should look like the following (note braces)

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[]args) {
  2. ...
  3. }
Remember that all methods (including main) have a body delimited by braces.
Jun 24 '08 #2
Thank you very much. I knew it was an obvious mistake.

Of course now I have 3 additional errors. This time they are within my varibale definitions. It says that the ' i ' in input is a symbol that cannot be found. nay ideas?

Thanks again!

Nicki
Jun 24 '08 #3
Laharl
849 Expert 512MB
You need to create your Scanner object using its constructor, so include a line at the top:

Expand|Select|Wrap|Line Numbers
  1. Scanner input = new Scanner();
That's how you create objects (anything that isn't an int/float/double/boolean/etc builtin primitive type).
Jun 24 '08 #4
BigDaddyLH
1,216 Expert 1GB
You need to keep in mind that local variables need to be defined before they can be used, and that you should prompt the user before reading their reply: just remember that statements are executed in order:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.     Scanner input = new Scanner(System.in);
  3.  
  4.     System.out.printf( "Enter the employee name:\n" );
  5.     String name = input.next();
  6. ...
Jun 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

55
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I...
3
by: Jay | last post by:
Hi, I implemeneted an FTP client and server long time back using Java. I found sockets porgramming in java quite useful and easy to handle. I now wanted to implement a similar program using C++....
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
5
by: Sophia | last post by:
Hi, My question is pretty much what the title describes. My situation is: The essential task is to provide a service to web user. This service can only be accessed from a java program on the...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
63
by: s0suk3 | last post by:
I've been programming Python for a couple of years now. Now I'm looking to move on to either C++ or Java, but I'm not sure which. Which one do you think will be a better transition for a Python...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.