If someone could take a look at my Java code for Payroll Program, I need to declare Int as a double in order to produce the produce of number of employees in a department times the average salary for each employee. If someone could throw up pointers, tips, or any type of help I would greatly appreciate it. Thanks.

// Fig 2.2: Product.java
// Printing a line of text with multiple statements.
// Calculate the product of two integers.
import java.util.Scanner; // program uses Scanner

public class Product {

    public static void main(String[] args) {
        // create Scanner to obtain input from command window
        System.out.print("Department Name [enter name]\n");
        System.out.print("Number of Employee's[enter total]\n");
        System.out.print("Employee Salary[enter salary]\n");
        System.out.println("H.R. Department");

        Scanner input = new Scanner(System.in);

        int x; // enter number of employee's
        double y; // enter employee salary
        int result; // product of numbers

        System.out.print("Enter number of Employee's: "); // prompt for input
        x = input.nextInt(); // read first integer

        System.out.print("Enter employee salary:($) "); // prompt for input
        y = input.nextDouble(); // read second integer

        result = (int) (x * y); // calculate product of numbers

        System.out.printf("Product is %d\n", result);

    } //end method main
} //end class Product

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

6 Years
Discussion Span
Last Post by NormR1

to declare Int as a double

double Int; // declare Int to be double

Can you restate your question. I guess I don't understand what you are asking.

Comment on your variable names:
Don't use single letters for variables that hold data to be used later.
Use a self-documenting name like: nbrOfEmployees or employeesSalary.

When you're in the middle of the code, what does x hold???? Hard to tell.

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.