Feedback5PayoffComparison.java
Feedback5PayoffComparison.java
/**
* This calculator will provide how long it will take to payoff your credit card
* using minimum monthly payments vs. larger monthly payments.
*/
import
java
.
util
.
Scanner
;
/**
*
@author
Nathan Christensen
*
@version
1.0 Java Assn 6
*/
/**
* PayoffComparison
*
*/
public
class
Feedback5PayoffComparison
{
/**
*
*
@param
args
*/
public
static
void
main
(
String
[]
args
)
{
final
double
MIN
=
3.0
;
final
double
MAX
=
25.0
;
double
balance
;
double
rate
;
double
monthPay
;
int
month1
;
int
month2
;
String
info1
;
String
info2
;
double
percent
;
String
info
;
System
.
out
.
println
(
"This program calculates how long it will"
+
" take to pay off your credit \ncard balance with"
+
" minimum payments vs. larger payments.\n"
);
balance
=
readBalance
();
rate
=
readPercent
(
MIN
,
MAX
,
"credit card's annual interest rate"
);
monthPay
=
percentPay
();
Feedback5CreditCardAccount
acc1
=
new
Feedback5CreditCardAccount
(
balance
,
rate
);
Feedback5CreditCardAccount
acc2
=
new
Feedback5CreditCardAccount
(
balance
,
rate
,
monthPay
);
month1
=
acc1
.
payOff
();
month2
=
acc2
.
payOff
();
System
.
out
.
println
();
System
.
out
.
println
(
"Paying minimum required payment per month,"
+
"\n it will take "
+
month1
+
" months to pay off the"
+
" credit card.\n"
);
System
.
out
.
println
(
"Paying "
+
(
int
)
acc2
.
getPercent
()
+
"% of the"
+
" balance per month,\n it will take "
+
month2
+
" months"
+
" to pay off the credit card."
);
}
/**
* read balance
*
@return
balance
*/
public
static
double
readBalance
()
{
final
double
LOWEST
=
500.0
;
double
balance
;
Scanner
input
=
new
Scanner
(
System
.
in
);
do
{
System
.
out
.
print
(
"Enter the beginning balance (at least $"
+
(
int
)
LOWEST
+
"): "
);
balance
=
input
.
nextDouble
();
if
(
balance
<
LOWEST
)
System
.
out
.
println
(
"Invalid input. Try again"
);
}
while
(
balance
<
LOWEST
);
return
balance
;
}
/**
* read percent
*
@param
min
*
@param
max
*
@param
param
*
@return
valid percentage read
*/
public
static
double
readPercent
(
double
min
,
double
max
,
String
param
)
{
boolean
valid
=
false
;
double
rate
;
Scanner
input
=
new
Scanner
(
System
.
in
);
do
{
System
.
out
.
print
(
"Enter the "
+
param
+
" (between "
+
min
+
"% and "
+
max
+
"%): "
);
rate
=
input
.
nextDouble
();
if
(
rate
<
min
||
rate
>
max
)
System
.
out
.
println
(
"Invalid input. Try again"
);
else
valid
=
true
;
}
while
(
!
valid
);
return
rate
;
}
/**
* read percent pay
*
@return
valid percent pay
*/
public
static
double
percentPay
()
{
final
double
MIN
=
6.0
;
final
double
MAX
=
33.0
;
double
rate
=
0
;
int
choice
;
boolean
valid
=
true
;
Scanner
input
=
new
Scanner
(
System
.
in
);
do
{
valid
=
true
;
System
.
out
.
println
();
System
.
out
.
println
(
"1 - 10% of remaining balance each month"
);
System
.
out
.
println
(
"2 - 20% of remaining balance each month"
);
System
.
out
.
println
(
"3 - 30% of remaining balance each month"
);
System
.
out
.
println
(
"4 - Some other percent of the balance each month between 6 and 33 "
);
System
.
out
.
print
(
"Enter choice from Menu above: "
);
choice
=
input
.
nextInt
();
if
(
choice
==
1
)
rate
=
10
;
else
if
(
choice
==
2
)
rate
=
20
;
else
if
(
choice
==
3
)
rate
=
30
;
else
if
(
choice
==
4
)
rate
=
readPercent
(
MIN
,
MAX
,
"credit card's monthly payment rate"
);
else
{
System
.
out
.
println
(
"Invalid choice. Try again"
);
valid
=
false
;
}
}
while
(
!
valid
);
return
rate
;
}
}