Here is the code taken by right clicking and viewing the Page Source View of the
ID: 3835294 • Letter: H
Question
Here is the code taken by right clicking and viewing the Page Source View of the JavaScript code. I am asked to Port this code to Java.
Is there a method for uploading a file to chegg? Because I can send the full .html file if needed.
<HTML>
Here is the code taken by right clicking and viewing the Page Source View of the JavaScript code. I am asked to Port this code to Java.
Is there a method for uploading a file to chegg? Because I can send the full .html file if needed.
<HTML>
<FORM NAME="loandata"> <TABLE> <TR><TD COLSPAN=3><BIG><B>Enter Loan Information:</B></BIG></TD></TR> <TR> <TD>1)</TD> <TD>Amount of the Loan (Any Currency):</TD> <TD><INPUT TYPE=text NAME=principal SIZE=12 ></TD> </TR> <TR> <TD>2)</TD> <TD>Annual Percentage Rate of Interest:</TD> <TD><INPUT TYPE=text NAME=interest SIZE=12 ></TD> </TR> <TR> <TD>3)</TD> <TD>Repayment Period in Years:</TD> <TD><INPUT TYPE=text NAME=years SIZE=12 ></TD> </TR> <TR><TD COLSPAN=3> <BIG><B> <INPUT TYPE=button VALUE="Compute" > <BR>Payment Information: </B></BIG> </TD></TR> <TR> <TD>4)</TD> <TD>Your Monthly Payment will be:</TD> <TD><INPUT TYPE=text NAME=payment SIZE=12</TD> </TR> <TR> <TD>5)</TD> <TD>Your Total Payment will be:</TD> <TD><INPUT TYPE=text NAME=total SIZE=12</TD> </TR> <TR> <TD>6)</TD> <TD>Your Total Interest Payments will be:</TD> <TD><INPUT TYPE=text NAME=totalinterest SIZE=12</TD> </TR> </TABLE> </FORM> <SCRIPT LANGUAGE="JavaScript"> function calculate() { var principal = document.loandata.principal.value; var interest = document.loandata.interest.value /100 /12; var payments = document.loandata.years.value *12; var x = Math.pow(1 + interest, payments); var monthly = (principal * x * interest)/(x-1); if ((!isNaN(monthly)) && (monthly != Number.POSITIVE_INFINITY) && (monthly != Number.NEGATIVE_INFINITY) ) { document.loandata.payment.value=(monthly); document.loandata.total.value=(monthly * payments); document.loandata.totalinterest.value=((monthly * payments) - principal); } else { document.loandata.payment.value=""; document.loandata.total.value=""; document.loandata.totalinterest.value=""; } } </SCRIPT> </HTML>Explanation / Answer
//EMI Calculator Program in Java
import java.util.*;
public class EmiCalc{
public static void main(String []args)
{
//Scanner class to take user input.
Scanner X = new Scanner(System.in);
double principal, rate, time, emi;
System.out.print("Amount of the Loan (Any Currency): ");
principal = X.nextFloat();
System.out.print("Annual Percentage Rate of Interest: ");
rate = X.nextFloat();
System.out.print("Repayment Period in Years: ");
time = X.nextFloat();
rate=rate/(12*100); /*one month interest*/
time=time*12; /*one month period*/
emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1);
System.out.print("Your Monthly Payment will be:"+emi+" ");
Your Monthly Payment will be:
}
}
//EMI Calculator Program in Java
import java.util.*;
public class EmiCalc{
public static void main(String []args)
{
//Scanner class to take user input.
Scanner X = new Scanner(System.in);
double principal, rate, time, emi;
System.out.print("Enter principal: ");
principal = X.nextFloat();
System.out.print("Enter rate: ");
rate = X.nextFloat();
System.out.print("Enter time in year: ");
time = X.nextFloat();
rate=rate/(12*100); /*one month interest*/
time=time*12; /*one month period*/
emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1);
System.out.print("Your Monthly Payment will be:"+emi+" ");
}
}
//EMI Calculator Program in Java
import java.util.*;
public class EmiCalc{
public static void main(String []args)
{
//Scanner class to take user input.
Scanner X = new Scanner(System.in);
double principal, rate, time, emi;
System.out.print("Amount of the Loan (Any Currency): ");
principal = X.nextFloat();
System.out.print("Annual Percentage Rate of Interest: ");
rate = X.nextFloat();
System.out.print("Repayment Period in Years: ");
time = X.nextFloat();
rate=rate/(12*100); /*one month interest*/
time=time*12; /*one month period*/
emi= (principal*rate*Math.pow(1+rate,time))/(Math.pow(1+rate,time)-1);
System.out.print("Your Monthly Payment will be:"+emi+" ");
Your Monthly Payment will be:
}
}