Start New Discussion within our Software Development Community

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

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.

This article has been dead for over six months. Start a new discussion instead.