12 Replies - 3684 Views - Last Post: 08 May 2012 - 03:26 PM Rate Topic: -----

#1 mchbgtony  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 28
  • Joined: 27-March 12

The second option does not work correctly

Posted 30 April 2012 - 09:12 PM

When I do the second option of the program I get a [] as the monthly payment and the table does not display correctly. The first option works fine, but the second is not. Here is the code below please help me out with this.
import java.io.*;

import java.text.DecimalFormat; // Import the java.text for formating

import java.lang.Math;           //Import the java math

import javax.swing.JOptionPane; //Import the GUI

import java.awt.*;

public class MCalculator3

 {

     public static void main(String[] args)

     {

       //Declaring Variables

              int numMonths,i,ptr,whichWayInt;

              int numYears=0;

              double loanAmount,monthlyPayment,newloanAmount,currMonthlyInterest,currMonthlyPrincipal;

              double annualInterestRate=0.0;

              double monthInterestRate=0.0;

              String totalLoan, interestLoan,menuSelection,pmtSched,whichWay,termLoan;

              int years[] = {7,15,30};   //Number of years in the loan

              double intRates[]={.0535,.055,.0575};   //Interest rate for the loan

             String sample[] = {"7 year at 5.35%","15 year at 5.5%","30 year at 5.75%"};

              //Set Decimal Formats

              DecimalFormat money = new DecimalFormat("$###,###,###,###.00");

              DecimalFormat percent = new DecimalFormat("#.00%");

         //Start the loop

         do {

                     whichWay=JOptionPane.showInputDialog(null, "How would you like to calculate this mortgage?\n#1 - I want to input the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment.\n#2 - I want to input the amount of the mortgage and then select the term and interest rate from one of the three most popular choices.\n(Enter 0 to quit.)");

                     whichWayInt = Integer.parseInt(whichWay);

                     if (whichWayInt>0) {

                         //User Assigned Variables

                         //Ask for total amount borrowed

                         totalLoan=JOptionPane.showInputDialog(null, "How much money was borrowed?");

                         loanAmount = Double.parseDouble(totalLoan);

                         switch (whichWayInt) {

                             case 1:

                                 //Ask for the number of years for the loan

                                 termLoan=JOptionPane.showInputDialog(null, "For how many years was this loan agreed upon?");

                                 numYears = Integer.parseInt(termLoan);

                                 //Ask for the annual interst rate for the loan

                                 interestLoan=JOptionPane.showInputDialog(null, "What was the ANNUAL interest rate of\nthe loan in decimal form  (5.75% = .0575) : ");

                                 annualInterestRate = Double.parseDouble(interestLoan);

                         break;

                         case 2:

         String option = (String)JOptionPane.showInputDialog(null,"Which loan option?","Options",JOptionPane.QUESTION_MESSAGE,null,sample,sample[sample.length-1]);

 }

                 monthInterestRate=annualInterestRate/12;  //The monthly interest rate of the loan

                 numMonths = numYears*12;                    //Number of months the loan covers

                 monthlyPayment=loanAmount*(monthInterestRate/(1-(Math.pow((1+monthInterestRate),0-numMonths))));    //The monthly payment for the loan

                 //Output Monthly Payment

                 JOptionPane.showMessageDialog(null,"Borrowing " + money.format(loanAmount) + " for " + numYears +" years \nat an annual interest rate of " + percent.format(annualInterestRate) + "\nwill cost you " + money.format(monthlyPayment) + " a month for the life of the loan.\n\nPlease click OK to see the Mortgage schedule.","Thank you for using McBride Financial Services!",JOptionPane.INFORMATION_MESSAGE);

                 //Output Payment Schedule in a GUI - Calculate and display each month's payment until the counter i = the number of months

                 i=0;

                 pmtSched="Month #         ";

                 pmtSched+="Balance                 ";

                 pmtSched+="Interest          ";

                 pmtSched+="Principal\n";

                 do {

                     i++;

                     currMonthlyInterest=loanAmount*monthInterestRate;          //The payment that is applied SOLELY to the interest on the loan

                     currMonthlyPrincipal=monthlyPayment-currMonthlyInterest;    //The payment that is applied to the principal of the loan

                     newloanAmount=loanAmount-currMonthlyPrincipal;            //The remaining balance of the loan at the end of the month

                     pmtSched+=String.valueOf(i)+"                    ";

                     pmtSched+=money.format(loanAmount)+"           ";

                     pmtSched+=money.format(currMonthlyInterest)+"          ";

                     pmtSched+=money.format(currMonthlyPrincipal)+"\n";

                     loanAmount=newloanAmount;

                     if ( i % 27 == 0) {

                         pmtSched+="\n\nMonth #        ";

                         pmtSched+="Balance                 ";

                         pmtSched+="Interest           ";

                         pmtSched+="Principal\n";

                     }

                 } while (i<numMonths);

                 JOptionPane.showMessageDialog(null,new TextArea(pmtSched,30,60),"Your Loan Payment Schedule",JOptionPane.INFORMATION_MESSAGE);
             }

         } while (whichWayInt>0);

         System.exit(0);

     }

 }



Is This A Good Question/Topic? 0
  • +

Replies To: The second option does not work correctly

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: The second option does not work correctly

Posted 01 May 2012 - 08:12 AM

This is one big method. 90% or more of the problems we see here are because rookies don't stop and plan nor block out their code into logical segments.
This article should help you see a way to block out your code by stubbing out the methods and logic, then filling in each method as you research it:
This is the 'Help me with my homework' article you wanted.


So what do you mean by "the second part"? Specifically starting at what line to what line?

Quote

does not display correctly.
In what way? 'Its broke' is vague. What should it display and what does it display?
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7765
  • View blog
  • Posts: 13,131
  • Joined: 19-March 11

Re: The second option does not work correctly

Posted 01 May 2012 - 08:21 AM

Debugging 101:

1. find where it does the wrong thing
2. figure out how that could happen- what state must the program be in for this to happen?
3. figure out how the program got into this state.
4. fix that.

If you ask some questions based on that, you might get more helpful responses.
Was This Post Helpful? 1
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: The second option does not work correctly

Posted 01 May 2012 - 08:25 AM

Screen captures are a wonderful way to show what a program is doing. Annotating them with callouts like "this should be 4" helps a lot and can often help get past language barriers if English is not your primary language.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7765
  • View blog
  • Posts: 13,131
  • Joined: 19-March 11

Re: The second option does not work correctly

Posted 01 May 2012 - 10:36 AM

Down-voting answers from forum leaders who are trying to help you doesn't seem like it could possibly do you any good. Surely this has occurred to you, no?

Now, if you want to keep this topic open, show a bit of effort. Start by characterizing the problem such that an outside observer can understand what your issue is. What is going wrong, under what conditions, and what is it you expect instead?

In other words, you should at least be able to point us to step 1: what is going wrong?

If you're not clear on the concept, read this essay and try again.
Was This Post Helpful? 1
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: The second option does not work correctly

Posted 01 May 2012 - 11:36 AM

View Postjon.kiparsky, on 01 May 2012 - 11:36 AM, said:

In other words, you should at least be able to point us to step 1: what is going wrong?


View Postmchbgtony, on 30 April 2012 - 10:12 PM, said:

The first option works fine, but the second is not. Here is the code


It sounds just like one of the examples of bad questions:

Quote

Statements like:
  • I need it to do x, y, z and I'm having trouble.
  • Its supposed to report boink and glorp but I don't know how to do that.
  • Its not working. Here's my code:
from this article

While the down voting because we didn't just give the OP functioning code is right out of this article.

Judging from the OP's other posts, he has a real chip on his shoulder and likes to attack anyone that doesn't just give him working code.

Seems like more than enough reason to unsubscribe from this thread and place the OP on my person "To risky/juvinile to try to help" list.

This post has been edited by tlhIn`toq: 01 May 2012 - 11:43 AM

Was This Post Helpful? 0
  • +
  • -

#7 mchbgtony  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 28
  • Joined: 27-March 12

Re: The second option does not work correctly

Posted 01 May 2012 - 07:56 PM

View PosttlhIn`toq, on 01 May 2012 - 11:36 AM, said:

View Postjon.kiparsky, on 01 May 2012 - 11:36 AM, said:

In other words, you should at least be able to point us to step 1: what is going wrong?


View Postmchbgtony, on 30 April 2012 - 10:12 PM, said:

The first option works fine, but the second is not. Here is the code


It sounds just like one of the examples of bad questions:

Quote

Statements like:
  • I need it to do x, y, z and I'm having trouble.
  • Its supposed to report boink and glorp but I don't know how to do that.
  • Its not working. Here's my code:
from this article

While the down voting because we didn't just give the OP functioning code is right out of this article.

Judging from the OP's other posts, he has a real chip on his shoulder and likes to attack anyone that doesn't just give him working code.

Seems like more than enough reason to unsubscribe from this thread and place the OP on my person "To risky/juvinile to try to help" list.


I love how you guys are asking me what is wrong and to explain it and I have in the first post that I put up. You quote me on

View Postmchbgtony, on 30 April 2012 - 10:12 PM, said:

The first option works fine, but the second is not. Here is the code

, but then you miss the first line that I post in the topic and question before that. You ask me for what is going wrong and I already have explained it as stated in the first line: When I do the second option of the program I get a [] as the monthly payment and the table does not display correctly.

Basically what I am saying is that the code is there, but not working properly. If you run the program the #1 option choice runs fine and does what the program is supposed to do. The #2 option gives the above problem when it is supposed to have the same results as the #1 option. The only difference is the choice to enter in the different amounts. One asks for the mortgage amount and a selection and the other asks to input all three options: loan amount, rate, & term. So I do not see how you guys could have missed it unless you didn't read it properly. All this time complaining when you did not read it and that would be why I gave the -1 scores. The question you were asking was already answered and you were asking for duplicate information. Just read the whole question and you will know what problem I am having and the solution I was looking for.

If this was my workplace and QA graded this post you would have got points docked off right away for asking for duplicate information/information already provided about the problem. Amazing how many people are blind to certain stuff and do not read fully the question and jump to conclusions so quickly.
Was This Post Helpful? -1
  • +
  • -

#8 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7765
  • View blog
  • Posts: 13,131
  • Joined: 19-March 11

Re: The second option does not work correctly

Posted 01 May 2012 - 08:17 PM

Quote

If this was my workplace and QA graded this post you would have got points docked off right away for asking for duplicate information/information already provided about the problem. Amazing how many people are blind to certain stuff and do not read fully the question and jump to conclusions so quickly.



"Doesn't work" and "doesn't display correctly" are acceptable bug reports in your workplace?

Clearly you've never filed a bug report in your life.


I'm going to leave this topic up, just in case anyone wants to bother with you. I don't.
Was This Post Helpful? 1
  • +
  • -

#9 mchbgtony  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 28
  • Joined: 27-March 12

Re: The second option does not work correctly

Posted 01 May 2012 - 08:22 PM

View Postjon.kiparsky, on 01 May 2012 - 08:17 PM, said:

Quote

If this was my workplace and QA graded this post you would have got points docked off right away for asking for duplicate information/information already provided about the problem. Amazing how many people are blind to certain stuff and do not read fully the question and jump to conclusions so quickly.



"Doesn't work" and "doesn't display correctly" are acceptable bug reports in your workplace?

Clearly you've never filed a bug report in your life.


I'm going to leave this topic up, just in case anyone wants to bother with you. I don't.


Just a question, but did you ever try running the code in a compiler and program to see what I am talking about or did you just look at the code, read the problem, and then answer. If you would run the code in a program (I used textpad)then you would know what I mean by it is not displaying correctly and what is happening. I at least thought that you guys would have done that then just look at the code and question to answer.....
Was This Post Helpful? 0
  • +
  • -

#10 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: The second option does not work correctly

Posted 01 May 2012 - 08:25 PM

The people you are talking to have skills in the Java language. They understand it enough to be able to tell errors without the aid of a compiler.
Was This Post Helpful? 1
  • +
  • -

#11 mchbgtony  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 28
  • Joined: 27-March 12

Re: The second option does not work correctly

Posted 01 May 2012 - 08:31 PM

View PostDimitriV, on 01 May 2012 - 08:25 PM, said:

The people you are talking to have skills in the Java language. They understand it enough to be able to tell errors without the aid of a compiler.


Obviously not. They keep on asking the same questions and if you take the time to run the program you will see what the problem is from the code and why I am asking for help. It will also explain the problem in more depth and what the solution should be. So just by looking at the code, does not solve the problem. Obviously the code looks fine, but when I compile and run the program it does not produce the same result when you choose option(case) 2 as it should on option (case) 1. Instead I get all the same question as to clarify what the problem is when it is right there in front of you.....

I love how at first this was a great site to get help and then over the course of a couple of weeks my expectations are thwarted with all of this.
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,843
  • Joined: 02-June 10

Re: The second option does not work correctly

Posted 02 May 2012 - 06:02 AM

View Postmchbgtony, on 01 May 2012 - 08:56 PM, said:

but then you miss the first line that I post in the topic and question before that. You ask me for what is going wrong and I already have explained it as stated in the first line: When I do the second option of the program I get a [] as the monthly payment and the table does not display correctly.


Speaking of missing stuff... You have spent 10 times the amount of time telling us what we missed and defending yourself and telling us what we needed to do to help you; than if you had just answered my two simple questions in the very first reply to your post.

All I asked for was some clarification. I think the questions were direct, meaningful, and not at all threatening. For some reason this thread got taken WAY off target. Jon has helpped literally thousands of people here and so have I. He's given up on you because you're more interested in telling us how bad we are at what we do. Not just in this thread but most of your others as well. I'm not far behind him for the same reason. That's not a good sign.

You can either take that information and do something productive with it; like take that big chip on your shoulder and flush it, or not. That's your choice. We are all just photons on a screen to each other. My opinion of you is that of some random person on the internet and as such isn't going to affect you in the least, ruin your job or attitude or keep you up at night. It works the other direction as well. Personally, if you're going to continue in the programming field I'd like to see you get along with your co-workers, the programming community at large (like this forum) and programmers from other vendors: one of them might be me some day.

So I'm going to make one last appeal to simply get some clarification about your issue.

So what do you mean by "the second part"? Specifically starting at what line to what line? Because your code is one big method instead of being broken down into smaller methods with descrete purposes it is harder to debug and harder to even identify portions and purposes. That's why I asked for line numbers. Normally I would have asked "which method?" but you only have one.

Quote

does not display correctly.
In what way? 'Its broke' is vague. What should it display and what does it display? I don't understand what you mean by " I get a [] as the monthly payment ". Are you saying you have looked at this in a debugger and the actual value of the variable is null; or do you mean that when it displays on screen it literally only shows the two square bracket characters?

Screen captures (especially with annotations) do wonders for letting us see exactly what you are seeing. You'd be amazed at how many times a piece of code works differently between two different computers either because of different compilers, UAC settings, 32 v 64 bit OS, and son on. So we'd like to see what it does on YOUR machine since that is where the problem is.
Was This Post Helpful? 2
  • +
  • -

#13 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: The second option does not work correctly

Posted 08 May 2012 - 03:26 PM

Why do you expect everyone to go to the extra trouble of setting up and running your code, rather than you going to the extra trouble of explaining your problem clearly so as to minimize the amount of work you're asking people to do? You seem not to understand that you are asking highly-paid professionals for free advice, which they give because they enjoy helping people. Instead, you're adopting an attitude similar to that of refusing to pay for shoddy consulting work, by downrating people with the quality of whose help you are dissatisfied. News flash: YOU ARE NOT PAYING FOR THE HELP. If you want to fuss at someone, go fuss at your mother for not doing your laundry the way you like it or something. We're not interested.

You have such a gift for chutzpah that one can only conclude that you've had years of practice.

This post has been edited by BobRodes: 08 May 2012 - 03:29 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1