import java.util.Scanner;

 public class Solution
 {
     public static void main(String[] args)
     {
         Scanner input = new Scanner(System.in);

         System.out.print("Loan Amount: ");
         double loanAmount = input.nextDouble();
         System.out.print("Number of Years: ");
         int numberOfYears = input.nextInt();
         System.out.print("Annual Interest Rate: ");
         double interestRate = input.nextDouble();

         input.close();

         double monthlyPayment = loanAmount * (interestRate / 12) /
             (1 - 1 / Math.pow(1 + interestRate / 12, numberOfYears * 12));
         System.out.println("Monthly Payment: " + monthlyPayment);
         double totalPayment = monthlyPayment * numberOfYears * 12;
         System.out.println("Total Payment: " + totalPayment);

         System.out.printf("%s\t\t%s\t\t%s\t\t%s", "Payment#", "Interest", "Principal", "Balance");
         System.out.println();

         double interest, principal;
         double balance = loanAmount;

         for(int i = 1; i <= numberOfYears * 12; i++)
         {
             interest = interestRate / 12 * balance;
             principal = monthlyPayment - interest;
             balance -= principal;
             System.out.printf("%d\t\t%f\t\t%f\t\t%f", i, interest, principal, balance);
             System.out.println();
         }
     }
 }

HW4.22的更多相关文章

  1. CENTOS 6.5 平台离线编译安装 Mysql5.6.22

    一.下载源码包 http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.22.tar.gz 二.准备工作 卸载之前本机自带的MYSQL 安装 cmake,编 ...

  2. EC笔记:第4部分:22、所有成员都应该是private的

    EC笔记:第4部分:22.所有成员都应该是private的 更简单的访问 用户不用记得什么时候该带上括号,什么时候不用带上括号(因为很确定的就要带上括号) 访问限制 对于public的成员变量,我们可 ...

  3. Hadoop学习笔记—22.Hadoop2.x环境搭建与配置

    自从2015年花了2个多月时间把Hadoop1.x的学习教程学习了一遍,对Hadoop这个神奇的小象有了一个初步的了解,还对每次学习的内容进行了总结,也形成了我的一个博文系列<Hadoop学习笔 ...

  4. 在同一个硬盘上安装多个 Linux 发行版及 Fedora 21 、Fedora 22 初体验

    在同一个硬盘上安装多个 Linux 发行版 以前对多个 Linux 发行版的折腾主要是在虚拟机上完成.我的桌面电脑性能比较强大,玩玩虚拟机没啥问题,但是笔记本电脑就不行了.要在我的笔记本电脑上折腾多个 ...

  5. Fedora 22中的Services and Daemons

    Introduction Maintaining security on your system is extremely important, and one approach for this t ...

  6. Fedora 22中的RPM软件包管理工具

    Introduction The RPM Package Manager (RPM) is an open packaging system that runs on Fedora as well a ...

  7. Fedora 22中的用户和用户组管理

    The control of users and groups is a core element of Fedora system administration. This chapter expl ...

  8. Fedora 22中的日期和时间配置

    Introduction Modern operating systems distinguish between the following two types of clocks: A real- ...

  9. Fedora 22中的DNF软件包管理工具

    Introduction DNF is the The Fedora Project package manager that is able to query for information abo ...

随机推荐

  1. ECMA5.1中Object.seal()和Object.freeze()的区别

    1  Object.seal(O)的调用 When the seal function is called, the following steps are taken:   If Type(O) i ...

  2. 配置php连接apache

    配置php连接apache 1.安装php所需要的库 yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel li ...

  3. linux-信号。

    信号 信号是在软件层次上对中断机制的一种模拟,在原理上,一个进程收到一个信号与处理器收到一个中断请求可以说是一样的. 信号是异步的,一个进程不必通过任何操作来等待信号的到达,事实上,进程也不知道信号到 ...

  4. Cocos2d-x课程大纲/学习路线

    Cocos2d-x课程大纲/学习路线 这是什么? 这个一个Cocos2d-x技术路线的课程大纲/学习大纲. 你能用它做什么? 如果你是找工作的人, 利用本大纲, 你可以学习Cocos2d-x, 做一个 ...

  5. z-index使用以及失效的处理方法

    1.一般z-index的使用是在有两个重叠的标签,在一定的情况下控制其中一个在另一个的上方出现. 2.z-index值越大就越是在上层.z-index:9999:z-index元素的position属 ...

  6. 数组-去重、排序方法、json排序

    1.数组去重 /*方法一: 1,'1' 会被认为是相同的; 所有hash对象,如:{x;1},{y:1}会被认为是相同的 //10ms */ Array.prototype.unique=functi ...

  7. 解决 nginx 返回数据不完整的方法

    通过PHP请求接口时发现接口的内容输出没有完整的返回整个数据,早上只修改了nginx api_metrics插件里的计算response大小的代码,观察日志发现一条: 2012/08/28 02:13 ...

  8. VC菜菜鸟:建立第一个基于Visual C++的Windows窗口程序

    建立第一个基于VisualC++的Windows窗口程序: 发表于:http://blog.csdn.net/it1988888/article/details/10306585 a)执行命令:新建 ...

  9. PPT2010小技巧 教你如何快捷抠图

    相信不少人在做PPT时,都有想插入个漂亮个性图案的想法,但是往往手头上的图片都不太令人满意,需要“裁剪”一下才能达不到自己想要的效果.这时大部分人可能会PS,但是相比起今天要分享给大家的方法,步骤就显 ...

  10. simhash--文本排重

    转载自 https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/zh/06.12.md http: ...