ZhenghaoZhu

PiggyBank

Nov 12th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 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("You have " + pennies + " pennies." + " This equals " + dfA.format(vpennies) + " dollars.");
  31.     System.out.println("You have " + nickels + " nickels." + " This equals " + dfA.format(vnickels) + " dollars.");
  32.     System.out.println("You have " + dimes + " dimes." + " This equals " + dfA.format(vdimes) + " dollars.");
  33.     System.out.println("You have " + quarters + " quarters." + " This equals " + dfA.format(vquarters) + " dollars.");
  34.     System.out.println("You have " + dfA.format(vtotal) + " dollars in savings.");
  35.     System.out.println("You've saved " + dfA.format(avgweek) + " per week.");
  36.     System.out.println(name + " you can save " + dfA.format(avgyear) + " per year!");
  37.    
  38.    
  39.    
  40.    
  41.   }
  42. }
Add Comment
Please, Sign In to add comment