// purpose: demonstrate decimal arithmetic by playing with a piggy bank import java.util.*; public class PiggyBank { // method main(): program starting point public static void main( String[] args ) { // set up input scanner Scanner stdin = new Scanner( System.in ); // prompt and get the various amounts of change System.out.print( "Number of quarters, dimes, nickels, & pennies: " ); int quarters = stdin.nextInt(); int dimes = stdin.nextInt(); int nickels = stdin.nextInt(); int pennies = stdin.nextInt(); System.out.println(); // calculate total worth double total = ( quarters * 0.25 ) + ( dimes * 0.10 ) + ( nickels * 0.05 ) + ( pennies * 0.01 ); // display result System.out.println( "The following coins" ); System.out.println( "\t" + quarters + " quarters" ); System.out.println( "\t" + dimes + " dimes" ); System.out.println( "\t" + nickels + " nickels" ); System.out.println( "\t" + pennies + " pennies" ); System.out.println( "are worth $" + total ); System.out.printf( "are worth $%4.2f \n", total ); } }