Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>and i dont mind if u can give me the whole code for this program

So, actually you are perfectly ok with cheating, even though you claim you don't want to.
Read your class notes, get a program outline or at least a decent amount of pseudo code together on your own, and post that back here with specific questions or errors.

No one here is going to complete this for you. Better get started soon, you don't have a lot of time left.

verruckt24 commented: Caught him !!! +2
stephen84s commented: lol +6
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it is "read" in Thread1, because it's the same static "cnt" that you declared in your top level class - but you really should pass it as a parameter. I'd recommend writing a constructor for Thread1 (which you really should rename - Thread1 doesn't really convey anything about what that class is for) which takes that count as a parameter and initializes the arrays to the proper sizes. Make those arrays plain private members. They don't need to be public static.

I'd also recommend adding a println check on the value of "cnt" before starting that thread to verify that it is the value you think that it should be.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And are you certain that "cnt" is greater than zero when those arrays are getting declared?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the first thing you need to fix is your paintComponent() method. If you override that method, you cannot arbitrarily change its signature. It must match the original method, which this does not

public void paintComponent(Graphics a,Graphics g){

It should be

public void paintComponent(Graphics g){

The method you have written is not getting called at all because it is not declared correctly.

Correct that method declaration and change all "a" references to "g" and you will see the result of your painting code.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not going to count each line to find line 45, but it's most likely your first access of the "transition" array in Thread1. "(cnt*(cnt-1)/2)" is most likely coming up zero and leaving you with zero-length arrays.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This should get you started:
How to Use Actions

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I completely agree, niek_e.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use the Scanner to read from files as well. Take a look at the documention.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

When you try to call "drawCircle" where? Because in your code above, you don't have any call to that method, nor do you create an instance of your Circle class.

You certainly don't want this in your Circle class constructor

Circle circle = new Circle();

because it's going to call itself recursively until you overflow the stack.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't. I haven't really seen any compelling reason to.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is that babble supposed to make any sense at all?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start with this: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html
If you have specific questions, post back with them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The reason is The Java Language Specification - that is just how it is.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Start with this: http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
That will tell you what you need to know to compile and run from a command window.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes exactly, you'd calc the actual elapsed time instead of assuming that just because you slept 1 second (or whatever increment) that only 1 second had elapsed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

1. Nontheist (100%)
2. Secular Humanism (100%)

Not a very difficult call for their quiz to make.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I doubt anyone else here does either since it's your data and your GUI and you haven't posted a single line of code.

Since you got the info one time, I assume you can get it again and if you displayed in once before, you can display it once more. That is exactly what your ActionListener needs to do.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So read that tutorial I linked and write an action listener for your button that does that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

how do i create java code that randomly assign numbers to letters,

With Random and a HashMap I suppose.

sum them,

"+" operator.

display them

A console or a Swing GUI

and store them in a database

JDBC

javaAddict commented: you put a lot of effort in this response +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I guess that would depend on what it's "refreshing" wouldn't it? Start with this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

OpenOffice has a Java API as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@rapture: No, because that method signature does not have a parameter. He is calling it correctly, but it's not doing what he thinks it might be doing.

That method is not actually doing anything but returning a null string variable that was never initialized, which in turn is causing a null pointer exception I would imagine (I haven't run any of the code and he didn't specify the error).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What errors? You didn't specify what they are. Have you read the stack trace of the error? It indicates the nature of the problem and the line number.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you running it from the directory that contains that class file?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This article/tutorial on the class path may help in understanding the issue further, if you want to know the "why" of it: http://www.kevinboone.com/classpath.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, not knowing your exact directory structures and where your output class files are located (you said they were in different directories), I would recommend compiling all of those java files at the same time with javac *.java . It's just a simple classpath problem that you are encountering. There is nothing wrong with the code itself.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you definitely need to replace all of those print statements with a loop that prints each line item from the array. There is absolutely no reason to type all of that in manually - it only differs by the array index.

I'd recommend writing a small data class (a struct if you have a c background) to hold the data for each of your entries. i.e.

class HurricaneEntry{
    int year;
    String name;
    int category;
    float pressure;
    float windspeed;
}

For your frequency count on the categories, a HashMap is useful.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are your class files in a different folder than your source files? Do the file names match the class names?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is one point I think we can all agree on: returning the value itself if it is found is not a useful thing to do.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, you replace your array with an instance of an ArrayList and use it's methods to manage the items.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You shouldn't have any problems doing that. The API for ArrayList is pretty straightforward. You don't have to manage the size of it yourself and you have methods to add(), get(), and remove() items. If you run into difficulties, post the code here along with your questions or error messages.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your while loop is fine as long as you re-prompt for the next value at the end of your loop code. In pseudo code, you want something like this

prompt "continue?"
while ("yes"){
 // do stuff

  prompt "continue?"
}

As for as "tracing", just start with the initial value of "counter" in your loop (which is zero) and walk it through your code mentally (or on paper if you prefer). That's all tracing is. You don't have to run through it very far to understand why you are getting the output that you are.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

>When I run my program I input 1 sales figure and the program goes into a never ending loop. Why?
Because you never change this condition

while  (dollars > 0)
        {

>and where are all the tallies "*" beside my references coming from and why
They are coming from your loop on your fixed "Sales" array. Trace the value of "counter" through those loops and compare them to the output you are getting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By the way Ezzaral, I apologize if my previous post seemed offensive or antagonistic. I was just trying to explain my position but after further examination it donned on me that it might have seemed a bit coarse.

Your post was not antagonistic, but if you spend much time here at all you will quickly see that we encounter many students who just want the code for their assignment handed to them and do not want to put any effort into learning the material. That is quite clearly not the intent of these forums. Some answers may be more vague than a student would like, but learning programming is a process of learning how to think things through in certain ways and learning how to use the elements of the language to craft a solution. Handing someone a completely working program does not invoke the same understanding of a concept as does providing enough guidance for the student to figure it out for themselves.

I did acknowledge that I understood hexcode was merely being helpful, but since he is a new member I did want to let him know that posting completed assignments is somewhat frowned upon.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Real code that you can read and manipulate to see how it works teaches much better than single lines of code or vague responses that don't really answer the questions asked because the poster doesn't want to provide "too much" information.

I did not discourage "real code". I discouraged posting a complete working version of the assignment. The two are not the same.

Those "vague responses" may or may not be so vague depending upon how much effort and searching has gone into finding a solution. They may "really answer the question" if the student reads the referenced portions of the API documents and thinks about how the methods would apply to their situation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should be overriding paintComponent(), not paint(), in your "NewClass" class.
(And find a new name for that class because NewClass is an awful name for a component)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hexcode, while you obviously mean to help, please keep in mind that writing a student's entire assignment for them teaches nothing and is discouraged by the forum rules.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Definitely.
Pretty neat... until they turn on us... :twisted:

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I can't really see how anything vaguely useful could come from leaving it open.

Salem commented: Neither can I, and I've reported it as such. +28
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Since your assignment specifies it, do you not have any class notes related to StringTokenizer? Seems strange to me that you have an assignment on things that were not covered in class at all.

StringTokenizer is also a legacy class and it's usage in new code is discouraged:

StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First thing, use [code] [/code] tags around any code that you post. No one wants to try to read that huge unformatted wall of text you just dumped on the page.

Second, http://www.catb.org/~esr/faqs/smart-questions.html#urgent

Lastly, how do you intend to specify the frame you want to grab? Your question is extremely vague.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

can u sahre that email id's as i am doing the e-marketing

You need to work on your communication skills before you even think of doing any "marketing".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They will start you with the most entry-level tasks they can find. That may be fixing a few simple bugs in certain packages, adding a trivial feature to an existing code section, or anything else that lets you get acquainted with the code base and style with minimal interference to ongoing work of the team. You're right that it won't have anything to do with Fibonacci numbers, but it will completely depend on the current work that the team is doing and how they decide to work you in to deal with the learning curve - which will be fairly steep in your first "real" job.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And stephenpeter, don't shout your questions in all caps. It's rude.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

@verruckt24: He certainly could use a boolean return if "contains()" is all he needs to know, but he doesn't really say what he needs it for. Additionally, as s.o.s. points out, returning the index of the element or -1 satisfies both the "contains()" functionality and "indexOf()" functionality at the same time, which can make for a more compact API.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's because you aren't repainting the background rectangle before you paint the oval. Even so, you really should do your custom painting on a lightweight component such as a JPanel or small JComponent class that overrides paintComponent(), rather then painting directly on the JFrame. Here is your code with a small canvas component for the painting:

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class Court extends JFrame implements Runnable {

    private int x = 10;
    private int y = 20;
    private int r = 3;

    public Court() {
        setBounds(0, 0, 200, 200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setBackground(Color.BLACK);

        // adding the new component here
        getContentPane().add(new CanvasComponent());

        this.setVisible(true);
        start();

    }

    // Custom component for your paint work.
    // JPanel is also a good candidate for this.
    class CanvasComponent extends JComponent {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.GREEN);
            g.fillOval(x - r, y - r, 2 * r, 2 * r);
        }
    }

    public void run() {
        while (true) {
            x++;
            repaint();

            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {}
        }
    }

    public void start() {
        Thread thread = new Thread(this);
        thread.start();
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Court();
            }
        });
    }
}//end
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm going to chime in and agree with the -1 return. I had assumed you were already doing what s.o.s. mentions above about returning the index of the element. That is the way many such methods operate in the standard JDK classes. Sticking to the common idioms for things like that makes your code much easier to work with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

One thing to note on the do-while loop verruckt24 posted above:
You probably want a normal while() loop there instead of the do-while(), otherwise you're performing the loop code before checking the user's response.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's the problem. the terminal window doesn't come and ask to input the numbers.

Well, of course it doesn't because you just declared string variables. You didn't ever do anything with them. I had hoped my answer might make you think a little and figure out why you weren't getting the prompts. JavaAddict has answered that for you above though.