|
-
Jul 4th, 2010, 07:38 PM
#1
Thread Starter
Hyperactive Member
Need Help....2 operator errors
here is my code, what can I do to fix these 2 errors to execute???
2 errors
C:\Program Files\Java\jdk6\bin>javac AmortizationPayment.java
AmortizationPayment.java:49: operator * cannot be applied to int,short[]
double n = 12 * terms; // n is the
number of total payments
^
AmortizationPayment.java:74: operator / cannot be applied to double[],int
i = ((ir / 100) / 12); //conve
rts interest rate to monthly interest rate
Code:
/**********************************************************************
* Program: Mortgage Calculator
* Purpose: Week 2 Individual Assignment
* Programmer: Kyle von Oven
* Class: PRG420
* Instructor: Vince Anderson
* Creation Date: June 20, 2010
*********************************************************************
* Programmer Mod. Date Purpose
Kyle von Oven 6-27-2010
* ------------------ -------------- --------------
*
*
**********************************************************************
* Program Summary: A program written in Java (without a graphical user interface) that will calculate and display the monthly payment amount to fully
amortize a $200,000.00 loan over a 30 year term at 5.75‰ interest.
**********************************************************************/
import java.io.IOException;
import java.text.DecimalFormat;
public class AmortizationPayment
{
public static void main(String[] args) throws IOException
{
// Define variables
double i = 0; // i is the interest rate in decimals
short []terms = {7,15,30}; // years loan is for
double n = 12 * terms; // n is the number of total payments
double Plusone = 0; // For calculation only
double Minusone = 0; // For calculation only
double raised = 0; // For calculation only
double p = 200000; // p is the principal or loan amount
double []ir = {0.0535, 0.055, 0.0575}; // interest rate in percentage
double high = 0; // For calculation only
double low = 0; // For calculation only
double sum = 0; // For calculation only
double m = (p*(i*(Math.pow(1+i,n)))/(Math.pow(1+i,n)-1)); // Mortgage function
double term;
double int_rate;
//This formats the decimals must import java.text.DecimalFormat to use
DecimalFormat df = new DecimalFormat("#,###.00");
DecimalFormat nd = new DecimalFormat("####");
// program information
System.out.println("Week 3 Individual Assignment: SR-mf-0003 Change Request 1");
// Calculations and Printout
i = ((ir / 100) / 12); //converts interest rate to monthly interest rate
n = (12 * term); //converts years into months
Plusone = i+1;
high = Math.pow(Plusone,n);
Minusone = high - 1;
sum = i * (high/Minusone);
m = (p * sum);
//for each term and Rate starting from the first location of each array terms[] and Rates[]
for (int j=0;j<terms.length;j++){
//Calculates the Payment per month to be paid under mortgage scheme One
int_rate=ir[j]; //take value from the array Rates[] to a temporary variable
term=terms[j]; //take value from the array terms[] to a temporary variable
System.out.println("The monthly payment amount to fully amortize a "+ df.format(p) + " loan over a $"+ term + " year term at "+ ir + "% interest is $"+ df.format(m) + ".");
}
double month = 1;
double user_input;
double counter = 1; // Sets counter to 1
while (month <= n)
{
if (counter == 30)
{
System.out.println("Press enter to continue, or Type Q to quit"); // User can continue or quit Program
user_input = (char)System.in.read(); // Read in userInput
if (user_input == 'Q') // Start 2nd if loop
{
break; // Ends program
} // End 2nd if loop
else // Start else condition
{
}
}
double pi = p * i;
double pp = m - pi;
double bal = p - pp;
System.out.println("#" + nd.format(month) + " Interest Paid $" + df.format(pi) + " Principal Paid $" + df.format(pp) + " Remaining Balance $" + df.format(bal));
p = bal;
month = month +1;
counter = counter+1;
}
}
}
Last edited by si_the_geek; Jul 5th, 2010 at 04:09 AM.
Reason: added Code tags
-
Jul 4th, 2010, 08:16 PM
#2
Re: Need Help....2 operator errors
You do know this is a Visual Basic forum, right?
So two notes here:
1. Since terms is an array, would this work in Java:
double n = 12 * terms;
to multiply all array items by 12, since that wont work in VB. You need to multiply each item individually through a For loop. Or is that a syntax error and you meant to say:
double n = 12 * terms[x];
2. Since terms is an integers and n is double, does Java do automatic conversions or do you need to typecast it?
Last edited by baja_yu; Jul 4th, 2010 at 08:23 PM.
-
Jul 5th, 2010, 04:10 AM
#3
Re: Need Help....2 operator errors
Duplicate threads merged - please post each question (or variation of it) only once.
-
Jul 5th, 2010, 04:33 AM
#4
Re: Need Help....2 operator errors
 Originally Posted by baja_yu
Since terms is an integers and n is double, does Java do automatic conversions or do you need to typecast it?
Yes it does. As long as it's a widening conversion
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|