JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

android.gf, somjit: That's enough now. Keep this strictly to the Java question.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not familiar with the rules of the game, so I can't comment on the logic, but the overall style looks OK to me.
Maybe you can generalise that code for any directiopn by passing in a couple of variables to define the direction (delta-row and delta-col)? So instead of isEast you could have something like

isAnyDirection((Piece color, int row, int col, int dRow, int dCol){ 
    if(board[row + dRow][col + dCol] ... etc

Then you could call it for East by passing 0,1 for the deltas, etc
Just a thought...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no real alternative to writing that code. Yu may be able to avoid repeating code for each direction by putting that code into a method you can call repeatedly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should take 5 minutes to read this Oracle tutorial (on internal frames and how to use them) before doing anything else...
http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds like you may be printing your stack elements (ie your class with a data item and the pointer to the next elements)? If so you need to provide a toString method for that class, in which you could return something like "List element: " + theDataItem. The string concatemation will automatically call the data item's toString method for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If that's it then please mark this "solved" for our knowledge base.
Thanks
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So step 1, 2, 3(for worst case) and 7 will occur once

No, that's completely wrong - see below

System.currentTimeMillis() returns the current time in milliseconds.
But time complexity is more theoretical than that. Just timing algorithms won't tell you that unless you run many very very large test cases.

You have to examine the code and how it scales up with large data values to determine the time complexity.
Eg, with your example the outer loop will be executed n times. The inner loop will be executed on average n/2 times for each time the outer loop executes. So the code in the inner loop will be executed n*n/2 times - that's O(n^2).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Show some initiative and get on and do some work.

Do some research to fill in any gaps in your knowledge (use the internet). Write and test both implementations. Compare their speeds...

If your tutor gave you this assignment then obviously (s)he expects it to stretch you, but (s)he also expects that you should be able to do it.

If you get stuck you can come back here, explain what you have done so far, and clarify exactly what help you need.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I assume your tour[] array just contains the city numbers in the right order, yes?

so the first line to draw is from (the x,y coords of the city identified in tour[0]) to (the x,y coords of the city identified in tour[1]). The second line is from (... tour[1]) to (... tour[2]) etc ... I'm sure you can see the pattern there and how to code that loop?

ps please don't call me "sir"
!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a good start! At least we don't have to striggle with basic Swing concepts!
It looked to me like the weight array holds the distance/cost bewteen each pair of cities, yes? (It's size is n^2). I was looking for some data that holds an x and a y coordinate for each city (size 2*n). You need that to know where to draw each city because your paint routine needs to look something like this (pseudocode):

for each city
   draw a small box (or circle etc) at the x,y coordinates of the city
for each step in the tour
   draw a line from (x,y coords of the city at the start of this step) to (x,y coords of the city at the destination of this step)
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you understand what that code does? Have you been able to use it to draw some ovals or anything else? Do you have any data that defines the position/location of each Node?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java is case-sensitive. string and String are not the same. String is a class name and is spelled with a capital S

Madiya122 commented: Thanks for pointing out. Really appreciate it. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you delete an entry (i) then the next entry will become the new entry (i) so you will need to look at that next time round the loop, so you will need to reset that loop variable back one. YOu may find deleteing (k) has simpler side effects than deleting (j) for that reason.
Gotta go now.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I assume HighArray is some kind of ArrayList-like object, so all you need is around line 18 to delete the duplicate you just found. Remember that you will need to update k to allow for that deletion otherwize you won't detect consecutive duplicates.

ps line 12 etc is redundant because k starts > j and just gets bigger!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

They're simple literals. Just like the "h", "o", "u" etc at the start of the string. Anythingthat's not part of a "format specifier" is"fixed text" (ie a literal).
See the API doc for the Formatter class for complete detailed descriptions of all the format string options.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's right.
Similarly, rand.nextInt(25) will give you random ints in the range 0-24 inclusive.
Think of the parameter as defining how many different values it will return.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your random numbers are in the range 0-12 so your first loop will never be able to process 14 letters, but it keeps on trying...

Ps. Your second loop will never select Z, for the same reason. It seems you have mistaken the contract for nextInt - review the API doc ;)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's in this code, yes?

 while (re.next()){
Student myStudent = new Student();
myStudent.setStudentNumber(re.getString("studentNo"));
mayaman = myStudent.getStudentNumber();
bringMe+=mayaman;
System.out.println("sana: "+ myStudent.getStudentName());
}

You create a new Student, set & get its sudentNumber, then get the studentName. There's nowhere you set the name, so it's null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(Unknown Source)
at app.SearchByKey.SearchStudentNumber.SearchStudentRecordReader(SearchStudentNumber.java:38)

That's not a null reference. It's an attempt to get a char from a String that doesn't have enough characters in it. Specifically you are trying to acccess the second character (index number 1, the indexs are zero-based) when there is only one or zero characters in the String. That's because count has become greater than (length -1) in youyr loop.
Look at your loop termination condition on line 37. You use <=. Think about it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's trivial - the only difference is in the way you connect - just see the link in my previous post.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Never NEVER NEVER do this when writing new code:

} catch (Exception e) {
}

If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks like some kind of server configuration problem???
But why are you running in server mode at all if you know the database is strictly local to your java application? Maybe you should be simply running Derby in embedded mode to avoid configuration and access problems?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 8,9,10 are redundant - a single Education object contains values for degree, major and research, so all you need is a single instance of Education - let's call that variable "education" for the moment, and assume you initialise it with a complete instance of each Faculty's Education.
Now on line 51 you want to get the degree info from that Education.
No problem, the Education class has a suitable method, so you can just use that...
education.getDegree()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The java classes and other resources just go into a jar file. For the databases maybe you could use System.getProperty to get the user's home directory and place the databases in a new directory inside the user directory - that should work on any OS. (You can also get a suitable temp directory via System.getProperty, should you need temp files at runtime)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK! Looks like your button had one or more blanks as its text.
Please amrk this "solved" for our database.
Thanks
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That all looks sensible. In general you need to test for null first, then if it's not null you can test for an empty String - if you want to treat a blank string as being empty, then use trim() first.
getText returns a String, so the toString() is not needed.

if (btn[].getText() == null || btn[i].getText.trim().length() == 0) ...

It looks like the button text is something else, or you are in some context where that code isn't being executed. Try printing the text and the length of the text to see exactly what you've got.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. I hoped you found a new idea there. :(

So the best answer we have is "you can't change the text field in a JOptionPane.showInputDialog, so you will have to create a custom dialog and use a JFornattedTextField". For examples just Google "custom JDialog"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

mKorbel: Hi. What's the easiest way you know to use a JFormattedTextField for the input in a JOptionPane InputDialog?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's hard to see how you could get a divide by zero when k starts at 2 and goes up...
try putting some print statenents into that loop to show the values of randomNumber and k so you can see what's happening.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes.

String's format method uses java.util.Formatter format specs (based on C's printf) to format data into strings with specified padding, decimal places etc etc etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a nice demo of using a panel in a standard dialog. Thank you.

ps

 String password = new String(pf.getPassword());
 if (password.equals("admin")) {
   test = true;
 } else {
   test = false;
 }

OR just

String password = pf.getPassword();
test = password.equals("admin");
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Arrays.toString takes a whole array in one go and converts it to a single string so you can print it without needing a loop. So instead of

for(int i = 0; i < phrase.length; i++)
{
   System.out.print(phrase[i]);
}

you can just have

System.out.print(Arrays.toString(phrase));

Your latest code is an odd cross between the two, that isn't valid either way.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The fully-qualified name of that class is java.util.Arrays so either use the fully qualified name, OR (and this is what people usually do) import it at the beginning of your program just like you did with ArrayList or Scanner
import java.util.Arrays;

ps all the java.lang classes (eg String) are automatically imported, no need for you to import those.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't need any kind of loop for this. Just declare the counter in the class and initialise it to zero. In your actionPerformed add 1 to it, then test to see if it's reached 6 yet.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All you need is a counter in your DisplayButtonMessage class that you can increment inside the actionPerformed until it reaches 6. You need to declare it in the class so its value will persist between the sucessive calls to actionPerformed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

getScaledInstance - just pass it the desired width/height and a scaling method (use SCALE_DEFAULT if yo don't know). It returns a new Image that is the size you requested.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

On lines 34-46 you prompt for first and second number, even if the user's menu choice was not a calculation (1,2,3 or 4)
If the user's choice was 5 your program exits properly after prompting for those two values.
You may want to make prompting for 1st and 2nd number dependent on the menu choice being 1-4 ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Means what it says... the compiler can see that it's possible to reach a statement where you use those variables before you have given them a value.
Easiest thing is to initialise them when you declare them, eg
int i = 0;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

3 errors:
First is self-explanatory
while(i...
i is defined inside the while loop's {}, so it's not accessible outside those {}. Define it before starting the loop.
Ditto result - defined inside the loop so not accessible outside it. Define it before starting the loop

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's great! Please consider marking this thread as "solved" so people will know there is an answer here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, exactly that. It's really nice.
OK, it's not necessary, but if I were marking this as an assignment I would give a whole heap of bonus points for doing that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Collection interface is documented in the API doc, so you can read the definitions of methods that it includes. What it gives you is the capability to use your ResizingCircularArray just like you can use ArrayList or LinkedList etc as in
Collection<String> myData = new ArrayList<>();
(etc)
change to
Collection<String> myData = new ResizingCircularArray<>{};
... and the rest of the code will work without any further changes

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Iterable would be a good thing so you can use the enhanced for/each loop with your data structure. For the absolute pinnacle of professionalism implement the whole Collection interface.
Frankly I think your code is very good.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

readLine returns a null when you reach end of file, so you loop reading lines until you get a null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just use readLine inside a simple loop to read all the lines and append them to your edit buffer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You only get one == on each run of the inner loop because that's the special case where j happens to be the same as i so you are comparing an array element with itself. Ie if j==i then array[i] == array[j]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

== means "refers to exactly the same object (same address in memory)"
equals(...) usually means "may be a different object, but the two objects have equivalent values, so I will treat them as equal"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe its because you are (or are not) using anti-aliasing???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you setFont for your Graphics befroe drawing the text?