Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.hin.Lekse.Oblig2;
- /**
- * @author Fredrik Hauger Olsen
- */
- import javax.swing.JOptionPane;
- public class MånedligeBetalinger {
- public static double monthlyPayment (double loanAmount, double monthlyInterestRate, int years) {
- return loanAmount*monthlyInterestRate/(1-1/(Math.pow(1+monthlyInterestRate, years*12)));
- }
- public static void main(String[] args) {
- double monthlyP, totalP, loanAmount;
- int years;
- JOptionPane p = new JOptionPane();
- try {
- loanAmount = Double.parseDouble(p.showInputDialog(null, "Tast inn lånebeløpet."));
- years = Integer.parseInt(p.showInputDialog(null, "Tast inn antall år for nedbetaling."));
- System.out.println("Rentefot\tMånedlig betaling\tTotalt betalt");
- for(double i=4; i<=9; i+=0.5)
- {
- monthlyP = monthlyPayment(loanAmount, i/100/12, years);
- totalP = monthlyP*12*years;
- System.out.format("%.3f%% \t\t %.2f \t\t %.2f\n", i, monthlyP, totalP);
- }
- } catch (NumberFormatException e) {
- p.showMessageDialog(null, "Du har ikke tastet inn et beløp.");
- }
- }
- }
Add Comment
Please, Sign In to add comment