Sunday, August 24, 2014

Bank Transaction

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

import javax.swing.JOptionPane;
public class LabExercise11 {
    public static void main(String[] args)
    {
        double yearlyRate=0.025;
        double balance=0.0;
        double amount;
        double withdraw;
        String menu;    

       do
        { 
           menu=JOptionPane.showInputDialog("[D]eposit \n[W]ithdraw \n[E]xit \nBeginning of Month Balance: "+balance);
            
            menu = menu.toLowerCase();
       switch(menu.charAt(0))
        {
       case 'd':
   
        if(balance == 0.0)
         {
         amount=Double.parseDouble(JOptionPane.showInputDialog("\nEnter Deposit Amount: "));
         JOptionPane.showMessageDialog(null,"Balance after transaction: "+amount);
         balance= amount+(yearlyRate / 12) *amount;
    
         }
         else
         {
         amount=Double.parseDouble(JOptionPane.showInputDialog("\nEnter Deposit Amount: "));
         balance=amount+balance;
         JOptionPane.showMessageDialog(null,"Balance after transaction: "+balance);
         balance = balance+(yearlyRate / 12) * balance;
         }
        break;
       
        case 'w':
                   if(balance == 0.0)
                    {
                  JOptionPane.showMessageDialog(null,"Invalid Transaction. Empty balance.");
                    }
                    else
                    {
                      withdraw=Double.parseDouble (JOptionPane.showInputDialog("Enter Withdrawal Amount:"));  
                        if(withdraw>balance)
                        {      
                        JOptionPane.showMessageDialog(null, "Amount is beyond balance.","Invalid Transaction!", 0);
                        }
                        else
                        {
                            balance=balance-withdraw;  
                            JOptionPane.showMessageDialog(null,"You have successfully withdrawed "+withdraw);
                        }
                    }
                break;
            case 'e':
            JOptionPane.showMessageDialog(null,"Program is now terminating...");
            System.exit(0);
            break;
            default:
            JOptionPane.showMessageDialog(null,"Invalid choice."); 
              }        
           }   while(!menu.equals("e"));
        } 
    }

No comments:

Post a Comment

advertisement