Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package javaapplication1;
  6. import javax.swing.JOptionPane;
  7. /**
  8.  *
  9.  * @author Cody
  10.  */
  11. public class JavaApplication1 {
  12.  
  13.     public static class BankAccount{
  14.         private static float balance;
  15.         private static float interestRate;
  16.         //String compondPeriod;
  17.        
  18.        
  19.         public void setBalance(float amount){
  20.             this.balance = amount;          
  21.         }
  22.         public void setInterestRate(float rate){
  23.             this.interestRate = rate;
  24.         }
  25.        
  26.         public void showBalance(){
  27.             JOptionPane.showMessageDialog(null, this.balance);
  28.         }
  29.        
  30.         public void showInterestRate(){
  31.             JOptionPane.showMessageDialog(null, this.interestRate);
  32.         }
  33.        
  34.         public float calculateBalance(int compoundPeriod){
  35.             for(int i = compoundPeriod;i>0;i--){
  36.                 balance = balance *(1+interestRate);
  37.             }
  38.             return balance;
  39.         }
  40.        
  41.         public BankAccount() {
  42.             this.balance = 0;
  43.             this.interestRate = 0;
  44.             //this.compondPeriod="";
  45.         }
  46.     }
  47.    
  48.     public static void main(String[] args){
  49.         BankAccount account1 = new BankAccount();
  50.         String balance = JOptionPane.showInputDialog(null, "Please enter the amount in your account");
  51.         String interestRate = JOptionPane.showInputDialog(null, "Please the interest rate in %");
  52.        
  53.         float balance2 = Float.parseFloat(balance);
  54.         float rate = Float.parseFloat(interestRate);
  55.         rate /=100;
  56.         account1.setBalance(balance2);
  57.         account1.setInterestRate(rate);
  58.        
  59.        
  60.         account1.showBalance();
  61.         account1.showInterestRate();
  62.         int compoundPeriod[] = {1, 12, 365};
  63.        
  64.         for(int i=0;i<3;i++){
  65.             JOptionPane.showMessageDialog(null, account1.calculateBalance(compoundPeriod[i]));
  66.         }
  67.         //sayHelloTo(balance);
  68.         System.exit(0);
  69.         // TODO code application logic here
  70.     }
  71.    
  72.     public static void sayHelloTo(String nameToGreet){
  73.         JOptionPane.showMessageDialog(null, "Hello, " + nameToGreet + "!");
  74.     }
  75.    
  76.    
  77.    
  78. }
Add Comment
Please, Sign In to add comment