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("You have " + pennies + " pennies." + " This equals " + dfA.format(vpennies) + " dollars.");
- System.out.println("You have " + nickels + " nickels." + " This equals " + dfA.format(vnickels) + " dollars.");
- System.out.println("You have " + dimes + " dimes." + " This equals " + dfA.format(vdimes) + " dollars.");
- System.out.println("You have " + quarters + " quarters." + " This equals " + dfA.format(vquarters) + " dollars.");
- 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