Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Nov 15th, 2012  |  syntax: Java  |  size: 1.53 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.Scanner;
  2.  
  3. public class U4A4 implements Runnable
  4. {
  5.     private int count = 0;
  6.     private double accum = 0;
  7.     private int apr, min, months;
  8.     private double balance, profit;
  9.    
  10.     public static void main(String[] args)
  11.     {
  12.         U4A4 u = new U4A4();
  13.         u.run();
  14.     }
  15.    
  16.     public U4A4()
  17.     {
  18.         Scanner in = new Scanner(System.in);
  19.        
  20.         System.out.print("Enter credit card balance: ");
  21.         balance = in.nextDouble();
  22.         System.out.print("\n\nEnter minimum payment (as % of balance): ");
  23.         min = in.nextInt();
  24.         System.out.print("\n\nEnter annual percentage rate: ");
  25.         apr = in.nextInt();
  26.        
  27.         profit = this.getMonths(balance);
  28.        
  29.         System.out.println("\n\n\n# of months to pay off debt =  " + count);
  30.         System.out.println("\nProfit for credit card company = " + profit + "\n");
  31.     }
  32.    
  33.     public double getMonths(double bal)
  34.     {
  35.         double newBal, payment;
  36.         count++;
  37.        
  38.         payment = bal * min;
  39.        
  40.         if (payment < 20 && bal > 20)
  41.         {
  42.             newBal = bal * (1 + apr / 12 - 20);
  43.             accum += 20;
  44.            
  45.         } else if (payment < 20 && bal < 20)
  46.         {
  47.             newBal = 0;
  48.             accum += bal;
  49.         } else
  50.         {
  51.             newBal = bal * (1 + apr / 12) - payment;
  52.             accum += payment;
  53.         }
  54.         if (newBal != 0) {
  55.             getMonths(newBal);
  56.         }
  57.        
  58.         return accum;
  59.     }
  60. }
clone this paste RAW Paste Data