Programming and Problem Solving with Java

(やまだぃちぅ) #1

148


public classWarmUp
{
public static voidmain(String[] args)
{
final doubleDEBT = 300.0; // Original value owed
final doublePMT = 22.4; // Payment
final doubleINT_RATE = 0.02; // Interest rate
doublecharge; // Interest times debt
doublereduc; // Amount debt is reduced
doubleremaining; // Remaining balance
// Compute values for output
charge = INT_RATE * DEBT; // Compute interest charge
reduc = PMT – charge; // Compute debt reduction
remaining = DEBT – reduc; // Compute remaining balance
// Output result
System.out.println(“Payment: “+ PMT + “ Charge: “+ charge +
“ Balance owed: “+ remaining);
}
}
7.Enter the following application into your computer and run it. Add comments,
using the pattern shown in Exercise 6. (Notice how difficult it is to tell what the
code does without the comments.)
publicclass WarmUp2
{
public static voidmain(String[] args)
{
final intTOT_COST = 1376 ;
final intPOUNDS = 10 ;
final intOUNCES = 12 ;
int totOz;
doubleuCost;
totOz = 16 * POUNDS;
totOz = totOz + OUNCES;
uCost = TOT_COST / totOz;
System.out.println(“Cost per unit: “+ uCost);
}
}
Free download pdf