I have two different codes, one you can pull up in a web browser and the other you can't.
Two questions...
1. How can I make the one I can pull up in a web browser into an amortization code? (First code shown)
2. How can I make the other one be shown in a web browser. (second code shown)
Yes, I know they look different. We're working on a team project and I can't figure out how to merge the two, so I'm trying to turn one into the other...
Thanks for all your help!!
<BODY>
<SCRIPT LANGUAGE="JavaScript">
// calculates the payments and updates for fields to
// display the result
// the next 9 lines is where I specify the equation for the calculation
function morgagepayment() {
var amt = document.frm.amt.value;
var ir = document.frm.ir.value / 1200;
var term = document.frm.term.value * 12;
var total=1;
for (i=0;i<term;i++) {
total = total * (1 + ir);
}
mp = amt * ir / ( 1 - (1/total));
// use Math object to chop all numbers after 2 digits
document.frm.payment.value = Math.round(mp*100)/100;
document.frm.total.value = Math.round(mp * term *100)/100 ;
}
</script>
<!--//The below code is used for making the table and specifying its style and look for the user interface>
<!--//type in the morgage amount>
<tr>
<td>Mortgage amount</td>
<td><input type="text" name="amt" value="200000" /></td>
</tr>
<!--//type in the interest rate>
<tr>
<td>Yearly interest rate</td>
<td><input type="text" name="ir" value="5.75" /></td>
</tr>
<!--//type in the term in years>
<tr>
<td>Term (in years)</td>
<td><input type="text" name="term" value="30" /></td>
</tr>
<tr><td colspan="2"><hr/></td></tr>
public class amortization {
public static void main(String args[]) {
// Make sure we use types that hold decimal places
double new_balance = 0.0, ending_balance = 0.0;
double interest_paid = 0.0, annual_rate = 0.0, principle_paid = 0.0, payment = 0.0;
Scanner input = new Scanner(System.in);
System.out.print("Please enter the original loan amount $ (-1 to end the program): ");
ending_balance = input.nextDouble();
System.out.print("Enter the interest rate on your loan %: ");
annual_rate = input.nextDouble();
System.out.println();
DecimalFormat f = new DecimalFormat("$#,###,###.00");
// Setup a counter to count payments
int count = 1;
// Get our standard payment which is 1/20 of loan
payment = (ending_balance / 20.0);
while (ending_balance > 0.0) {
new_balance = ending_balance;
// Calculate interest by multiplying rate against balance
interest_paid = new_balance * (annual_rate / 12.0);
// Subtract interest from your payment
principle_paid = payment - interest_paid;
// Subtract final payment from running balance
ending_balance = new_balance - principle_paid;
// If the balance remaining plus its interest is less than payment amount
// Then print out 0 balance, the interest paid and that balance minus the interest will tell us
// how much principle you paid to get to zero.
Well, for one, Java and JavaScript are not at all related in any way. You're not going to be able to copy and paste from one into the other and have anything other than a big ass broken mess.
If the second one, which is in Java, does what you need then you need to learn JavaScript well enough to implement the same logic written in JavaScript. Alternately, you need to learn Java well enough to take that Java code and turn it into a jsp or servlet, get access to Tomcat, and get it working as a servlet or jsp. I assure you, the first option is a lot less work, especially if your experience level is where it appears to be (very beginning of learning this stuff).
Posts
If the second one, which is in Java, does what you need then you need to learn JavaScript well enough to implement the same logic written in JavaScript. Alternately, you need to learn Java well enough to take that Java code and turn it into a jsp or servlet, get access to Tomcat, and get it working as a servlet or jsp. I assure you, the first option is a lot less work, especially if your experience level is where it appears to be (very beginning of learning this stuff).
Either way, i figured it out. Asked one of the developers I work with.
Please close this thread.