ZhenghaoZhu

PiggyBank

Nov 14th, 2015
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import java.util.*;
  2. import java.text.*;
  3.  
  4. public class PiggyBank{
  5.   public static void main (String []args){
  6.     Scanner input = new Scanner(System.in);
  7.     DecimalFormat dfA = new DecimalFormat("$###.00");
  8.     System.out.println("This is the PiggyBank program.");
  9.     System.out.println("What's your name?");
  10.     String name = input.nextLine();
  11.     //Questions about how many coins the user has.
  12.     System.out.println("How many quarters do you have?");
  13.     int quarters = input.nextInt();
  14.     System.out.println("How many dimes do you have?");
  15.     int dimes = input.nextInt();
  16.     System.out.println("How many nickels do you have?");
  17.     int nickels = input.nextInt();
  18.     System.out.println("How many pennies do you have?");
  19.     int pennies = input.nextInt();
  20.     System.out.println("How many weeks have you saved up?");
  21.     double weeks = input.nextDouble();
  22.     //Calculations.
  23.     double vquarters = quarters * .25;
  24.     double vdimes = dimes * .10;
  25.     double vnickels = nickels * .05;
  26.     double vpennies = pennies * .01;
  27.     double vtotal = vpennies + vnickels + vdimes + vquarters;
  28.     double avgweek = vtotal / weeks;
  29.     double avgyear = avgweek * 52;
  30.     System.out.println("Coin" + "         " + "Quantity" + "         " + "Value");
  31.     System.out.println("Pennies" + "\t      " + pennies + "\t\t" + dfA.format(vpennies));
  32.     System.out.println("Nickels" + "\t      " + nickels + "\t\t" + dfA.format(vnickels));
  33.     System.out.println("Dimes" + "\t      " + dimes + "\t\t" + dfA.format(vdimes));
  34.     System.out.println("Quarters" + "\t      " + quarters + "\t\t" + dfA.format(vquarters));
  35.     System.out.println("You have " + dfA.format(vtotal) + " dollars in savings.");
  36.     System.out.println("You've saved " + dfA.format(avgweek) + " per week.");
  37.     System.out.println(name + " you can save " + dfA.format(avgyear) + " per year!");
  38.    
  39.   }
  40. }
Add Comment
Please, Sign In to add comment