Biyernes, Setyembre 20, 2013

LabExer#11

11. Develop a program for computing the month-by-month balance in your savings account. You can make one transaction-a deposit or a withdrawal-each month. Interest is added to the account at the beginning of each month. The monthly interest rate is the yearly percentage rate divided by 12.

Use the following formula:
yearlyRate=0.025.
balance = balance+(yearlyRate / 12) * balance
Sample Output:
Enter d for deposit, w for withdrawal or x to exit: d
Beginning of Month Balance: 0.0
Enter deposit amount: 5000
Balance after transaction: 5000.0
Enter d for deposit, w for withdrawal or x to exit: d
Beginning of Month Balance: 5010.416666666667
Enter deposit amount: 3000
Balance after transaction: 8010.416666666667
Enter d for deposit, w for withdrawal or x to exit: w
Beginning of Month Balance: 8027.105034722223
Enter withdrawal amount: 2000
Balance after transaction: 6027.105034722223
Enter d for deposit, w for withdrawal or x to exit: e
Beginning of Month Balance: 6039.66150354456
Balance after transaction: 6039.66150354456





import javax.swing.JOptionPane;

public class wee{

    public static void SavingsAccount (String[]args){
       
        double yearlyRate=0.025, balance=0,balance1=0,withdrawal=0;
        String choice="";
        do{
           
       
        choice=JOptionPane.showInputDialog(null, "Please enter choice.. \n\nD. Deposit \nW. Withdrawal \nE. Exit" + "\n\nBeginning of Month Balance: "+balance1);
       
        switch(choice.toLowerCase()){
        case "d":
           
        balance=Double.parseDouble(JOptionPane.showInputDialog("Enter deposit amount: "));   
        balance1=balance1+balance;
        JOptionPane.showMessageDialog(null, "Balance after transaction: "+balance1);
        balance1 = balance1+(yearlyRate / 12) * balance1;
        break;
        case "w":
            withdrawal=Double.parseDouble(JOptionPane.showInputDialog("Enter amount: "));
            if(balance1>=withdrawal){
                balance1=balance1-withdrawal;
                JOptionPane.showMessageDialog(null, "Balance after transaction: "+balance1);
                balance1 = balance1+(yearlyRate / 12) * balance1;
            }
            else{
                JOptionPane.showMessageDialog(null, "Insufficient Funds!", "Alert", JOptionPane.ERROR_MESSAGE);
            }
                break;
            }
        }
        while(!(choice.toLowerCase().equals("e")));
        JOptionPane.showMessageDialog(null, "Balance after transaction: "+balance1);
       
        }
}

Walang komento:

Mag-post ng isang Komento