JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why is your forst question a problem? Your code counts 5, does something random, counts on up to 7 then starts again. How is that different from what you want?


Which value do you want the user to enter?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you certain that the code you posted is the latest version that you are executing (no old .class files hanging around anywhere?).
Are you saying that line 39 outputs a "." but line 44 outputs "null".

If both those are yes then I'm baffled...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

carProcess is an inner class of roundabout01 (ps - please use standard Java capitalisation to make your code easier to understand). It's not declared static, so just like any other instance member of roundabout01 you need an instance of roundabout01 to qualify any reference to carProcess. Read this next:
http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
Unless your instances of carProcess need access to instance variables from roundabout01 then you can probably just declare carProcess as a static class.

So,, moving on...
You have screwed up your run/start solution. You are trying to create a new Thread with your carProcess class. You were right to define a run() method in the class, so change that back again. The start() method is defined in the Thread class. If you want carProcess to be a thread then declare it as extends Thread and it will inherit the necessary method(s). Then when you call start() the method inherited from Thread will start a new Thread, and call your run() method on that new Thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Create two panels, one with the four buttons and a separate panel with the label. Then add both panels to your main panel. This allows you to use different layout managers in each panel to get the exact result you want.

Alternatively, you could use a GridBagLayout to do the whole thing, but the learning curve is quite steep.

mKorbel commented: great minds thinks alike !!!, I didn't saw your answer :-) +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You call it a CryptoSecondaryFrame but actually it's a JPanel - you can't display that unless you add it to a frame or window of some sort.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Add 1 to the value of the variable "i" in the object "v2" in the object "fd1"
That's why choosing good variable names is an essential skill; finding the shortest way to code something isn't.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess this is where you try to slide?

for(int i = 0; i < 84; i++)
{
board[r1][c1].translate(0, -1);
repaint();
}

Here's your problem. That loop is run in your actionPerformed, which means it runs on the Swing Event Dispatch Thread (EDT). Swing is single-threaded, so there will be no other Swing activity (including screen repaints) until your actionPerformed terminates.
When your method returns, Swing then repaints the screen, so you just see your rect in its final position.
The only way to do this kind of animation is with your Timer, so on each call to actionPerformed you do a small translate then return to allow the repaint. That's going to need some status/mode variables that define what's needed each time actionPerformed is called.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think there may be a language problem here. Java does not have "global" variables, so if you use that term you can create ambiguity and confusion. The nearest Java gets is to declare variables as public static in a public class, although some people refer to public instance variables as "global" if their intent is that they should be shared. We, of course, know better and never share non-final variables with anyone :)

The statement "The array will have object scope" simply implies that the variable will be an instance variable, not a static or local variable. (Java Language Specification, section 6.3)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK then, KeyMap is a simple way to go.
If this is going to get any more complicated than just year+file you should think about creating a small class to hold all the info about each journal.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's easier to do in memory after reading the pdfs but before writing your output txt file.
There are many many ways to sort data in Java, but here's one simple way:
As you process the pdfs, put the results into a TreeMap (documentation in the usual places) with the year as the key and the file name as the value. (TreeMaps are kept sorted in key order.)
When all the pds are processed you can write the contents of the KeyMap to the file.

But do you mean sort or search?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The OP's fundamental misunderstanding here is that he has "Parent" objects that seem more-or-less reasonable, but uses doubles in method calls where we would expect a Parent. What is the relationship bewtween a double and a Parent in this application?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Great. Writing them to to text file is just like printing, you just need a PrintStream, eg new PrintStream("myfile.txt") and print to that instead.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Check out the format specs for printf. You can format the Miles column so its always the same width, so all the subsequent columns line up properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can OR the expressions together like this
c1=='a' || c1 == 'b' ...

but if you want a very short version with many tests like that you can use some geeky construct like
"abc".indexOf(c1) >= 0

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can set a compositing rule then draw the second icon with an alpha between 0.0 (totally transparent (invisible)) and 1.0 (not transparent at all (opaque))

Graphics2D g2d = (Graphics2D) g;
// draw image 1
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
g2d.setComposite(composite);
// draw image 2

Have a look at the API doc for AlphaComposite

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How far have you got? Have you been able to use the code above as a base to find the year for a single pdf and just print it out? If not, that would be a good place to start.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

1. If there are two loops just because there are two termination conditions then no, one is enough if you AND the two conditions together:
while (condition1 && condition2) { ...
2. printf formats have an optional width spec that sets the column width (by left-adding with blanks). Documentation is in the usual places.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Who's your daddy!

SimpleTimeZone tz = new SimpleTimeZone(-10*24*60*60*1000,"10 days ago");
TimeZone.setDefault(tz);
System.out.println(new Date());

(dances round PC throwing punches in the air)

Celebrations maybe a bit premature - Max integer value limits offset to about +/- 24 days.
Is this enough?

stultuske commented: Actually that would be P. Brinkhof, but still a very impressive answer/sollution :) +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The getOffset method seems to imply you can get an offset in years, so maybe it's worth a quick try.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I've never tried this but maybe you can create your own TimeZone that has a rawOffset that shifts the date to where you want it to be, then set that custom TimeZone for your program???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's nearly right...
myShapes is declared as an array of Parent objects
public Parent myShape[] = new Parent[10];
and, as already said, z is a double. You can't put a double into an an array of Parents. That array can only hold Parent objects, instances of any sub-classes of Parent, or nulls.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sounds like your code is one big chunk (although I'm guessing, because I haven't seen it). Stage 1 would be to break out the code for creating a new Person into its own method that can be called from anywhere. Ditto Destination. Then you can get the flow of the logic right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

counter=counter+1;
sum=sum+sale[counter];

counter has already been incremented to 1 before you use it the first time. These two statements should be the other way round.
(or you could use ejosiah's version, which does the same thing more compactly or cryptically, depending on your experience level).

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What exactly do you mean by "executables" in a Java context? Java will link to classes in other jars at run time without any difficulty.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm having to fill in a few blanks in the requirements here, but probably:
Think about the real world. You go to a travel agent and they already have a list of destinations. They add you to their customer database, and then you can book a holiday.
So in Run you need a way to create Destinations and People. You'll need to keep a collection (eg ArrayList) for each of those. Then you can create Holiday by linking it to an existing Person and an existing Destination.

dantinkakkar commented: That I got... By my post, I meant that :) +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Generally a bad design to include so many parameters in the constructor. Getters and setters should be invoked over extensively adding input parameters.

I can't let this pass without comment.
When you instantiate any class there is some number of values that must be set for subsequent uses of that instance to be valid. Eg a Book must have an ISBN, title and author. Best practice is to require ALL mandatory non-defaultable values in every non-private constructor. If you don't do this then anyone instantiating this class will need to call one or more setters to create a valid instance, but there is no standard protocol to inform them of this requirement, nor to check that it has been met.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 223 as in
(userCode.equalsIgnoreCase(codesRead.codes[1]) && userQuantity >= 1) {
the first question is which of those is null? Immediately before that line print all those variables to see which is null (personally I suspect userCode)
When you know which it is, you should be able to see why

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

get your self eclipse IDE or intelij and save yourself a lot of stress.

That's one person's opinion. The majority view from the more experienced contributors here is that a full-scale industrial IDE like Eclipse hinders rather than helps a beginner to get a good grounding in Java. Auto correcting and completing code is only useful once you understand what is being auto corrected or completed and why. The IDE itself also has a huge learning curve, which is not a good thing to add to the Java language and API learning curves. Most of us recommend a programmer's editor and command line JDK for the early stages of learning, or maybe a very simple IDE. But, once again, it's all a matter of opinion.
J (Eclipse user)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can't define a method inside another method - that's why the line in red is an error. It's the calls to those methods that need to be in the loop, not the method definitions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"code is to repeat " tells you you need a loop. You can put the code enter a year and display the result into a while loop, and keep looping until the user enters "n".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exception ex contains full details of what went wrong and exactly where it went wrong. Don't ignore it. Use ex.printStackTrace(); to see what it can tell you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I actually do want to iterate through a collectionOfThings and remove or add things?

One word: ListIterator
It's "An iterator for lists that allows the programmer to traverse the list in either direction, modify the list during iteration" Documentation is in the usual places

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In a single-threaded environment you get a ConcurrentModificationException when you modify the Collection that you are iterating over - ie by adding or removing or replacing elements. You don't get an error when you modify the attributes of the individual elements in the Collection (unless they, in turn, cause things to be added to or removed from the collection). In general it's perfectly OK to do this:

for (Thing t : collectionOfThings) {
   t.setX(...
   t.addY(...
}

but not this:

for (Thing t : collectionOfThings) {
   collectionOfThings.add(...
   collectionOfThings.remove(...
}

From what you have posted it looks like you are doing the former, not the latter, so you should not get a ConcurrentModificationException, and there should be no need to use any more complex loops.
Can you post a small runnable version of the code that demonstrates the problem?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Typical roseindia - hardly an expert solution, and more important to this thread, does nothing about the file headers.
riahc3 - have you had a look at the NIO (new I/O) classes in Java 7? They have lots of new stuff for copying files and handing file attributes - even OS-dependent headers.
http://docs.oracle.com/javase/tutorial/essential/io/fileio.html

See especially Files.copy(source, target, COPY_ATTRIBUTES);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... or to keep things really simple - you already have some code to fill in a random HI, so why not a constructor with no arguments that just creates an HI filled with random values? You can always do the one that takes (and validates) values later.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm really sorry about the confusion. There are two ways to approach this and it would be even more confusing if we mixed them up in our advice. Since stultuske has done the most work in this thread then he has the right to make the call - immutable or mutable stultuske? Once that's decided we can get you back on track.
Either way, please spend a little time with my "essay" on arrays a couple of posts ago. That's something you will have to get straight in your own mind a.s.a.p.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi stultuske. Can I suggest a little pause for a design question before going too far down this track? Your suggestions of getters/setters etc are perfectly sensible, but there are strong reasons for making BI immutable (like String or BigDecimal)
http://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html
http://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
and, most relevant here, is that ultimately the code is simpler for immutable objects.

If you want to guide the OP along the getter/setter route then I won't create any more confusion, but I think you should consider this... J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are getting confused between HugeInteger objects and arrays. As you described it a HI object consists of a 4x4 array. The array is part of the internal implementation of the HI class. Inside your HI class you deal with the arrays, but outside it the arrays should be invisible. Outside your HI class you just deal with HI's - you don't know or care whether they are 4x4 arrays or a List of 16 values, or anything else - that's HI's own business.
You are also getting tangled up with the syntax for declaring arrays. One of the great mistakes they made when creating the Java language was to allow two different syntaxes. you can say int[] myArray or int myArray[] The first version is the preferred one - it says "I have an array of ints, and I call it myArray". The second version compiles to the same result, but when you read it it seems to say "I have an array of myArrays, type int".
In your code you say things like HugeInterger array[][] I guess you are thinking that a HI is an array and combine those two ideas in one place, but that's not what it does. Write that same code using the preferred format and its much clearer: HugeInteger[][] array ie you declare a 2-D array of HI's, and you call that "array". That's where your code goes all wrong - each HI is internally a 4x4 array, but you then create …

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is there any code to create a single HugeInteger, to initialise one, or to perform any operations on single HugeIntegers?
The code above defines a HugeInteger as consisting of a 4x4 array of ordinary ints. Is that right?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's the exact error message, and which line does it refer to?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have I missed something? Where is the OP's statement about requiring StringTokenizer?

Anyway, gedas - if this is solved please mark it such and close the thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
String data =  "one two three four five six seven eight nine ten eleven twelve thirteen";

String[] words = data.split("\\s");
for (int i = 2; i<words.length; i+=3) System.out.println(words[i]);

I doubt that you will get much better than 2 simple lines of code...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@James, I think he means "words" by saying tokens, because, as he said, he wants "this" from "i want this". So I guess he wants to extract the third word.

Yes, that's what I assumed. That's why I suggested the approach that I did.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Use split to get he tokens in ann array
Loop thru the array processing every third element (int i = 2; i<array.length; i+=3)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No way I'm downloading a RAR from an unknown source.
Publish your code in this thread, correctly indented, in code tags if you want anyone to read ut.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, that's not valid. You must complete the power expression before doing the modulo

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Isn't this fun!! I tried a "manual" calculation in both double and long variables:

void calcDouble() {
      double c=11, cPow2 = c*c, cPow4 = cPow2*cPow2, 
             cPow8 = cPow4*cPow4,cPow16 = cPow8*cPow8, 
             cPow23 = cPow16*cPow4*cPow2*c;
      System.out.println(cPow23 + " " + cPow23%187);     
   }

   void calcLong() {
      long   c=11, cPow2 = c*c, cPow4 = cPow2*cPow2, 
             cPow8 = cPow4*cPow4,cPow16 = cPow8*cPow8, 
             cPow23 = cPow16*cPow4*cPow2*c;
      System.out.println(cPow23 + " " + cPow23%187);     
   }

Which gave the following results:
8.954302432552372E23 175.0
6839173302027254275 65
neither of which match yours.
Personally I'd put my money on the long manual version.
Any other offers?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can get the time in milliseconds very easily... It's System.getTime... something. If you're using an IDE that gives suggestions, just write "System." and that func will come up. :) Hope this helps.

That's not his problem. He already has code that gets the time in mSec and in a class where he can format it. Maybe you should read threads more carefully before posting

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Calendar.getInstance(); really does get the latest time each time you execute it. but...

You have a machine that clocks at - I don't know but maybe 1GHz give or take a factor of 3? That's 1 million clock cycles per milliSec. That's can be a huge amount of calculation.
Also most ordinary desktop computers get the time from a simple traditional clock circuit that updates every 1/60 sec. So if you keep printing the time in mSec in a loop you will probably see it jumping in increments of 16 mSec. Not a lot you can do about that, other than go out and buy a proper workstation!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have you tried the obvious
SET PLAYCOUNT = PLAYCOUNT + 1
... seems to work in ordinary SQL