9 Replies - 7299 Views - Last Post: 10 May 2007 - 09:31 AM Rate Topic: -----

#1 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

'Unexpected Type' Error

Posted 09 May 2007 - 01:33 PM

Quote

I had this program compiling and doing everything, until I added this to lines 72-74:

if(newBalance<((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))){
(((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))) = newBalance;
}

I am getting an error:

Line 73 unexpected type

Can anyone help me?



//packages imported for class and method use
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
import java.lang.Object;
import java.awt.*;

//class header
public class MortgageCalculator3
{
	//method header
	public static void main(String[] args) throws IOException
	{

		Date currentDate = new Date(); //Date constructor
		DecimalFormat decimalPlaces=new DecimalFormat("	 $###,##0.00\t");//Decimal converter
		DecimalFormat intPlaces=new DecimalFormat("000\t"); //Decimal converter
		DecimalFormat singPlace=new DecimalFormat("0\t"); //Decimal converter
		DecimalFormat interestfmt=new DecimalFormat("0.00%");//decimal converter
		InputStreamReader stdin = new InputStreamReader(System.in);
		BufferedReader infoin = new BufferedReader(stdin);
		String input;
		
		//declaring variables
		int i;
		int j;
		final double principle = 200000;
		//declaring array
		double [] array1 = {.0535, .0550, .0575};
		double [] array2 = {7, 15, 30};
		double [] array3 = {200000, 200000, 200000};
		
		double interestPaid;
		double balancePaid;
		double newBalance;
		//double previousBalance;
		
		

		// Program Header
		System.out.println();
		System.out.println("\t\t\t\tMortage Calculator");
		System.out.println("\t\t\t\tBy Jennifer Prince");
		System.out.println("\t\t\t\tJava Programming");
		System.out.println("\t\t\t\t" + currentDate);
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println("Loan\t\tPrinciple\t\tPercentage Rate\t\tTerm(years)\t\tInstallment\t\tMonthly Mortgage Payment\t\t  Balance\t\t  Interest Paid");
		System.out.println();
		System.out.println();
		
		//The first time through, the previous balance is the beginning balance of $200,000
		//previousBalance = principle;
		//loop through calculations and increment the counter by one each time
		for(i=0; i<359; i++){
			System.out.println();
			for(j=0; j<3;j++){
				
			if(newBalance<((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))){
				(((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))) = newBalance;
			}
				if(i<array2[j]*12){
					interestPaid = ((array1[j]/12)*array3[j]);
					 balancePaid = ((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))-interestPaid);
					 newBalance = array3[j]-balancePaid;
					 System.out.println((j+1)+ "\t" + decimalPlaces.format(principle) + "\t\t" + interestfmt.format(array1[j]) + "\t\t\t\t" 
		 			 	+ singPlace.format(array2[j]) + "\t\tPayment " + intPlaces.format(i + 1) + "\t\t" 
		 			 	+ decimalPlaces.format ((principle*array1[j]/12)/(1-Math.pow(1+array1[j]/12, - array2[j]*12))) 
		 			 	+ "\t\t" + decimalPlaces.format(newBalance) + decimalPlaces.format(interestPaid));
		 			 array3[j] = newBalance;
		 			
		 			 
				}else {
					 System.out.println("Loan" + "\t\t" + (j+1) + "\t\t" + "Paid");
				}
				
				
			}
			

		
 				//test for lines of output by using modulus function
 				if(i % 3 == 0){
 					//prompt user for input
 			 		System.out.println("Do you want to continue? (y/n)");
 			 		//read user input	
 					input = infoin.readLine();
 					//if user input is y, the next 9 lines will show
 					//if user input is n, the program exits
 					if(input.equals("n") || input.equals("N")){
 						break;
 						}
				}
				
		}						
		
	}//close method header
}//close class header 


Is This A Good Question/Topic? 0
  • +

Replies To: 'Unexpected Type' Error

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 01:41 PM

The problem is that you are trying to assign the variable newBalance to an equation. newBalance needs to be on the left side of the equal sign, not the right side.

This is invalid:
 (((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))) = newBalance;


This is the correct way to do it.
newBalance = (((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))));

Was This Post Helpful? 0
  • +
  • -

#3 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 01:54 PM

View Postjayman9, on 9 May, 2007 - 01:41 PM, said:

The problem is that you are trying to assign the variable newBalance to an equation. newBalance needs to be on the left side of the equal sign, not the right side.

This is invalid:
 (((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))) = newBalance;


This is the correct way to do it.
newBalance = (((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))));

Thanks, but now I get this error:

variable newBalance might not have been initialized

Any ideas?[quote]
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 02:04 PM

As well you should get that error. Try initializing your variables when you declare them, it is good programming practice.

double newBalance = 0;


You are trying to use it in this IF statement, but you have never assigned a value to it. As a result you get this type of error.
if(newBalance<((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))))

Was This Post Helpful? 0
  • +
  • -

#5 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 02:15 PM

View Postjayman9, on 9 May, 2007 - 02:04 PM, said:

As well you should get that error. Try initializing your variables when you declare them, it is good programming practice.

double newBalance = 0;


You are trying to use it in this IF statement, but you have never assigned a value to it. As a result you get this type of error.
if(newBalance<((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))))

Thanks, that was a pretty silly mistake. I will remember that one.

Even worse though, it doesn't do what I wanted it to. I wanted it to determine if the newBalance is less than the monthly mortgage payment(the calculations), and if it is, I want it to make the payment equal the newBalance. Does that make sense? No matter where I put this if statement, it doesn't change anything. AAAhhhhh!!![quote]
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 03:29 PM

You need to calculate the newBalance before you use it in the IF statement. Then you will get the results you are expecting.
Was This Post Helpful? 0
  • +
  • -

#7 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 04:33 PM

View Postjayman9, on 9 May, 2007 - 03:29 PM, said:

You need to calculate the newBalance before you use it in the IF statement. Then you will get the results you are expecting.

ok, so I did it like this, and it isn't doing anything for me. What am I doing wrong?

This is a piece of the output I am receiving:

1 $200,000.00 5.35% 7 Payment 083 $2,859.79 $2,847.10 $25.33
2 $200,000.00 5.50% 15 Payment 083 $1,634.17 $127,734.98 $590.24
3 $200,000.00 5.75% 30 Payment 083 $1,167.15 $178,777.54 $858.12

1 $200,000.00 5.35% 7 Payment 084 $2,859.79 - $0.00 $12.69
2 $200,000.00 5.50% 15 Payment 084 $1,634.17 $126,686.26 $585.45
3 $200,000.00 5.75% 30 Payment 084 $1,167.15 $178,467.03 $856.64
[quote]



//packages imported for class and method use
import java.io.*;
import java.util.Date;
import java.text.DecimalFormat;
import java.lang.Object;
import java.awt.*;

//class header
public class MortgageCalculator3
{
	//method header
	public static void main(String[] args) throws IOException
	{

		Date currentDate = new Date(); //Date constructor
		DecimalFormat decimalPlaces=new DecimalFormat("	 $###,##0.00\t");//Decimal converter
		DecimalFormat intPlaces=new DecimalFormat("000\t"); //Decimal converter
		DecimalFormat singPlace=new DecimalFormat("0\t"); //Decimal converter
		DecimalFormat interestfmt=new DecimalFormat("0.00%");//decimal converter
		InputStreamReader stdin = new InputStreamReader(System.in);
		BufferedReader infoin = new BufferedReader(stdin);
		String input;
		
		//declaring variables
		int i;
		int j;
		final double principle = 200000;
		//declaring array
		double [] array1 = {.0535, .0550, .0575};
		double [] array2 = {7, 15, 30};
		double [] array3 = {200000, 200000, 200000};
		
		double interestPaid;
		double balancePaid;
		double newBalance = 0;
		//double previousBalance;
		
		

		// Program Header
		System.out.println();
		System.out.println("\t\t\t\tMortage Calculator");
		System.out.println("\t\t\t\tBy Jennifer Prince");
		System.out.println("\t\t\t\tJava Programming");
		System.out.println("\t\t\t\t" + currentDate);
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println("Loan\t\tPrinciple\t\tPercentage Rate\t\tTerm(years)\t\tInstallment\t\tMonthly Mortgage Payment\t\t  Balance\t\t  Interest Paid");
		System.out.println();
		System.out.println();
		
		//The first time through, the previous balance is the beginning balance of $200,000
		//previousBalance = principle;
		//loop through calculations and increment the counter by one each time
		for(i=0; i<359; i++){
			System.out.println();
			for(j=0; j<3;j++){
				if(newBalance < ((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12))))){
				  newBalance = (((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))));
			}
				if(i<array2[j]*12){
					interestPaid = ((array1[j]/12)*array3[j]);
					 balancePaid = ((principle*array1[j]/12)/(1-Math.pow(1+(array1[j]/12), - (array2[j]*12)))-interestPaid);
					 newBalance = array3[j]-balancePaid;
					 System.out.println((j+1)+ "\t" + decimalPlaces.format(principle) + "\t\t" + interestfmt.format(array1[j]) + "\t\t\t\t" 
		 			 	+ singPlace.format(array2[j]) + "\t\tPayment " + intPlaces.format(i + 1) + "\t\t" 
		 			 	+ decimalPlaces.format ((principle*array1[j]/12)/(1-Math.pow(1+array1[j]/12, - array2[j]*12))) 
		 			 	+ "\t\t" + decimalPlaces.format(newBalance) + decimalPlaces.format(interestPaid));
		 			 array3[j] = newBalance;
		 			
		 			 
				}else {
					 System.out.println("Loan" + "\t\t" + (j+1) + "\t\t" + "Paid");
				}
			}
 				//test for lines of output by using modulus function
 				if(i % 3 == 0){
 					//prompt user for input
 			 		System.out.println("Do you want to continue? (y/n)");
 			 		//read user input	
 					input = infoin.readLine();
 					//if user input is y, the next 9 lines will show
 					//if user input is n, the program exits
 					if(input.equals("n") || input.equals("N")){
 						break;
 						}
				}
				
		}						
		
	}//close method header
}//close class header

Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 05:47 PM

How does that differ from what you should be receiving?
Was This Post Helpful? 0
  • +
  • -

#9 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

Re: 'Unexpected Type' Error

Posted 09 May 2007 - 06:39 PM

View PostAmadeus, on 9 May, 2007 - 05:47 PM, said:

How does that differ from what you should be receiving?

If you will notice, it is giving 0's and it shows the monthly mortgage payment as the normal. It should be less than the normal, as it is the last payment. I wanted the Monthly mortgage payment to show the total of the last payment, and then the balance to be 0.
[code]
Was This Post Helpful? 0
  • +
  • -

#10 princejlynn  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 15-January 07

Re: 'Unexpected Type' Error

Posted 10 May 2007 - 09:31 AM

View Postprincejlynn, on 9 May, 2007 - 06:39 PM, said:

View PostAmadeus, on 9 May, 2007 - 05:47 PM, said:

How does that differ from what you should be receiving?

If you will notice, it is giving 0's and it shows the monthly mortgage payment as the normal. It should be less than the normal, as it is the last payment. I wanted the Monthly mortgage payment to show the total of the last payment, and then the balance to be 0.
[code]

Any suggestions?
[quote]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1