FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaTutorial/src/F032_SolutionMortgageCalculator.java at master · windweb/JavaTutorial · GitHub
windweb
/
JavaTutorial
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaTutorial
/
src
/
F032_SolutionMortgageCalculator.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (42 loc) · 1.8 KB
Breadcrumbs
JavaTutorial
/
src
/
F032_SolutionMortgageCalculator.java
Copy path
File metadata and controls
53 lines (42 loc) · 1.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import
java
.
text
.
NumberFormat
;
import
java
.
util
.
Scanner
;
public
class
F032_SolutionMortgageCalculator
{
public
static
void
main
(
String
[]
args
) {
final
byte
MONTHS_IN_YEAR
=
12
;
final
byte
PERCENT
=
100
;
int
principal
=
0
;
float
monthlyInterest
=
0
;
int
numberOfPayments
=
0
;
Scanner
scanner
=
new
Scanner
(
System
.
in
);
while
(
true
) {
System
.
out
.
print
(
"Principal / Основная сумма (1K - 1M): "
);
principal
=
scanner
.
nextInt
();
if
(
principal
>=
1000
&&
principal
<=
1_000_000
)
break
;
System
.
out
.
println
(
"Enter a value between 1000 and 1,000,000"
);
}
while
(
true
) {
System
.
out
.
print
(
"Annual Interest Rate / Годовая процентная ставка: "
);
float
annualInterest
=
scanner
.
nextFloat
();
if
(
annualInterest
>=
1
&&
annualInterest
<=
30
) {
monthlyInterest
=
annualInterest
/
PERCENT
/
MONTHS_IN_YEAR
;
break
;
}
System
.
out
.
println
(
"Enter a value between 1 and 30"
);
}
while
(
true
) {
System
.
out
.
print
(
"Period (Years): "
);
byte
years
=
scanner
.
nextByte
();
if
(
years
>=
1
&&
years
<=
30
) {
numberOfPayments
=
years
*
MONTHS_IN_YEAR
;
break
;
}
System
.
out
.
println
(
"Enter a value between 1 and 30"
);
}
double
mortgage
=
principal
* (
monthlyInterest
*
Math
.
pow
(
1
+
monthlyInterest
,
numberOfPayments
))
/ (
Math
.
pow
(
1
+
monthlyInterest
,
numberOfPayments
) -
1
);
String
mortgageFormatted
=
NumberFormat
.
getCurrencyInstance
().
format
(
mortgage
);
System
.
out
.
println
(
"Mortgage / Ипотека: "
+
mortgageFormatted
);
}
}
Back
|
FazBrowse Home
|
New Git URL