Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS570-Java_Projects
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bjv33
CS570-Java_Projects
Commits
aca675d3
Commit
aca675d3
authored
6 years ago
by
bjv33
Browse files
Options
Downloads
Patches
Plain Diff
Loan Payment Calculator with Interest, Principal, and Balance
parent
667bb4e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Loan_Payment_Calculator.java
+124
-0
124 additions, 0 deletions
Loan_Payment_Calculator.java
with
124 additions
and
0 deletions
Loan_Payment_Calculator.java
0 → 100644
+
124
−
0
View file @
aca675d3
// Program: Loan_Payment_Calculator.java
// Purpose: This program calculates monthly loan payments including interest.
// Author: Brian Vojtko
// Date: 10/24/2018
import
java.text.DecimalFormat
;
import
java.util.Scanner
;
public
class
Loan_Payment_Calculator
{
public
static
void
main
(
String
[]
args
){
//Make outputs in 2 decimals
DecimalFormat
money
=
new
DecimalFormat
(
".00"
);
char
decision
=
'y'
;
//Loops program if user responded with 'y'
while
(
decision
==
'y'
||
decision
==
'Y'
)
{
Scanner
input
=
new
Scanner
(
System
.
in
);
//Integers
double
interestPercent
;
double
monthlyRate
;
double
totalInterest
=
0
;
double
payment
;
//User Introduction
System
.
out
.
println
(
" Loan Payment Calculator"
);
System
.
out
.
println
(
"*********************************"
);
//Amount user owes
System
.
out
.
println
(
"Enter the initial loan amount: "
);
double
amount
=
input
.
nextDouble
();
//Error Loop
while
(
amount
>
1000000
)
{
System
.
out
.
println
(
"the loan amount cannot exceed $1,000,000. Try again."
);
amount
=
input
.
nextDouble
();
continue
;
}
//Error Loop
while
(
amount
<=
0
)
{
System
.
out
.
println
(
"You must enter a value greater than zero. Try again."
);
amount
=
input
.
nextDouble
();
continue
;
}
//Annual Interest Rate
System
.
out
.
println
(
"Enter the annual interest rate (as a percentage): "
);
interestPercent
=
input
.
nextDouble
();
//Calculate Monthly Interest Rate
monthlyRate
=
(
interestPercent
/
100
)
/
12
;
//Error Loop
while
(
interestPercent
<
2
||
interestPercent
>
15
)
{
System
.
out
.
println
(
"You must enter a value between 2.0 and 15.0 (inclusive). Try again."
);
interestPercent
=
input
.
nextDouble
();
continue
;
}
//Amount of years user has to repay
int
years
;
System
.
out
.
println
(
"Enter the term of the loan in years: "
);
years
=
input
.
nextInt
();
//Error Loop
while
(
years
<=
0
||
years
>
30
)
{
System
.
out
.
println
(
"Please enter a term between 1-30 years."
);
years
=
input
.
nextInt
();
continue
;
}
//Monthly Payment Calculation
double
m
=
(
years
*
12
);
payment
=
(
amount
*
monthlyRate
)
/
(
1
-
Math
.
pow
(
1
+
monthlyRate
,
-
m
));
//Monthly Payment output
System
.
out
.
println
(
"Your monthly payment is: $"
+
money
.
format
(
payment
));
//Line space
System
.
out
.
println
(
""
);
//Beginning of Loan Chart
System
.
out
.
println
(
"Month\t\tInterest\tPrincipal\tBalance"
);
System
.
out
.
println
(
"----------------------------------------------------------"
);
//Loan Chart Calculation
double
balance
=
amount
,
principal
,
interest
;
for
(
int
i
=
1
;
i
<=
m
;
i
++)
{
interest
=
monthlyRate
*
balance
;
principal
=
payment
-
interest
;
balance
=
balance
-
principal
;
totalInterest
+=
interest
;
//User output
System
.
out
.
println
(
i
+
"\t\t"
+
"$"
+
money
.
format
(
interest
)
+
"\t\t"
+
"$"
+
money
.
format
(
principal
)
+
"\t\t"
+
"$"
+
money
.
format
(
balance
));
}
//User output for total amount of interest paid
System
.
out
.
println
(
""
);
System
.
out
.
println
(
"The total amount of interest paid is: $"
+
money
.
format
(
totalInterest
));
System
.
out
.
println
(
""
);
//Repeat Loop
boolean
yesDecision
;
boolean
noDecision
;
input
.
nextLine
();
do
{
System
.
out
.
println
(
"Do you have another loan to process? (y/n): "
);
decision
=
input
.
nextLine
().
charAt
(
0
);
yesDecision
=
(
decision
==
'y'
||
decision
==
'Y'
);
noDecision
=
(
decision
==
'n'
||
decision
==
'N'
);
}
while
(!(
yesDecision
||
noDecision
));
System
.
out
.
println
(
""
);
}
System
.
out
.
println
(
"Thank you for using our loan calculator. Goodbye!"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment