JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Place an ex.printStackTrace() in EVERY catch clause.
Never ever ever do what you do in lines 45/46 if you want any chance finding bugs.
When posting here always post the full text of the exception stackTrace, and make sure we have a listing of the code lines it refers to.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In order to be able to sort instances of some class (such as Scores) you need to be able the compare two Scores to see what order to sort them in. Scores is a class you define, so there's no sensible guess that Java can make about what order you want. To fix this you must implement the Comparable interface in your class. This consists of only 1 method to compare two Scores and say which sorts first. Have a look at this:
http://onjava.com/pub/a/onjava/2003/03/12/java_comp.html

Kerrai commented: Greatly helpful post +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Threads and Swing

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about a HashMap<String, ArrayList<String>> ?
Hashmap has photo name as key, list of keywords as value.
Get list of keywords for a photo is trivial, list of photos for a keyword is easy using contains(keyword) on each of the keyword lists in a loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

at usefulapps.MortgageCalculatorGUI.<init>(MortgageCalculatorGUI.java:41)
at usefulapps.MortgageCalculator4.<init>(MortgageCalculator4.java:20)
at usefulapps.MortgageCalculatorGUI.<init>(MortgageCalculatorGUI.java:41)
at usefulapps.MortgageCalculator4.<init>(MortgageCalculator4.java:20)

Looks like MortgageCalculatorGUI's constructor is creating a new instance of MortgageCalculator4, which is what I would expect, BUT the constructor for MortgageCalculator4 seems to try to create a new instance of MortgageCalculatorGUI, which is absolutely wrong, and causes an infinite loop.
MortgageCalculator4 should have NO hard-wired references to any poart of the GUI.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can you suggest some smaller problems that help me to be familiar with this class so that i can implement this in my project.

Firstly, that's the right question.

So, create a small graphic image file (use any paint program you like),, maybe 10x10 pixels, with a small block of white, one of black, a bit each of R, G and B. Save it as a bmp, not a jpeg so it says intact when saved.
This test file is small and simple enough for you to be able to check that you are getting the right results.
Now write a simple class with a main method that just reads the file into an Image, pixel grabs it, and prints the RGB values to System.out.
This is as simple to write and test as any pixel app can possibly be. If you find this too much at your current level of expertise, then set aside any thoughts of pixels for the moment and build up your basic Java skills with some simpler programs. If you look in this board you will find lots of students posting problems around learning exercises that you could try for yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hello Bhargavi
Thanks for the feedback - it's good to know that the suggestion was helpful. That particular problem was a very interesting one, and I really wanted to know if the diagnosis was right.
As for your "small problem now", without all the code (including the database) I can't fix that for you; you will have to debug that yourself. As I understand it the selection from the first list to second is working, and the process for going from the second to the third should be exactly the same process. In that case your problem can't be too hard. If you compare the 1->2 case with the 2->3 case they should match up line for line, with just the variable names being changed in a totally predictable way. My guess is you have either (a) something you fixed in the first case that's not fixed in the second or (b) you have a variable name from the first case that hasn't been replaced correctly for the second case.
If you can't see the problem by inspecting teh code as above, you should use print statements to find exactly where its going wrong.
Good luck
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I would like to know what I am doing wrong.

I took a very quick look and nothing jumped out at me.
Exactly what problems are you having, exactly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No time now to read all that code, but it looks like you declare things like intRate and total in the superclass, but then declare them again in the subclass. This means that you have at least 2 versions of these variables floating around, with huge potential for confusion. As a general rule you should never re-declare variables without some very good and well thought out reason.
I would start by deleting every duplicated declaration of any variable, keeping only the one in the highest level class (or the widest scope in the case of re-declaring a variablein a method).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your mortgage class will probably have methods something like:
setTerm(int years), setInterestRate(float rate), setAmount(int dollars) etc etc
and others like:
float[] getMonthlyPayments() // returns an array, one element per month
float getTotalInterest()

So in your GUI you create an instance of that class, then use the set methods, as in
setInterestRate(Float.parseFloat(rateText.getText());
finally, when the user presses the Calc button(s) you can call the get methods to get the values to display in the GUI.

In terms of dependent/independent files/classes, the goal is that the mortgage class should not depend on the GUI - after all the calculation of a mortgage does not depend in any way on how the user happened to enter to data. But the GUI class(es) will depend on the mortgage class to do the calculations for them.
It's a one-way dependency, which is a far better architecture than two-way dependencies because the interactions between the classes are easier to understand and control. It also allows for re-use - for example if you wrote a web-based mortgage system, you could use exactly the same mortgage calculation class without any modifications, only the UI classes would be replaced.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You declared Loan loan inside the if tests, so as soon as you got to the next } they ceased to exist. Just declare Loan loan in the class, but outside any methods. Basically, when you declare a variable it only exists within the {} brackets that immediately surround the declaration.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, sorry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean cannot find symbol, method nextChar()?
If so, check out the API for Scanner - there is no nextChar() method in Scanner (there also isn't a Char() method either)
A char is a single character, and I guess your department names are longer than 1 char, so you probably want to use nextLine()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You already asked the same question in your previous thread. Please do not double-post.
You teacher is being silly. You cannot overload pop() with no parameters, and there is no parameter needed for a pop.
Serena5 already gave you good advice

have two methods: int popInt() and float popFloat()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What I posted was code fragment, not a class. If you read it you will see one line to declare the reader and one line to read from it. The rest is to demo how it works.
I don't believe you will find a shorter solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have to create an instance of one of its concrete subclasses, as in

Loan loan = new PersonalLoan(...) or
loan = new BusinessLoan (...)

You can use the same Loan variable for either type because they are both a "kind of" Loan.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you referring to the fact that Console input does not work in Eclipse (or other industrial-grade IDE's)? If so, you can use a reader on System.in like this:

try {
         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
         System.out.print("Type name: ");
         String name = reader.readLine();
         System.out.println("Hello " + name);
      } catch (IOException e) {
         e.printStackTrace();
      }
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Code would still work without "private", but real systems made up of many many classes would become impossible to maintain.
The public print method has no parameters, but the private implementation is recursive and needs a Node parameter, so they should be two different methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

19. Because the user of this class doesn't need to know about it, and if they did get access to it they would probably screw up the list.
28. When the return statement is executed
32. This stops execution of the method immediately and returns to the wherever the method was called from. This therefore makes it exit the loop.
57. Because its the recursive implementation for the public print() method. Users should call print(), but how that works is private to this class. If they had access to the print(Node node) method who knows what damage they may do?

NewOrder commented: Thank you for clearing this out for me +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's up to you whether you separate your 2 user interfaces into 2 separate classes. The main thing to do is to extract all the mortgage-related variables and logic into their own class that is independent of any UI, then use that as a service that the UI or UIs can call.
Google MVC (model, view, controller) - you will be doing a simplified version with a model and a UI that combines the view and the controller. Or look at how classes like JTable separate the user interface from the underlying data.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without the current version of all the relevant code there's nothing that I can do here. Also, I'm about to go out, so I'll be offline till tomorrow. Just debug it one step at a time - put loads of print statements into each step of the code until one of them prints out a wrong/unexpected value. Never assume you don't need to print a value because you know what it is - if your understanding of the code was 100% perfect it would work, wouldn't it?
It may be tedious, but it always works. Good luck. J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nice point Norm
Mark thread as solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Mark thread as solved?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, you're trying to print the whole array on line 12, so all you get is the internal pointer to that array. I guess you intended to say System.out.println(wrong1); ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What kind of crap exactly? Code looks sensible to me

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Still looks to me like the output screen is buried deep in the if/elses. Leaving aside the attempt to re-enter a bad score around line 76 (which needs more work), it should look more like

if (testScore < 40) {
   ...
} else {
   if  (testScore < 50) {
      ...
         etc 
            etc 
               etc
         }
      }
   }
}
// show output window - outside all those nested ifs
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Looks like the final display screen is deeply buried in the nested if tests when maybe it needs to be after all those - without proper indentation it's hard to tell

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint:

abstract class Stack
class FloatStack extends Stack
class IntStack extends Stack

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, one is push(int) the other is push (float), unlike your pops which are both pop(). Check Serena5's post again, it's the answer you needed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Separate the mortgage logic & calculations from the user interface. Put them in their own class, with its own variables, and provide public methods that the user interface can call to set the variables and get the calculated mortgage figures.
Now you have 2 classes; put each one in its own file.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Seems odd. Have you tried printing the array values after the update to confirm that they really are what you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is line 2 part of a method? (it should be)

the dreaded serialVersionUID is because the API says any Serializable class should declare a version number so that if serialization changes you will know which version was serialised when you try to de-serialise it. Eclipse is just picking up every low-level warning that a default stand-alone compile may suppress. Just let it put the version variable in and don't worry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have to use an if test in some form or another.
If you really want to use catch/finally to handle it you can throw a new Exception, as in

if (somethingIsWrong) throw new Exception("Something went wrong");

(although some writers think you shouldn't use exceptions for ordinary user errors)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 22 is missing something ;). Just compare it with the other 3 showInputDialog lines and I'm sure you will see it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

sory sir james,but i'm just a new member here so i dont know how to post a new threads

On the main forum page http://www.daniweb.com/forums/forum9.html click where it says "Want to start a new topic discussion? - Click here to start a new thread"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Joss - did you read the last line of my previous post?
Lance - do not hijack other people's threads. Start a new one for your problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think your tests for invalid input should be || not && - ie it's invalid if either criterion is not met. And maybe you should put these tests before the accept/reject tests, so that a gp of 9 and a ts of 200 is shown as invalid rather than pass.
And doubleValue(...) looks a bit incomplete! Have a look at Double.parseDouble(...) in the API.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't forget that you are allowed to press more than 1 button. And that an elevator with no buttons pressed either waits where it is, or returns to the ground floor and waits - it doesn't just "move up and down".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you have misunderstood the purpose of this forum. We are here to help you do your homework, not to do it for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, now I see the whole error stack I can see something very interesting.
I have a theory.
In appSetComboBox_actionPerformed you remove all items from the app combo box.
This changes the state of that combo box, which fires an action event.
Your action event handler for the app combo box is called immediately.
That handler calls getSelectedItem() - which returns null because there are no items (you just removed them all).
You then call toString() on that, and get an NPE.

In other words it's not the removeAllItems() that's giving the NPE, it's the handler for the event that's generated by removing the items.

IF I'm right then you need to test for a null selected item. If it is null you can just return from the handler because there's nothing else for you to do.
Try changing BOTH action event handlers to replace the line like this

String app = this.getAppComboBox().getSelectedItem().toString();

with something like this

Object selectedItem = getAppComboBox().getSelectedItem();
if (selectedItem == null) return;
String app = selectedItem.toString();

ps: No need to call me "Sir", just James will do!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, but don't confuse the variables and the methods. It's not appComboBox() it's just appComboBox - it's a variable not a method.
I want you to try that because:
You want to remove the items from the existing appComboBox, and the obvious syntax to do that is
appComboBox.removeAllItems();
If you use getAppComboBox().removeAllItems();
that creates a new combo box, and has side effects, whiuch MAY be the cause of your problem

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think it would not work for just packagecombobox.removeAllItems(), and it will give error for me because packageComboBox it not a method

I can see no reason why that would not work. Did you try it?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes yes yes, I know that. I asked why you used the first version of the code, not the second version that I showed you. Why do you think I asked you a question? If you don't want to answer it, just tell me and I'll go away.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which values are you testing on lines 33 and 37 ??? ;-)
I didn't type this just for fun. Read those lines again. Think about this question.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which values are you testing on lines 33 and 37 ??? ;-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Small syntax error - you put the count++ OUTSIDE the {} for the while loop, it's before the opening {, so the compiler sees

while(count<=number) count ++; // this is a valid complete while loop
{ // this isn't valid now

what you should have is

while(count<=number)
{
count ++;
etc

ps: you reversed the order of the if tests compared to tong's code - this is inportant.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why do you have

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.getPackageComboBox().removeAllItems();
		this.packageComboBox.addItem("All Package");

and not

String app = this.getAppComboBox().getSelectedItem().toString();
		this.appComboBox.setSelectedItem(app);		
		this.packageComboBox.removeAllItems();
		this.packageComboBox.addItem("All Package");
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is x an instance variable (ie not static)?
If so, every instance of Class1 has its own value for x.
You can do whatever you like with x in one instance of Class1, and this will have no effect on the value of x for any other new instance of Class1 that you create later.
What are you trying to achieve, exactly?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You never answered my post 2 days ago

One last time before I move on to something else...
why are using getAppComboBox() instead of just referring to appComboBox like you do on the next line? It can't be what you told me earlier - "give the list of items for the app combo box" - because the very next thing you do is to remove all the contents anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So this is exactly the same problem that you have (had?) with the first listener?
Do you still have that problem with the first listener?
You seem to have ignored everything I said about that, so I'm not going to say it all again.