Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps your SalaryGenerator should take the current salary as a parameter and add a random amount to it, a randomRaise() perhaps.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to begin the effort on your own, which is why I posted the link for other Java game sources from which you can learn. This forum is for help - not handing over code for whatever you request.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This site has source for several games in Java. Perhaps something there will help get you started.
http://www.codebeach.com/index.asp?tabID=1&categoryID=4&subcategoryID=11

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Which part of the behavior specifically do you want to change? The fact that things float a bit, that certain components disappear if sized too small, should the message box be the only part that gets larger to fill the area? If you can be more specific it would help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, for one thing, don't set all of those constraint properties in the constructor. How are you going to read and make sense of that parameter string as you try to make adjustments?

Set the constraint properties individually. You can use a single GridBagContstraint object and vary the properties only as much as you need to for each placement. So if you are placing a component that only needs to change its gridx property, change only that property before you submit it with add().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

well then I can pass it as an Integer and a Float

Yes, and that is a different story. You repeatedly said you were working with int and float, which are not the same thing.
You can use the "instanceof" operator to check the type of an object variable.

(I think you also mean "abstraction" in your original question - not generics, based on the question. Generics are a type parameterization mechanism introduced in Java 1.5)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The question still makes no sense. You can't generically pass a primitive as a parameter, so you would need separate signature for each anyway, which alleviates the ambiguity.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just keep two int counters. Why do anything more complicated? There will never be more than two players in the game.

If there were more than two, you could keep their scores in an array, a HashMap, or most any collection.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you were asked that in an interview and do not have the answer and cannot figure out how to find that answer, you really should not have the job. A working programmer should know how to find answers to such things on their own through the documentation or other available resources.

I don't say that to be mean. It's just something you need to learn to do if you expect to hold a job programming and the sooner you get used to it the better.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See this is what I'm confused about: how do I know what I'm going to compare given that the compareTo() method is supposed to be able take any type of object argument? Different data types added to DataSet may require different methods of measurements (i.e. for strings you compare their length; numbers, magnitude; etc..). Somehow, I don't see a way to do this for generic objects, even with casting. There must be something I'm forgetting here.

edit: no emoticons -.-||

You could use instanceof to check the type of the object and operate appropriately. Any object that is of a numerical wrapper type (Integer, Long, etc.) extends Number, so that check becomes easy, as you can see here

Integer a = 3;
Integer b = 2;

if (a instanceof Number){
    if (a < b)
        System.out.println("-1");  // just printing here as example
    else if (a > b)
        System.out.println("1");
    else
        System.out.println("0");
}

If the object is an instanceof String, those operations can be separated the same way.

Since you have a parameter of Object to be compared to "this", you will also need to decide what to do if they are not compatible types. The compareTo() method says that it will throw ClassCastException if the types are not comparable, so you need to throw that exception unless you have a specific strategy on comparing disparate types (ie by their toString() values, or perhaps treating Strings as a numeric zero, etc). Most likely you would want to throw the exception, since …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It sounds like you mostly understand how compareTo(Object o) works. Your job is to compare the specific properties of the objects in your if() statements such that you return the proper int value. If you need to compare on some property value, say object.cost() for example, you write the if() statements to copare those properties such that if o1.cost()<o2.cost() then return -1, etc. If you aren't using generics to define the object types, then you will need to case Object to the correct type before you can access the properties.

I think you almost have it nailed well enough, but if my explanation is still confusing, just post back on what you don't understand.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here is a small example with a view controller. The two view classes defined have essentially the same code here (which you would never want to code into a real app), but since they just represent your other two frames I made them separate for clarity of the example.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import javax.swing.JButton;
import javax.swing.JFrame;

public class FrameExample {
        
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                Controller viewController = new Controller();
                MainView main = new MainView(viewController);
                DetailView detail = new DetailView(viewController);
                viewController.showView("Main");
            }
        });
    }
    
    static class Controller {
        HashMap<String,JFrame> views;
        
        public Controller(){
            views = new HashMap<String,JFrame>();
        }
        
        public void registerView(String name, JFrame view){
            views.put(name,view);
        }
        
        public void showView(String name){
            if (views.containsKey(name)){
                for (String key : views.keySet()){
                    views.get(key).setVisible(key.equals(name));
                }
            }
        }
    }
    
    static class MainView extends JFrame {
        final Controller viewController;
        
        public MainView(Controller controller){
            super();
            this.viewController = controller;
            
            setTitle("Main");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            getContentPane().setLayout(new BorderLayout());
            JButton button = new JButton("Show Detail");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    viewController.showView("Detail");
                }
            });
            getContentPane().add(button, BorderLayout.SOUTH);
            pack();
            setSize(200,200);
            viewController.registerView(getTitle(), this);
        }
    }
    
    static class DetailView extends JFrame {
        final Controller viewController;
        
        public DetailView(Controller controller){
            super();
            this.viewController = controller;
            
            setTitle("Detail");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            getContentPane().setLayout(new BorderLayout());
            JButton button = new JButton("Show Main");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    viewController.showView("Main");
                }
            });
            getContentPane().add(button, BorderLayout.SOUTH);
            pack();
            setSize(200,200);
            
            viewController.registerView(getTitle(), this);
        }
    }    
}

This in itself is still probably not a solution to your needs, but without any more information on the relationship between your …

peter_budo commented: Nice example, what more can I say :) +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As long as the two frames have references to one another, you can easily interact between the two. Another idea may be to use a non-visual controller that can act as a mediator between the two frames and synchronize interactions and state changes as needed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

One more very handy site for code snippet examples on many things:
Java Examples from The Java Developers Almanac 1.4

emaan.gseo1 commented: nice post +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Maybe you could run around with a sharpened tiny straw and suck their blood for a change.

It might teach them a lesson... but it probably tastes icky :(

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

:-(
is this a forum only for experts?

No, not at all. You asked an incredibly general question and jwenting gave you a general answer. If you need specific answers you need to ask more specific questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He also gives out presents only, but in some countries Santa Claus gives out beatings and coal for the bad kids. Not a role for comedians.

Adam Sandler could pull that one off.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ezzaral
I would like to do something like this:

do
{
System.out.print("Enter number: ");
a = input.nextInt();
} while (a is a number);

can I still use hasNextInt() if I don't know what the value is?

Thanks guys!

Did you read the API documentation for the method? http://java.sun.com/javase/6/docs/api/java/util/Scanner.html#hasNextInt(int)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Scanner has a hasNextInt() method that will tell you if the input can be read as an int (also has method to test for float if needed). If that returns false you can just consume the input and re-try.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Move to the desert! I haven't heard or seen one of those buggers for the last 10 years.

He wanted to know how to fight them though... not avoid them :)
I stand by tiny pointy sticks or perhaps tiny swords. Tiny guns would be unfair as they can't hold those well with their little feet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sell it on eBay, they take everything.

Especially if you can claim it bears an image of the Virgin Mary!
http://news.bbc.co.uk/2/hi/americas/4034787.stm

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just an unrelated side suggestion:
Always go ahead and use braces with your for() and if() blocks, even if they execute a single statement. Yes, it is unnecessary, but you will save yourself a lot of debugging headaches when one day you add another statement to block and can't figure out why your code isn't working right.
Trust me - you will do that one day. :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Don't forget about your friend the mod operator as well:

for (int i=0; i < 5; i++) {
            for (int k=0; k < 5; k++) {
                System.out.print((i+k)%5 + 1);
            }
            System.out.println("");
        }

:)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Other:
"Heavy Metal" http://en.wikipedia.org/wiki/Heavy_Metal_%28film%29

The listed choices were pretty lame :P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"A Christmas Story" http://en.wikipedia.org/wiki/A_Christmas_Story_%281983_film%29

"Bad Santa" was pretty good as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Every shedding minute is a memoir.

Yeah, and between two dogs and two cats, our house has too damn many memoirs...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Stick it under an extremely wobbly table to add stability.

Excellent!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

With very small pointy sticks.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will first need to work up something on it for yourself. If you run into problems, then post that code and specific questions about it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, something like what S.O.S. posted was what I had in mind, and you'll notice that it does still show exception handling as your assignment required.

It may make no difference to your current assignment, but keep such things in mind for future consideration when your initial plan yields duplicate code blocks.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By giving your arrays to that method, you give them a local copy of the arrays.
This means that what ever you do inside that method, happens to the copy. In orde to get the result back into your initial arrays, you need to let your methods return the adjustments you made.

Actually, no, any operations he performs on the elements of the passed array do affect the original. It does not make a copy of the array.

rickster11,
The reason for the error is that you are not checking the length of the array in your loop, just for the end of file. You have declared the arrays to have five elements, but you are not hitting "eof" on the fifth read so it has incremented "x" and is trying to access an array element that doesn't exist. Make sure that your loop also checks against the array length to avoid this.

edit: Additionally, your "y" variable remains 0 as it is, so you will never have data past the first element in that dimension of your array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A 2D array doesn't have a method called empty(), which is what you are trying to call here a.empty(row,column) . You don't show your empty() method, but if it already operates on an instance level array variable, just call emtpy(row,column) . If you need that method to work against different arrays when called, you need to pass the array as a parameter to the method along with the row and column.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Cannot find symbol" means you are using a class, method, or variable that hasn't been defined. In this case, you are calling "hprintln()", which doesn't exist in that file.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A counter of the incorrect entries would be easier. What if you decided to allow for three incorrect entries instead of two? Another try block with identical code would be needed. In most all cases, duplicate code blocks should suggest to you that something could be arranged more efficiently.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you look at the source code for the Hough transformation applets in those links?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, so again, what is your question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please use code tags around your code to preserve formatting, and.... what is the question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm assuming that he is wanting you to treat the problem like a minimum spanning tree over a weighted graph. Assigning the inverse of the key frequencies as the weights might give you something to go on if you can find any statistics on the grouped key frequencies.

(This may be of use also: http://en.wikipedia.org/wiki/Bigram)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try these:
# http://www.rob.cs.tu-bs.de/content/04-teaching/06-interactive/Hough.html - Java Applet + Source for learning the Hough transformation in slope-intercept form
# http://www.rob.cs.tu-bs.de/content/04-teaching/06-interactive/HNF.html - Java Applet + Source for learning the Hough-Transformation in normal form

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Think of using the stack as a place to put something to be processed later by your algorithm as opposed to recursion being used to process it right now.

From your starting position, examine whatever you need to check. If it meets the criteria, push it onto the stack instead of making the recursive call. Once you've checked everything from the current position, pop from the stack and continue in the same manner. You're done when you have checked the last item from the stack.

Using a stack or queue will tend to work outward more gradually from the starting position by completing the task at hand before moving along to newly discovered tasks. Recursion will "rabbit trail" off through a series of discovered tasks and return to wherever it started from after completing all of the newly discovered tasks.

(I'm being intentionally vague on the operations themselves so as not to just hand you a solution to the maze checking part)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are merely scanning all the words and incrementing the position, but you don't do anything when you get to the position where the insertion is to take place. The for loop is just printing the last word found by the scanner "number of words" times.

You are also returning a recursive call back into the same function, which is definitely not what you want to do. You need to return the new sentence string (which you haven't created).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just have the boolean values reversed in the conditions

if ( numerator != -99) {
                    int result = quotient( numerator, denominator );
                    System.out.printf( "\nResult: %d / %d = %d\n", numerator,
                      denominator, result );
                    //continueLoop = true;   don't even need this one
                } else {
                    continueLoop = false;  // set to false if -99
                }
DeadJustice commented: Thanks again! +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

African American is a stupid word, as that could include white africans, living in america

Hehe, yeah, I thought the same thing.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hmm 400 is way over my budget haha i'm a broke college student so i'll do what i can

Cheaper and more productive to just do your own homework.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>Apparently American blacks are now feeling insulted by the word "black", irrespective of when it's used.

Actually, it seems to me that "Black" is becoming accepted usage again after years of "African American" being the only term acceptable to the PC wonks.
:icon_rolleyes:

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Wouldn't it be ironic if the pregnancy she terminated would have grown into the person who perfected a carbon-less energy source that brought the entire world out of its dependence on fossil fuels? :)

(Though you're probably right - the gene pool is most likely better off)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, I like to eat bass too :)

Caught quite a few nice bass about a week ago. Don't like to catch drum though :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to go through the Space Invaders 2D game tutorial on this site: http://www.cokeandcode.com/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I didn't know about this (I must be blind or something ;-) ). But, sad, just sad.

You didn't see it because it happened in a thread in the Geeks Lounge and whatever disagreements or rep slinging that happen there have no business in the technical forms.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You'll need to use a formatter like DecimalFormat or String.format().

float value = 0.60f;
DecimalFormat df = new DecimalFormat("0.00");
String formattedValue = df.format(value);