MelindaElezovic

PiggyBank

Nov 13th, 2015
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. //Melinda
  2. //11.12.15
  3. //PiggyBank
  4. import java.util.*;
  5. import java.text.*;
  6. public class PiggyBank
  7. {
  8.   public static void main(String [] args)
  9.   {
  10.     Scanner input = new Scanner (System.in);
  11.     System.out.println("What is your name?");
  12.     String name = input.nextLine();
  13.     System.out.println("How many quarters do you have this week?");
  14.     int quarters = input.nextInt();
  15.     System.out.println("How many dimes do you have this week?");
  16.     int dimes = input.nextInt();
  17.     System.out.println("How many nickels do you have this week?");
  18.     int nickels = input.nextInt();
  19.     System.out.println("How many pennies do you have this week?");
  20.     int pennies = input.nextInt();
  21.     //calulations
  22.  
  23.     DecimalFormat df = new DecimalFormat("$###,###.00");
  24.     double quarterValue = quarters*.25;
  25.     double dimeValue = dimes*.10;
  26.     double nickelValue = nickels*.05;
  27.     double pennyValue = pennies*.01;
  28.    
  29.     System.out.println("Coin\t\tAmount");
  30.     System.out.println("Quarters:\t\t" + quarters);
  31.     System.out.println("Dimes:\t\t" + dimes);
  32.     System.out.println("Nickels:\t\t" + nickels);
  33.     System.out.println("Pennies:\t\t" + pennies);
  34.    
  35.     double totalCoins = (quarterValue + dimeValue + nickelValue + pennyValue);
  36.     System.out.println("You have a total of $" + totalCoins);
  37.     double weeklyAverage = totalCoins/4;
  38.     System.out.println("You have saved a weekly average of $" + weeklyAverage);
  39.     double yearlySavings = weeklyAverage*52;
  40.     System.out.println(name);
  41.     System.out.println("if you continue to save at this rate in a year you will have $" +yearlySavings);
  42.   }
  43. }
Add Comment
Please, Sign In to add comment