Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Big help request

Soo.. I have this programming thing for school and im gettin reallly frustrated coz i just wont get
it.
I managed to make some basic stuff, which is nothing like required or not even pretty
coding.
So here is what the program should do:

1. Asks from user amount of loan, yearly intrest and monthly payment and stores this info to
array(s) (and arrays confused the heck out of me)
2. Checks that the info the user inputted is ok (numbers, bigger than 0, monthly payment is bigger
than first months intrest(if not it chages monthly payment to first months intrest + 1)
3. Then asks the user if he wants to input other combination (Yes/No) if answer is yes it does
the steps 1 and 2 again (and again and again), if answer is no, goes to step 4
4. calculates how long it takes to pay the loan back, how much were total intrests, how much was
total cost (loan + intrests)
5. Prints out the info from all combinations AND writes same info in text file
Out put would look like this:
1. loan
loan amount: 1000 euro
intrest: 10 %
monthly payment: 100 euro
total intrests: 48,6 euro
total cost: 1048,6 euro
time: 0 year 11 months

2. loan
loan amount: 1200 euro
intrest: 15 %
monthly payment: 90 euro
total intrests: 121 euro
total cost: 1321 euro
time: 1 year 3 months

And ofc it should be nice and tidy, so that stuff is in differetn methods, rather than all in main,
but again that was something i couldnt figure out. and ofcourse it only needs 1 decimal or no
decimals at all.

So if someone would have some free time in their hands to find time to help this girl out,
you would have my eternal grattitude and admiration
I know its askin a lot so if u feel like im out of the line, just ignore me, thanks all.

here is what i got done...

Code:
```import java.io.*;

public class loancalc {

public static void main (String args[]) throws Exception {

double loan, originalloan, intrest, payment, decintrest;

System.out.print("Give loan amount: ");
originalloan = loan;

System.out.print("Give yearly intrest without %-mark: ");
decintrest=intrest/100;

System.out.print("Give monthly payment: ");

double firstintrest;

firstintrest = loan * decintrest / 12;

if (payment < firstintrest) {
System.out.println("Monthyly payment cant be smaller than first month intrests");
payment = firstintrest + 1;
System.out.println("Minimun payment is " + payment + " euro");
System.out.println("Calculating with minimum payment.");
}

int time = 0;
double loanintrest;
double totalintrest = 0;
double totalcost;

do {
loanintrest	= loan * decintrest / 12;
loan = loan + loanintrest;
loan = loan - payment;
totalintrest = totalintrest + loanintrest;
time++;
}

while (loan > 0);

totalcost = originalloan + totalintrest;

System.out.println( );
System.out.println("Loan");
System.out.println("-------------");
System.out.println("Loan: " + originalloan + " euro");
System.out.println("Loan intrest: " + intrest + " %");
System.out.println("Monthly payment " + payment + " euro");
System.out.println("Totalinrests: " + totalintrest + " euro" );
System.out.println("Total cost: " + totalcost + " euroa" );
System.out.println("Time: " + time + " months" );

}
}```

• Try this on for size. I can't get the correct euro decimal and thousands separator figured out.

I also updated with standard java conventions and spelling.

You might be able to find the currency formatting here:
http://java.sun.com/j2se/1.5.0/docs/...malFormat.html

Code:
```import java.io.BufferedReader;
import java.text.DecimalFormat;
import java.util.Currency;
import java.util.Locale;

public class LoanCalc {

private double decInterest;

private final DecimalFormat euroFormat = new DecimalFormat();

private int interest;

private double loan;

private double originalLoan;

private double payment;

public static void main(String args[]) throws Exception {
LoanCalc lc = new LoanCalc();

DecimalFormat euroFormat = new DecimalFormat();
euroFormat.setMaximumFractionDigits(2);
euroFormat.setCurrency(Currency.getInstance(Locale.UK));

System.out.print("Give loan amount: ");

System.out.print("Give yearly interest without %-mark: ");

System.out.print("Give monthly payment: ");

System.out.println(lc.toString());
}

public LoanCalc() {
this.euroFormat.setMaximumFractionDigits(2);
this.euroFormat.setCurrency(Currency.getInstance(Locale.UK));
}

public void setInterest(int interest) {
this.interest = interest;
this.decInterest = interest / 100;
}

public void setLoan(double loan) {
this.loan = loan;
this.originalLoan = loan;
}

public void setPayment(double payment) {
this.payment = payment;
}

public String toString() {
StringBuffer sb = new StringBuffer();

double firstIntrest = this.loan * this.decInterest / 12;

if (this.payment < firstIntrest) {
sb.append("Monthly payment can't be smaller than first month interest\n");
this.payment = firstIntrest + 1;
sb.append("Minimum payment is " + this.payment + " euro\n");
sb.append("Calculating with minimum payment...\n");
}

int time = 0;
double loanInterest;
double totalInterest = 0;
double totalCost;

do {
loanInterest = this.loan * this.decInterest / 12;
this.loan = this.loan + loanInterest;
this.loan = this.loan - this.payment;
totalInterest = totalInterest + loanInterest;
time++;
} while (this.loan > 0);

totalCost = this.originalLoan + totalInterest;

sb.append("Loan\n");
sb.append("-------------\n");
sb.append("Loan: " + this.euroFormat.format(this.originalLoan) + " euro\n");
sb.append("Loan interest: " + this.interest + "%\n");
sb.append("Monthly payment " + this.euroFormat.format(this.payment) + " euro\n");
sb.append("Total interest: " + this.euroFormat.format(totalInterest) + " euro\n");
sb.append("Total cost: " + this.euroFormat.format(totalCost) + " euro\n");
sb.append("Time: " + time + " months\n");
return sb.toString();
}
}```

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•