Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.text.*;
- public class PiggyBank{
- public static void main (String []args){
- Scanner input = new Scanner(System.in);
- DecimalFormat dfA = new DecimalFormat("$###.00");
- System.out.println("This is the PiggyBank program.");
- System.out.println("What's your name?");
- String name = input.nextLine();
- //Questions about how many coins the user has.
- System.out.println("How many quarters do you have?");
- int quarters = input.nextInt();
- System.out.println("How many dimes do you have?");
- int dimes = input.nextInt();
- System.out.println("How many nickels do you have?");
- int nickels = input.nextInt();
- System.out.println("How many pennies do you have?");
- int pennies = input.nextInt();
- System.out.println("How many weeks have you saved up?");
- double weeks = input.nextDouble();
- //Calculations.
- double vquarters = quarters * .25;
- double vdimes = dimes * .10;
- double vnickels = nickels * .05;
- double vpennies = pennies * .01;
- double vtotal = vpennies + vnickels + vdimes + vquarters;
- double avgweek = vtotal / weeks;
- double avgyear = avgweek * 52;
- System.out.println("Coin" + " " + "Quantity" + " " + "Value");
- System.out.println("Pennies" + "\t " + pennies + "\t\t" + dfA.format(vpennies));
- System.out.println("Nickels" + "\t " + nickels + "\t\t" + dfA.format(vnickels));
- System.out.println("Dimes" + "\t " + dimes + "\t\t" + dfA.format(vdimes));
- System.out.println("Quarters" + "\t " + quarters + "\t\t" + dfA.format(vquarters));
- System.out.println("You have " + dfA.format(vtotal) + " dollars in savings.");
- System.out.println("You've saved " + dfA.format(avgweek) + " per week.");
- System.out.println(name + " you can save " + dfA.format(avgyear) + " per year!");
- }
- }
Add Comment
Please, Sign In to add comment