Wage Calculator

I am very new to any type of programming. I am to write a simple program that calculates wages using user input of hourly wage and hours worked. Can anyone tell me what I have done wrong here?

(code)

// Wage.java

//Java payroll program

import java.util.Scanner;

public class Wage

{

public static void main( String args [] )

{

Scanner input = new Scanner( System.in );

double x; // name

double y = 0.0; // hourly wage

double z = 0.0; // hours worked

double a = 0.0; // pay

System.out.print("Please Enter Employees Name:");

x = input.nextDouble();

System.out.println("Please Enter Hourly Wage:");

y = input.nextDouble();

System.out.println("Please Enter Hours Worked:");

z = input.nextDouble();

a = y * z;

System.out.printf( "Employee: %s\n", x );

System.out.printf( "Total pay for this period is $ %d\n", a);

}//end main method

}//end public class TomKinney1

(end code).

It compiles but I get java.util.InputMismatchException after I enter the name.

[1119 byte] By [tkinney2a] at [2007-11-27 6:39:22]
# 1

InputMismatchException is thrown when you use Scanner to look for a certain kind of value, but the next value in the file is something different.

That's probably because you're using "nextDouble" to look for the employee's name, and most people don't have names like "13.934".

When you post code, please wrap it in [code][/code] tags. It'll be much easier to read.

And when you get an exception, please post it and the whole stack trace you get when you ask about it here. The stack traces include valuable information to help you figure out the problem.

paulcwa at 2007-7-12 18:08:28 > top of Java-index,Java Essentials,New To Java...
# 2
Also give your variables better names. It may be extra typing but you or anyone else reading your code will understand what name means better than x
floundera at 2007-7-12 18:08:28 > top of Java-index,Java Essentials,New To Java...
# 3
previous posts have already explained the reason for your exception. I have just modified your code double x;should be String x; andx = input.nextDouble();should be x = input.next();
AnanSmritia at 2007-7-12 18:08:28 > top of Java-index,Java Essentials,New To Java...