Guest User

Untitled

a guest
Dec 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package org.hin.Lekse.Oblig2;
  2.  
  3. /**
  4.  * @author Fredrik Hauger Olsen
  5.  */
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class MånedligeBetalinger {
  10.    
  11.     public static double monthlyPayment (double loanAmount, double monthlyInterestRate, int years) {
  12.         return loanAmount*monthlyInterestRate/(1-1/(Math.pow(1+monthlyInterestRate, years*12)));
  13.     }
  14.    
  15.     public static void main(String[] args) {
  16.         double monthlyP, totalP, loanAmount;
  17.         int years;
  18.         JOptionPane p = new JOptionPane();
  19.        
  20.         try {
  21.         loanAmount = Double.parseDouble(p.showInputDialog(null, "Tast inn lånebeløpet."));
  22.         years = Integer.parseInt(p.showInputDialog(null, "Tast inn antall år for nedbetaling."));
  23.         System.out.println("Rentefot\tMånedlig betaling\tTotalt betalt");
  24.         for(double i=4; i<=9; i+=0.5)
  25.         {
  26.             monthlyP = monthlyPayment(loanAmount, i/100/12, years);
  27.             totalP = monthlyP*12*years;
  28.             System.out.format("%.3f%% \t\t %.2f \t\t %.2f\n", i, monthlyP, totalP);
  29.         }
  30.         } catch (NumberFormatException e) {
  31.             p.showMessageDialog(null, "Du har ikke tastet inn et beløp.");
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment