Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let's make some simple programs!

Name: Anonymous 2010-05-08 4:03

Because I know that half of /prog/ can't program, let's make simple ones!

---------------------- MySavings.java ----------------------

/**
 * @(#)MySavings.java
 *
 * MySavings application
 *
 * @author Tim H
 * @version 1.00 2010/5/7
 */
 
import java.util.Scanner;

public class MySavings {
   
    public static void printInterface() {
        System.out.print(
            "1. Show total in bank.\n" +
            "2. Add a penny.\n" +
            "3. Add a nickel.\n" +
            "4. Add a dime.\n" +
            "5. Add a quarter.\n" +
            "6. Take money of out bank.\n" +
            "Enter 0 to quit.\n" +
            "Enter your choice: "
            );
    }
   
    public static void main(String[] args) {
       
        Scanner input = new Scanner(System.in);
        int choice = 1;
        int moneyChoice = 0;
        double amount = 0;
       
        PiggyBank bank = new PiggyBank();
       
        while(choice > 0){
            printInterface();
            choice = input.nextInt();
           
            switch(choice){
                case 0: System.out.println("(c)Tim H 2010\nHave a nice day!"); break;
                case 1: System.out.println("Your current total is: " + bank.GetTotal()); break;
                case 2:
                case 3:
                case 4:
                case 5: moneyChoice = choice - 2; bank.AddMoney(moneyChoice); break;
                case 6:
                    System.out.print("Enter the amount you wish to withdraw: ");
                    amount = input.nextDouble();
                    bank.SubtractTotal(amount);
                    break;
                default:
                    System.out.println("Please enter a choice between 1-6!");
                    break;
            }
               
        }

---------------------- PiggyBank.java ----------------------


class PiggyBank {
    double total;
   
   
    public PiggyBank(){
        total = 100;
    }
   
    public void AddMoney(int choice){
        switch (choice) {
            case 0:
                total += 0.01;
                System.out.println("One penny added to total!\nYour total is now: " + total);
                break;
            case 1:
                total += 0.05;
                System.out.println("One nickel added to total!\nYour total is now: " + total);
                break;
            case 2:
                total += 0.10;
                System.out.println("One dime added to total!\nYour total is now: " + total);
                break;
            case 3:
                total += 0.25;
                System.out.println("One quarter added to total!\nYour total is now: " + total);
                break;
           
        }
    }
   
    public double GetTotal(){
        return total;
    }
   
    public void SubtractTotal(double amount){
        total -= amount;
        System.out.println(amount + " has been subtracted from your total!\nYour total is now: " + total);
    }
}

    }
   
}

Name: Anonymous 2010-05-08 23:29

>>16
Someone else added it when he wasn't looking, in the early '90s. It took him until Py3K to notice and have it moved to the functools module.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List