Join 150,356 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,883 people online right now. Registration is fast and FREE... Join Now!
Alright I just started this whole Java thing, and my book likes to say "don't worry about this now, we'll cover it later" and it's making me go crosseyed. I saw the topics about the Mortgage problem, but they use the javax.swing to get the input info, and we haven't learned that yet and I'm pretty sure my Prof would wonder how I know it lol, so here's my problem:
User needs to input principle amount, interest rate, and period of loan. Output should include monthly payment, total interest due, and total loan amount to be paid. So far I'm just working on getting the monthly payment:
CODE
import java.util.Scanner;
public class SerafinMortgage { public static void main(String[] args) { final int MONTH_IN_YEAR = 12;
// Display the Result System.out.println("Loan Amount is $" + principle); System.out.println("Monthly Interest Rate is " + finalInterest + "%"); System.out.println("Loan Period (years) is " + loanPeriod);
System.out.println("\n"); System.out.println("Monthly Payment is $ " + monthlyPayment); } }
As I compile it I get about 13 error messages all of which are similar: incompatible types, operator cannot be applied...
I don't understand why I put the values I did double principle = 100000, double interestRate = 6...and so on (it's what my book and the other forum discussing this did).
I'm so lost and my professor is a dousche and I can't get ahold of him! I'm not looking for someone to just post the answer with the correct code, I'm trying to figure out what to do
Help? //please
This post has been edited by iNaStY v3: 4 Feb, 2008 - 09:34 AM
Alright I just started this whole Java thing, and my book likes to say "don't worry about this now, we'll cover it later" and it's making me go crosseyed. I saw the topics about the Mortgage problem, but they use the javax.swing to get the input info, and we haven't learned that yet and I'm pretty sure my Prof would wonder how I know it lol, so here's my problem:
User needs to input principle amount, interest rate, and period of loan. Output should include monthly payment, total interest due, and total loan amount to be paid. So far I'm just working on getting the monthly payment:
CODE
import java.util.Scanner;
public class Mortgage { public static void main(String[] args) { final int MONTH_IN_YEAR = 12;
// Display the Result System.out.println("Loan Amount is $" + principle); System.out.println("Monthly Interest Rate is " + finalInterest + "%"); System.out.println("Loan Period (years) is " + loanPeriod);
System.out.println("\n"); System.out.println("Monthly Payment is $ " + monthlyPayment); } }
As I compile it I get about 13 error messages all of which are similar: incompatible types, operator cannot be applied...
I don't understand why I put the values I did double principle = 100000, double interestRate = 6...and so on (it's what my book and the other forum discussing this did).
I'm so lost and my professor is a dousche and I can't get ahold of him! I'm not looking for someone to just post the answer with the correct code, I'm trying to figure out what to do
Help? //please
I am pretty new to Java however I believe that you are only allowed to have one variable with the name principle. A neat little trick I learned from LibertyBasic is that you can have a variable called "word" as an int or something and then "word$" as another variable type, prefferably String (in Liberty the $ is the only way to use strings )
However I don't think that is very professional but I'm 15 and doing this for fun so I don't have to be professional
This post has been edited by DillonSalsman: 4 Feb, 2008 - 09:20 AM
no need to quote someone for the first reply in a thread.
but yes, just come up with a different name.
note: since your doing it for school adding a symbol won't get you the grade, the profs are sometimes real particular about having a name that is descriptive so that a) it can be graded and you follow habits that will pay off the in future
lol and what symbol did I add? The name of the project SerafinMortgage, Serafin is my last name (he told us to do this)
here maybe this will help you help me, these are my error messages:
operator / cannot be applied to java.lang.String, int operator + cannot be applied to int, <any> operator * cannot be applied to double, <nulltype> incomptible types found : int require: java.lang.String
12 errors total
This post has been edited by iNaStY v3: 4 Feb, 2008 - 09:42 AM
Well I guess I'm confused as to whether or not I even need the
String principle
if I change the name or not. I know I need the
double principle
because it defines the values that can be stored inside the variable principle. So I'm unsure about that, and why I'm putting 100000 as the value, as well as double interestRate = 6; and int loanPeriod = 30;
I don't understand why I'm using those values.
Also, when I remove my String values that I have already named as Double or int it removes two error messages, but I'm still getting all of the operator error messages and the incompatible types error messages
principle is defined as 100000, but as soon as the program starts thats over-written with a user input. normally you just want to declare to zero, or without a number so you don't get confused... like you just did.
also you declare a String finalInterest, but then the second thing pulled from user input is a double, so you need to match those up. Declare finalInterest as a double earlier in your code and remove the string crap.
I'm at the FAC for another 1/2 hour if your close I could show you... otherwise I can get home and test it later tonight and get you a complete answer.
would you mind posting the whole assignment though....
that way i can get a real understanding , not sure why the loan period and interest are hardcoded and the rest is pulled from input.
capty thank you SO much that cleared things up very nicely for me!
here is the original problem:
Lab 1 (Due 2/5): Write a program to calculate a mortgage's monthly payment with the end user interactively entering the loan’s a fixed interest rate, number of years, amount borrowed, and estimated escrow amount. The program will also display the payment value. You will first need to find the appropriate formula. Warning – translating the formula into code is not a simple task. Output the monthly payment amount, the total amount paid over the life of the loan, and the total amount of interest paid over the life of the loan.
here is my new (WORKING ) code:
CODE
import java.util.Scanner;
public class SerafinMortgage { public static void main(String[] args) { final int MONTH_IN_YEAR = 12;
// Display the Result System.out.println("\n"); System.out.println("Monthly Payment is $ " + monthlyPayment); System.out.println("Total Amount Due is $ " + finalPayment); System.out.println("Total Interest Due is $ " + finalInterest); } }
my only question now is how the hell do I get rid of the 13 decimal places in the results? lol that looks ridiculous!!
Also, just for fun, if I wanted to jazz it up a lil with GUI, I know i would use this:
but I can't figure out how to all three of my outputs (monthly payment, total payment, and total interest) in the same dialog box on seperate lines. All I can do is put them in three different dialog boxes or all on one line.
That's just curiosity lol I'm prolly getting wayyy ahead of myself. And if anyone wouldn't mind critiquing my style that would be awesome! I just want to make sure I'm writing things correctly and not over-complicating things. ANY advice/opinions/tips would be greatly appreciated!
But again, thanks a ton for clearing some stuff up for me, cause like you said, I confused the hell out of myself
// God this site rules
This post has been edited by iNaStY v3: 4 Feb, 2008 - 12:40 PM
The only reason I'm using this formula is because I don't know how to write exponents. I thought that it was just (1523) ** 5, 5 being the exponent, but I get error messages.
The formula I want to use (because it's right) is this:
// Display the Result System.out.println("\n"); System.out.println("Monthly Payment is $ " + monthlyPayment); System.out.println("Total Amount Due is $ " + finalPayment); System.out.println("Amount Owed in Interest is $ " + finalInterest); } }
Now will someone PLEASE lol help me so that there isn't 13 decimal places after my output? 2 would be nice lol
I think it has something to do with 'truncate'? What I found on Google looked like this:
CODE
0.499159 * 100.0 // Result is 49.9159 (int) (0.499159 * 100.0) // Result is 49
but first I can't figure out how to put this in my code without getting a million error messages, and secondly I still want 2 decimal places.....
This post has been edited by iNaStY v3: 4 Feb, 2008 - 05:51 PM