Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0

    Default Incompatible types Integer Boolean

    I am trying to write a program to calculate the monthly amount paid for a mortgage and the total amount but i keep getting this errors Attachment 5998

    This is my program:

    import static java.lang.Math.pow;
    import java.io.*;
    import java.util.*;


    class MyInput

    { static private StringTokenizer stok;
    static private BufferedReader br
    = new BufferedReader(new InputStreamReader (System.in));

    public static int readInt()
    { int i = 0;
    try
    { String str = br.readLine();
    StringTokenizer stok = new StringTokenizer (str);
    i = new Integer (stok.nextToken ()).intValue ();
    }
    catch (IOException e)
    { System.out.println(e); }

    return i;
    }

    public static double readDouble()
    { double d = 0;
    try
    { String str = br.readLine();
    stok = new StringTokenizer (str);
    d = new Double (stok.nextToken ()).doubleValue ();
    }
    catch (IOException e) { System.out.println(e); }
    return d;
    }
    }




    public class MortgagePayments{

    public static void main(String[]args)
    {//main menu begins

    double interest_rate;
    int year=0;
    double loan;
    double monthly_payment;
    double total;
    int yearopt1=7;
    int yearopt2=15;
    int yearopt3=30;
    int val;



    System.out.println("Please enter the year: ");
    year=MyInput.readInt();

    System.out.println("Please enter the loan amount: ");
    loan=MyInput.readDouble();

    if(year=yearopt1)
    interest_rate=7.25;

    else if (year=yearopt2)

    interest_rate=8.5;


    else if(year=yearopt3)

    interest_rate=year*9;

    val=year+12;
    monthly_payment=((loan*interest_rate)/(1-(Math.pow(1+interest_rate,val))));
    total=monthly_payment*year*12;

    System.out.println("The montly payment will be: " +monthly_payment);
    System.out.println("The total amount you will pay will be: " +total);

    }//main ends

    }//class ends

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Incompatible types Integer Boolean

    If you want to compare two ints you use ==. With a single = you assing the value.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Why are these types incompatible?
    By ras_oscar in forum New To Java
    Replies: 4
    Last Post: 10-07-2013, 12:08 PM
  2. incompatible types
    By mephistochen in forum New To Java
    Replies: 14
    Last Post: 05-20-2013, 12:40 PM
  3. Replies: 1
    Last Post: 07-12-2012, 11:17 PM
  4. incompatible types found object expect integer
    By bflhr673 in forum New To Java
    Replies: 3
    Last Post: 07-24-2010, 04:10 PM
  5. Replies: 6
    Last Post: 10-08-2008, 09:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •