I've written the following simple program to display a pecentage for each Pizza Chains total units but the percentage is comming out as 00.00 for all of the answers why is this? I bet it's going to be a simple mistake I made. Every thing works fine but it's to do with the division that produces the zeros any ideas?
>>> THANKS IN ADVANCE <<<Code:import java.text.DecimalFormat;
class pizzaChains
{
public static void main ( String args[] )
{
DecimalFormat twoDP = new DecimalFormat( "00.00" );
String chains[] = new String[10];
int units[] = new int[10];
int totalUnits = 0;
// initialise chains array with pizza chains name's
chains[0] = "Pizza Hut ";
chains[1] = "Domino's ";
chains[2] = "Little Caesar's ";
chains[3] = "Papa John's ";
chains[4] = "Round Table ";
chains[5] = "Godfather's ";
chains[6] = "Chuck E. Cheese ";
chains[7] = "Picadilly Circus";
chains[8] = "Pizza Inn ";
chains[9] = "Pizza Kitchen ";
// initialise units arrays with units for each pizza chain
units[0] = 14400;
units[1] = 5950;
units[2] = 4300;
units[3] = 1517;
units[4] = 539;
units[5] = 554;
units[6] = 312;
units[7] = 680;
units[8] = 514;
units[9] = 80;
// calculate total units for all pizza chains
for ( int i = 0; i <= 9; i++ )
totalUnits = totalUnits + units[i];
// calculate & display total percentage of units for each pizza chain
System.out.println ( "-----------------------------------" );
System.out.println ( "PIZZA CHAINS \tTOTAL UNITS" );
System.out.println ( "-----------------------------------" );
for ( int i = 0; i <= 9; i++ )
System.out.println ( chains[i] + "\t" + twoDP.format ( ( units[i] / totalUnits ) * 100 ) + "%" );
System.out.println ( "-----------------------------------" );
}
}
