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.

Page 2 of 2 FirstFirst 12
Results 26 to 38 of 38

Thread: If Then Statement Question!

  1. #26
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    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!

  2. #27
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    There is nothing wrong with that code. I just ran it on my computer and got the following result:
    Enter the loan amount: -100000
    Enter the rate: 500
    Enter the number of years: 5
    ALL NUMERICAL VALUES MUST BE POSITIVE!
    And then I ran it with positive values:
    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/

  3. #28
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    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

  4. #29
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    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/

  5. #30
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    yes.
    If that code is impossible what's the code you used to get that answer?!

  6. #31
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    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/

  7. #32
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    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....

  8. #33
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    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/

  9. #34
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    it says javac is unrecognizable...should I just give up?

  10. #35
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    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/

  11. #36
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    So this code works perfectly for you and it just seems to not want to work on netbeans?

  12. #37
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,657
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: If Then Statement Question!

    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/

  13. #38
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: If Then Statement Question!

    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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 03:19 PM
  2. if statement syntax question
    By lanmonster in forum Java Theory & Questions
    Replies: 2
    Last Post: January 27th, 2013, 02:29 PM
  3. Question about IF Statement
    By Brocco767 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 3rd, 2012, 02:21 PM
  4. Question about else statement
    By jean28 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 23rd, 2012, 11:52 PM
  5. [SOLVED] Switch statement question
    By shikh_albelad in forum Loops & Control Statements
    Replies: 5
    Last Post: May 31st, 2009, 05:13 AM