I know I have done something wrong here, but can't figure out how to make my arrays work. I need to have the radio buttons calculate the mortgage with the arrays, but I'm so lost! Any help making this work is appreciated. I do not want someone to do the work for me, but some help on where to go from here would be nice.
It would help us to help you if you could describe what exactly isn't working, or where you are confused. 150 lines of code is an awful lot to ask someone to review with nothing more than "it doesn't work".
Does it compile?
Does it run?
Does it crash?
Does it give the wrong output? If so, what does it give, and what do you expect?
The easier you make it for someone to help you, the faster and better that help will be. So, can you please elaborate?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Apr 27, 2011
Sorry, I'm new here and just getting the hang of this site. It will not compile but mostly because I don't have the calculations correct. the compile error is because I have mortgage = principal*(monthlyInterest....etc. but do not have the mortgage line. I do not have the mortgage line because I am not sure how to input the arrays into the program for the calculations to work. I know i need to put something to the effect of
But to be honest, I am having a real hard time figuring out how to add the array itself. Again, i do not want someone to do the work, just to point me in the right direction.
The idea behind error messages is that they provide information about the problem. So when you get an error message, you should read it. And if you want to ask somebody else about the error message, you should tell them what it says. (Tell them exactly what it says, too. Not a vague paraphrase of the message. Copying and pasting is best if you're going to tell somebody on a forum.)
It's also important to know which line of code the error message referred to. So you should tell the other people that as well.
The phrase "add the array itself" is ambiguous; it is difficult to determine what you want to do based on that.
I do have one suggestion. Write a program that does the calculations with the data and data structures that you want your real program to use, but do not put in any kind of user interface. If you're confused by how to "make arrays work", then I suggest you get the calculation part of your program working, even if just with fake data that you enter into your program source code, before you attempt to have it run with a GUI and buttons and so forth.
You can use System.out.println() to show you how calculations are proceeding, and even what values are at different points. You can have statements that display the values you use to do the calculations, and then a statement that says "user would press button here", and then invoke the methods that do the calculations, etc.
If you boil it down to that, then perhaps either your question or our answer can get more specific.
I think you are rather close... Your compiler error can be fixed by declaring mortgage as a double. However, you will still not get the proper payment.
I don't think you need to add the buttons to an array. What I think you need is a method like 'getInterestRate()' to determine which button is currently selected (if any). Have that method return a float. Then you don't need your interestArray array at all. I would call that right before your "if(principal>0)" line, and use it to set your monthlyInterest value.
Have you got that app working from the command line, without any sort of GUI? You ought to separate the "model", which works out the mortgage, from the "view" which displays it. When it is working at the command line, then you can add it to a GUI with only minor changes. I suspect you are trying to do too much all at once. You ought to code in tiny bits. Write 5 lines, then compile the whole thing and run it. then write another 5 lines. That reduces the scope you have to scour through looking for errors.
You are soon going to find that the common system of having the Frame implement ActionListener is poor design, even though you see it in many books. Add a few more buttons and watch the actionPerformed method enlarge and become un-maintainable.