PDA

View Full Version : Big help request



orava
01-16-2008, 12:46 PM
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.

This is what i got done...


import java.io.*;

public class loancalc {

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

BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System.in ));

double loan, originalloan, intrest, payment, decintrest;

System.out.print("Give loan amount: ");
loan = Double.parseDouble( stdin.readLine() );
originalloan = loan;

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

System.out.print("Give monthly payment: ");
payment = Double.parseDouble(stdin.readLine() );

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" );



}
}

djr33
01-16-2008, 01:34 PM
We're not here to do homework for you. We can, however, help.

This means that you should NEVER feel the need to post the full directions for an assignment. Much like your instructor we may help with some step along the way, but we will not do the work for you.

If something in particular is confusing, please specify and someone will try to help you understand.

Plus, it's for a class, right? If we do it, you won't learn anything. If you dislike it, I'm not sure why you would have taken the course, and the only reason such a course would be required is if it was required for a major, in which case I'd say you like it (and should be able to work it out-- remember, this stuff takes time to learn), or you might want to consider another path.