I know!! That's why I've been asking for help hahah
Hence "my goal"
All the equations and stuff work perfectly it's just the If-Then statements!
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I know!! That's why I've been asking for help hahah
Hence "my goal"
All the equations and stuff work perfectly it's just the If-Then statements!
There is nothing wrong with that code. I just ran it on my computer and got the following result:
And then I ran it with positive values:Enter the loan amount: -100000
Enter the rate: 500
Enter the number of years: 5
ALL NUMERICAL VALUES MUST BE POSITIVE!
Enter the loan amount: 10000
Enter the rate: 500
Enter the number of years: 5
The monthly payment is: $4,166.67
4166.66667016393
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
You just said that code could not create what I wanted and could you maybe screen shot it? Are you sure you didn't change it because this is exactly what I got after saving and reopening netbeans.
egfsdfgsdfb.PNG
No, I said the new code could not possibly create what you posted in the screen shot of your output.
Simply looking at the code, there is no possible way "ALL NUMERICAL VALUES MUST BE POSITIVE!" can be printed before you are done accepting all the user input. I'm not saying the new code is wrong, I'm saying your output (given the new code you posted last) is physically impossible to occur.
This is the code you are running, correct (formatting might be a bit different due to my auto-formatter, but formatting would not effect execution in any way):
import java.text.NumberFormat; import java.util.Scanner; /** * @author Akira */ public class MortgageCalculation2a { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); double loanAmount; double interestRate; double numberYears; double months; double monthlyPayment; System.out.print("Enter the loan amount: "); loanAmount = Double.parseDouble(in.nextLine()); System.out.print("Enter the rate: "); interestRate = Double.parseDouble(in.nextLine()); System.out.print("Enter the number of years: "); numberYears = Double.parseDouble(in.nextLine()); months = numberYears * 12; if ((loanAmount < 0) || (interestRate < 0) || (numberYears < 0)) { System.out.println("ALL NUMERICAL VALUES MUST BE POSITIVE!"); } else { interestRate = interestRate / 100 / 12; monthlyPayment = (interestRate * loanAmount * (Math.pow(1 + interestRate, months))) / (Math.pow(1 + interestRate, months) - 1); NumberFormat defaultFormat = NumberFormat.getCurrencyInstance(); System.out.println("The monthly payment is: " + defaultFormat.format(monthlyPayment)); System.out.println(monthlyPayment = (interestRate * loanAmount * (Math.pow(1 + interestRate, months))) / (Math.pow(1 + interestRate, months) - 1)); } } }
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
yes.
If that code is impossible what's the code you used to get that answer?!
Ok, then netbeans must be the problem.
Do you know how to compile and run from the command prompt?
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
Nope can you show me how?
EDIT: but that doesn't help me with the code will it? also, I have to turn it in working on netbeans sooo....
Ok, assuming that your MortgageCalculation2a class is in the mortgagecalculation2a package, do the following:
Locate the MortgageCalculation2a.java class in your file system (assuming windows explorer). Open this file with notepad and make sure it is the correct code. Once you've made sure of that, SHIFT+RIGHT-CLICK anywhere in the folder and go to: "Open command window here". Then, do the following in the command window:
1. Type: javac MortgageCalculation2a.java
2. Wait for that to finish (it may take a minute or two). The .class file should now appear in the same directory as the java file.
3. Type: java -cp .. mortgagecalculation2a.MortgageCalculation2a
And there you go, it should execute your program in the command window (it works the same as the console in netbeans).
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
it says javac is unrecognizable...should I just give up?
Um, I suppose you could close Netbeans, try to find the .class file Netbeans created and delete it in your file system, start up Netbeans again, recompile your file, and attempt to run it again.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
So this code works perfectly for you and it just seems to not want to work on netbeans?
The code works perfectly for me, both in my IDE and in the command line. My guess is Netbeans has either cached your old file and is running that, or your old file still exists somewhere and it is running it.
NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:
When asking for help, please follow these guidelines to receive better and more prompt help:
1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
2. Give full details of errors and provide us with as much information about the situation as possible.
3. Give us an example of what the output should look like when done correctly.
Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/
I guess netbeans is broken then...I created a new file, renamed it, did everything I think I could and it's still not doing what you said you got...
--- Update ---
SMH. I guess the file was completely messed up and I just compied and pasted the code in a new project and it worked!! thank you so much seriously