0

I need my overall data to all be output as double, but my counter is an int, and i imagine you cant use a double as a counter, so when it goes to compute my data, theres a mismatch between my counter and the rest . i need a way of converting my data to double for out put. Here's my code....i have a test also, all it does is call the main method.

public class Salary
{


    public void calcSalary()
    {

    int wages[]={50000,40000,30000,20000,10000,60000,35000,46000,23000,19000};

    final int TOTAL_LENGTH=10; //declare constant
    int total[]=new int[TOTAL_LENGTH];
    int bonus;
    int counter;



    System.out.printf("\n%s\t%11s\n\n","REP","SALARY");

    for (counter=0; counter <total.length; counter++)

    System.out.printf("%2d\t%10d\n",counter, wages[counter]);


    counter=0;

    System.out.printf("\n\n\n%s\t%10s\n\n","BONUS","TOTAL"); //column headings




        while (counter<total.length)
        {




            if (wages[counter]<=19000)
            {


            bonus=wages[counter]/100*30;
            total[counter]=wages[counter]+bonus;
            System.out.printf("%d\t%10d\n",bonus,total[counter]);


            }


            if (wages[counter]>19000 && wages[counter]<=40000)
            {

            bonus=wages[counter]/100*20;
            total[counter]=wages[counter]+bonus;
            System.out.printf("%d\t%10d\n",bonus,total[counter]);


            }


            if (wages[counter]>40000)
            {

            bonus=wages[counter]/100*10;
            total[counter]=wages[counter]+bonus;
            System.out.printf("%d\t%10d\n",bonus,total[counter]);


            }







            counter=counter+1;






        }




    }



 }

Edited by Nick Evan: Fixed formatting

3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by stultuske
0

well, why wouldn't you be able to use a double as a counter?
and converting an int to a double? what good whould that do? you would have decimals, yet, but since every value stored in an int is always rounded (since it has no decimal capacity) all your prints will end with .00, so what use would that be?

This question has already been answered. 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.