BestJewSinceJC 700 Posting Maven

There's a way you can get around that. I think its by putting a backslash before the thing it thinks is an illegal escape character. So try \\d.

BestJewSinceJC 700 Posting Maven

In addition to what he said above, if at all possible, don't post your assignment explanation, just post whatever information is relevant to helping you solve your problem. If you've identified the problematic code, this means telling us what the code is supposed to be doing and telling us what it is doing etc. Reading your entire project description isn't usually necessary.

BestJewSinceJC 700 Posting Maven

Are you trying to update a file that the program is reading from? Or are you trying to change the code of a program that is running and then run it again? (Which would seem quite difficult to me). I don't think either of these are what you're trying to accomplish so please explain.

Also, no shame in being a newbie. Some people consider me a newbie - some consider me an expert - and I'd say I'm somewhere around average. But everyone is learning.

BestJewSinceJC 700 Posting Maven

If that is how your search engine works, all you need to do is search through each String character by character, trying to match the current substring to your current search term. If you don't know any programming languages then you shouldn't be tackling this project, you should be learning the basics. If you do, then try the problem and let us know any specific difficulties you are having, where the problem lies, etc.

BestJewSinceJC 700 Posting Maven

time=(st * st2 - st3 * st4)/2.3;

One obvious mistake is that the above will calculate the area of the yard minus the length of the house, then times the width of the house. What you want to do is the area of the yard minus the area of the house. Then you want to divide that by 2.3, but you still aren't done. Consider your units. Area is in meters, your speed is in m/s, so the final units will be in s. In other words, your time variable will hold the number of seconds to cut the yard... but the problem asks for minutes, not seconds. Do the conversion.

But you still might have problems. After you make those changes, try out your code and if you experience problems, tell us what those problems are.

BestJewSinceJC 700 Posting Maven

just do

if currentMoneyValue < currentLowest{
currentLowest = currentMoneyValue;
}

BestJewSinceJC 700 Posting Maven

I don't see why you need a DecimalFormat, I don't think it is necessary. And what is your question?

BestJewSinceJC 700 Posting Maven

It would help if you declared main correctly, as

public static void

Also, you might want to check that the variable 'i' doesn't go out of scope after the for loop.

BestJewSinceJC 700 Posting Maven

edit: was looking at the wrong code, nevermind

BestJewSinceJC 700 Posting Maven

Ah. I see, thanks

BestJewSinceJC 700 Posting Maven

I understand reusability and coupling (not sure if the OP does or doesn't) but if I was writing this, I'd probably feel that your suggestion is needlessly complex and doesn't offer enough benefit to justify the extra work. Maybe I'm wrong - I'd like to see a seating collection that actually offers some benefit

BestJewSinceJC 700 Posting Maven

The code is the same in a static method as it would be in main. and main is a static method - just look at the method header.

BestJewSinceJC 700 Posting Maven

Nevermind. Eclipse had either imported the wrong class without telling me, or I did it and forgot. Either way, I removed the import and everything is fine.

BestJewSinceJC 700 Posting Maven

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();


Java Sun's site is down right now so I can't check but I'm guessing this is an old method since according to Eclipse, the method doesn't exist anymore. So my question is, are there any other ways to do the same thing?

BestJewSinceJC 700 Posting Maven

Haha I just realized what was going on. At first I read this and I was thinking "how is ezzeral's code going to produce that pound symbol?" because I literally thought you wanted that sign before the amount

BestJewSinceJC 700 Posting Maven

Java and Javascript are not the same thing.

BestJewSinceJC 700 Posting Maven

Lets say you have three sections. Then you would have three arrays of seats, one for each section.

public class Theater{
-seat array here
-second seat array here
-third seat array here

}

BestJewSinceJC 700 Posting Maven

int is 32 bits so it can only hold whatever value 32 bits can hold. And since you want to know if it's positive or negative, there goes one bit that would've gone towards calculation. So calculate that and there's your limit.

BestJewSinceJC 700 Posting Maven

I haven't looked at this guy's code since I responded to this thread a while ago (and judging by what I said in my response, I didn't look too hard then, either) but if I were you, I wouldn't be using his code to learn about Java.

BestJewSinceJC 700 Posting Maven

There are two obvious things you could do as far as how you're thinking about the section of the Seats.

Scenario 1:
Think of the section the seat is in as a property of the seat. (In other words, since the seat will always be in the same section, you could have a variable in the Seat class called section).

Scenario 2:
Think of the section the seat is in as a property of the Theater- not of the seat. In this case, your Theater class could have an array of seats for each section. This is what I would personally do, I think.

Ezzaral commented: Helpful and patient responses in this thread. +18
BestJewSinceJC 700 Posting Maven

Good point. You can also put it under the current project though, right? I seem to remember doing that a few times in the past and having no problems with it.

BestJewSinceJC 700 Posting Maven

What part of your program are you struggling with? How could we tell you how to make do without something if we don't know why you'd be using it to begin with?

BestJewSinceJC 700 Posting Maven

If you want examples consult Java Sun's tutorials on Swing. They have plenty.

BestJewSinceJC 700 Posting Maven

well, somebody might know something I don't, but you're unlikely to get much help without posting code.

BestJewSinceJC 700 Posting Maven

What do you need the collections framework for?

BestJewSinceJC 700 Posting Maven

Post your code (the part that is relevant to your question). http://java.sun.com/docs/books/tutorial/networking/sockets/readingWriting.html

Also, take a look at that example, particularly the part where the PrintWriter and BufferedReader objects are created.

BestJewSinceJC 700 Posting Maven

For one, you don't have a main method (that you showed), so you never constructed a PermutationGenerator object and int[] result = new int[length]; has no effect since it is never called.

Secondly, if you wanted to put the stuff from the result array into the choices ArrayList, it would look like (pseudocode)

for each element in result
add the element from result to the choices arraylist

BestJewSinceJC 700 Posting Maven

if (above40)
reject cuz you're too old


There you go.

BestJewSinceJC 700 Posting Maven

if you just say

imgIcon = new ImageIcon("jhtp3.gif");

it's probably going to assume that jhtp3.gif is located somewhere under your current project. So download it and put it there, or at least download it to your computer and specify the pathname in your argument to ImageIcon.

Also, use code tags.

BestJewSinceJC 700 Posting Maven

Sort it yourself, even use a BubbleSort if you want, since its a small collection of cities. I used a PriorityQueue for one of my projects before and it isn't hard to implement the default Java class for it, but you'll learn more doing it yourself probably.

BestJewSinceJC 700 Posting Maven

The problem is that nextDouble does not advance past the newline. You can use the methods in any order that works for you; none of the methods is necessarily better or worse, it depends on your situation. For example, you could continue to use nextDouble in your case, and simply add an extra "nextLine" to eat up the newline.

BestJewSinceJC 700 Posting Maven

You only need to do a few things:

Read in the characters from the file. As you go, assign a number to each character (make sure you don't assign the same number to two different characters). Keep these number-character pairs in a list. Then read the numbers from the file, looking at your list to see what character that number corresponds to. Print out the character.


From looking at your code, it doesn't seem that you've stored the number/character pairs anywhere.

BestJewSinceJC 700 Posting Maven

Read the thread. Both Ezzaral and S.o.S agree that returning the index (or returning -1 if it is not found) fulfills your need. And from what you've described I also agree.

BestJewSinceJC 700 Posting Maven

Oh, forgot to mark solved. Also - Ezzaral - My problem doesn't require as exact a solution as you suggested, but I am curious what you meant by the nanoseconds thing. Is this what you were saying?

while(true){
sleep for 1 second
take last measured nanoseconds - current nanoseconds
do adjustment to the current second, if necessary
}

BestJewSinceJC 700 Posting Maven

Thanks for the advice. I'm not concerned with "long term" correctness of the time - so I'll probably go with a Timer. And I don't need to schedule a repaint, since I'm using a String to write the time.

BestJewSinceJC 700 Posting Maven

Look at a piece of example code. . you're attempting to use numberOfEggs as if its a method, but you have not declared it w/ a method header & method body.

BestJewSinceJC 700 Posting Maven

I have to write a program that mimics a digital clock w/ seconds, minutes, and hours. I'm sure I can get the displays working on my own and everything. My concern: what is the most efficient way to check the time? Should I just do Thread.sleep for 1 second then update things accordingly? Or should I use Java's date and time classes to do this? If I use the date & time in, say, a while loop, it would be inefficient since I really only need to check to see if something is a new time every second.

BestJewSinceJC 700 Posting Maven

You can use Integer rather than int. null, as far as I know, can only be used with Objects. int is a primitive type whereas Integer is an Object or class type. So change the return type of your method to Integer.

BestJewSinceJC 700 Posting Maven

I think you have to call the revalidate method on your JTable, after removing or adding a column, to make it work. Its been a while, but I think that's the advice Ezzaral gave me when I asked a similar question before (I could be misquoting him; whatever advice he gave me worked).

BestJewSinceJC 700 Posting Maven

You didn't ask a question or explain what was wrong with the program. Surely if you've worked on it you know an area where your code doesn't work.

BestJewSinceJC 700 Posting Maven

No, that wouldn't work. How would it work for a set of numbers of arbitrary size (in other words how would it work when you don't know how many numbers you'll have, since in your example, it only works if you have 3 numbers)? Hard coding it like that would only work if you knew how many numbers you would have. And even then, it is unreadable and overly complex. The suggestions that a few people in here gave will work, but consider that the most efficient solution is probably to keep two variables: one being the lowestValue and one being the highestValue. Then, "look at" each number in your set of numbers once (go through your numbers once) and if it's greater than the highestValue set highestValue to the number you're looking at. And do the same for the lowestValue. If you study Java at all, you will be able to write this method. Nobody is going to hand you the code. But if this is hard to understand I'll give you the psuedocode so you can try to code it on your own:

declare highestVariable and set it to 0
declare lowestVariable and set it to something really high

for each of your numbers, compare the first number to highestVariable. If it's higher than highestVariable, set highestVariable to the current number. Do the equivalent for lowestVariable. Then move onto the second number. Do this for every number in your set of numbers.

BestJewSinceJC 700 Posting Maven

Or you could think of it in a few other ways. For example

1 * 10 ^ -1 is the same as 1/10^1 or 1/10. It is also equivalent to moving the decimal place back a few spots.

BestJewSinceJC 700 Posting Maven

They mean make a method that has a parameter, numberOfEggs, which is an integer.

BestJewSinceJC 700 Posting Maven

Shouldn't failing to override a method of an abstract class give you an error? In any case its a logic error not to if you need that method. So implement it and then say any problems you're having.

BestJewSinceJC 700 Posting Maven

Yes, that seems to be what I need. What I don't understand is that if OpenGL is an API, or a set of functions, i.e. a library of sorts, then why would I need to 'add OpenGL to be used for the specific project' like the link I posted suggests? I feel like I'm missing something here....

BestJewSinceJC 700 Posting Maven

Post your code in code tags and indent it properly (before posting it in code tags) and people will help you.

BestJewSinceJC 700 Posting Maven

After some research I found this link http://splainhow.com/jogl_eclipse.html which explains how to set up a project in Eclipse to use OpenGL with it. But I want to integrate the OpenGL libraries for JOGL with Eclipse so that I can import and use them with any projects. Does that make sense?

(Also, I searched for this question on daniweb, and found nothing similar)

BestJewSinceJC 700 Posting Maven

It isn't working because you never initialized the 'birthDate' variable to the person's birthday.

public int getLeefTijd()
    {
        // make an object with the birth date
        Calendar birthDate = new GregorianCalendar();
        
        if (today.before(birthDate))
        {
            age--;
            Age = age;          // Age is also a field
            return Age;
        }
      
    }

So birthDate just has whatever the default values are. . not the person's birthday like you want it to have. To fix it, you could use this constructor, "GregorianCalendar(int year, int month, int date)" instead of the default no parameter constructor you're currently using.

BestJewSinceJC 700 Posting Maven

if (today.before(birthDate))


You're passing a GregorianCalendar Object to the before method. Are you sure this is correct? I wouldn't really know, but I don't see how a calendar and a day are the same thing.... you should be passing a day to the before method, probably.

edit: Yeah, it seems like you have it correct. Hm

BestJewSinceJC 700 Posting Maven

You could also make an Object that holds a name and an integer. The integer would be timesSeen. Then you'd only need one array. Either way works.