BestJewSinceJC 700 Posting Maven

Hey, one of you guys suggested that I go on Wikipedia's page for hash tables. It was actually pretty informative. I'm pressed for time so I am doing separate chaining for my hash table because it seems like it will be one of the easiest to implement (and according to wikipedia, thats also true). Anyway, I have a couple of questions on separate chaining. Thanks for any suggestions in advance.

1. When does the hash table need to be resized. I know about load factor, so lets say I choose 75%. Doesn't checking to see how full the hash table is require looking at every index to see if something is there, and incrementing a counter. If so, how often should I check to see how full the hash table is? It seems like doing so every time would be inefficient.

2. How should I decide what the initial capacity of the array that my hash table uses should be? Is it related to my individual problem (I think so)? If so, any general strategies for choosing a good size? Also, are there any bad things that can occur (other than wasting too much memory) from picking an original size that is too large?

BestJewSinceJC 700 Posting Maven

float balance = (float) 0.0;

Saying (float) is unnecessary here, the compiler knows you are declaring a float.

The 'continue' statements are unnecessary, as far as I know, so you should consider that. (It isn't your problem, I don't think)

However, one way to limit down your problem is to add some print statements. For example, did you check to make sure you're reading in what the user entered correctly? That is a big step towards figuring out where your problem is. Try it and tell me what you get

BestJewSinceJC 700 Posting Maven

Are you sure you're in the right forum? (I'm not saying you're not - just curious, since I thought this kind of thing was usually php or something)

BestJewSinceJC 700 Posting Maven

The reason I'd code it w/o a loop is because it would take less time to hard code a few lines of '*' rather than spend time to think about the pattern then write loops based on it. The code to write the loops alone is probably longer than the code to just print the '*'s' out. And the code definitely makes more sense at first glance hard coded than if it is put in for loops. Also, you might want to consider that the sentence 'nested is the term' only makes sense to Yoda. Learning you are.

BestJewSinceJC 700 Posting Maven

You're doing a project for your major and you expect someone on here to give you the code? Lol.. rearry?

BestJewSinceJC 700 Posting Maven

There are a lot of ways you could produce that code using while loops or for loops, but most of them should not be coded using a while loop or for loop, unless your teacher is trying to make you use a math formula to calculate the number of '*' on each line. If I were you I'd just ask my teacher about this.

BestJewSinceJC 700 Posting Maven

Is that supposed to be a link to the source code - it just looks like an ad? If not, where can I find it? I've heard of unicode, I'll take a peek at the code but I tried to google it and couldn't find it.

BestJewSinceJC 700 Posting Maven

Just so you know, an Object oriented approach to solving the problem would involve creating a class called Bicycle that had instance variables such as wheelRadius and the other things you listed above. Then, you would have methods - for example, one method might calculate the effective radius. In this example, in your main, you could just say

System.out.println("The effective radius is " + effectiveRadiusMethod());

Of course, that's just an example. In the Bank Account example you posted in your other thread, it would be much more necessary to do as I said above. In this case, you can get away without doing so. Also, keep in mind, in order to get help, you have to ask specific questions and show that you have attempted the problem yourself. Or, if you aren't sure where the problem lies, you can post code and ask for help. BUT you must, at the least, identify a problem. If you don't identify a problem nobody wants to help you. I'm still open to helping you at this point, although many members might not be... and I don't blame them. Try reading the Daniweb rules - code tags, homework help rules, etc.

BestJewSinceJC 700 Posting Maven

Thanks - much appreciated. I should have just searched isLetter first, but I didn't realize that my guess would be the method name. Lol.

Also, out of curiosity, if anyone knows the method's logic, please tell. I doubt its that complicated, probably a few lines of code.

BestJewSinceJC 700 Posting Maven

He's not asking a question, he's asking somebody to do his work for him. Vote- death

BestJewSinceJC 700 Posting Maven

parseInt does not seem to be throwing an exception when I pass a letter of the alphabet to it. I assume this is because ASCII letters are treated as integers. So my question is, is there a method that will do this:

boolean isLetter();

And if not, how do I get around what I said about ASCII (if its even a correct assumption) to write the method myself?

BestJewSinceJC 700 Posting Maven

Personally I would write this in C over Java. Only because Java is Object oriented and the problem you have posed isn't. Well sort of, but even more the fact that C will probably be much faster than Java for this project.


Also, this topic has been posted on daniweb before, so you might want to try to find the thread. I'm not sure how you plan to implement it, but in any case, be sure to consider something: does the file have to match exactly in order to be considered a match? Or will it be based on what % of the file matches? In either case, be sure to discontinue scanning the file at any point if its determined it doesn't match. You might want to consider using Tries. See Trie based cheat checker.

BestJewSinceJC 700 Posting Maven

ArrayList is allowed.. Object is allowed. I meant the obvious ones are banned.

BestJewSinceJC 700 Posting Maven

Problem: when the user prints the JTextArea, the text at the right-hand side of the "paper" is cut off, despite the fact that it is visible on the screen. Question: How can this be solved? I've tried two ways of printing the text area, and neither has worked as I'd hoped. Unfortunately, I do not have a printer for my laptop so I can't do tests easily. Does anyone know of a better way to do the printing?

public class MatchListing extends JPanel implements Printable, ActionListener{

	private JFrame frame;
	private JButton print;
	private JTextArea textArea;
	
	public void actionPerformed(ActionEvent e){
		//alternatively to the below:
		try{
		textArea.print();
		} catch(Exception excp){}
	}
	 

	
	
	public MatchListing(){
                // ...

		textArea = new JTextArea(10, 25);
		textArea.setMargin(new Insets(0,100,0,0));
		textArea.setFont(new Font("Times New Roman", Font.PLAIN, 18));
		textArea.setEditable(false);
		JScrollPane jsp = new JScrollPane(textArea);
		
                 // put text into the textArea here & add it to the frame
                 //(code removed for readability)

        add(jsp, c);
        add(print);
	}
	
	public int print(Graphics g, PageFormat pf, int page) throws PrinterException{
		if (page > 0) { /* We have only one page, and 'page' is zero-based */
			return NO_SUCH_PAGE;
		}

		/* User (0,0) is typically outside the imageable area, so we must
		 * translate by the X and Y values in the PageFormat to avoid clipping
		 */
		Graphics2D g2d = (Graphics2D)g;
		g2d.translate(pf.getImageableX(), pf.getImageableY());

		/* Now print the window and its visible contents */
		frame.printAll(g);

		/* tell the caller that this page is part of the printed document */
		return PAGE_EXISTS;
	}

}
BestJewSinceJC 700 Posting Maven

if (SecondIndex == -1)
//call method with null params here
else
//call method with normal params here

So you would just do some calculations to figure out if the index is not a valid index. You could do this anywhere you want - I'd recommend a separate method, it keeps your code clean & readable. Then, you'd call the method setTheNeighbors based on what your method returned.

BestJewSinceJC 700 Posting Maven

Nobody is going to sift through your code looking for errors.

http://java.sun.com/docs/books/tutorial/uiswing/

That tutorial is what helped me gain the skill to write a GUI which handled multiple different activities, including printing, interactivity between itself and other GUIs, updating its information while running (adding text), and updating its main database while running. Ezzaral helped me quite a bit with the interactivity part -- why? Because I showed effort, identified a problem & explained what I could, and didn't just post something asking for someone to do it. I suggest you do the same. You can start by figuring out what part of your code has the problem. If your problem is that the buttons aren't added properly, then go to the portion of your code where you add the buttons and post it with code tags. If we need more code to help you figure out your problem, we'll ask for it at that point. It could be that you don't call frame.setVisible(true); or something simple like that.

BestJewSinceJC 700 Posting Maven

I need to build a hash ADT from scratch. This means no use of any java library methods or classes. Does anyone know of any good resources that will explain how hashing works and how this info is helpful to build one? For example, how find() works, how insert() works, how to handle collisions, etc. Concepts though, not code.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

A scanner object is created the same way any other Object is created in Java. If you don't know anything about Objects and how they are created, go read the Java tutorial stickied for this forum.

BestJewSinceJC 700 Posting Maven

Use % and / to do this.

BestJewSinceJC 700 Posting Maven

My point is that its not a queue, then. Just take an ArrayList, use int index = Math.Random(n) where n is the # of items in your ArrayList, then index is the random index you want.

BestJewSinceJC 700 Posting Maven

Also, your problem lies in your logic/algorithm, not in what type of variable you made. According to you,

"The input has to be divisible by 4 and 400 but not by 100."

You could accomplish this just by writing

public static boolean isLeapYear(Integer theYear){
if (theYear % 4 == 0 && theYear % 400 == 0 && theYear % 100 != 0){
return true;
} 

return false;
}

Also, it is important to note that the way you stated the problem, the code I gave you above is correct. However, you didn't state the problem correctly. According to what I just read online, a leap year occurs according to the following rules:

The rules for determining a leap year: Most years that can be divided evenly by 4 are leap years. Exception: Century years are NOT leap years UNLESS they can be evenly divided by 400.

This changes the code; I will let you figure out how. Hint: it requires a conditional (if) statement to decide whether or not it is a century year.

BestJewSinceJC 700 Posting Maven

You don't need to make an InputStreamReader if the stream is 'System.in'. System.in is the default input stream, just say BufferedReader input = new BufferedReader(System.in)

BestJewSinceJC 700 Posting Maven

What do you mean? A queue means its FIFO - first item put in the queue is the first item that comes out of the queue. So its not random.

BestJewSinceJC 700 Posting Maven

Get rid of the call to pack(). pack() resizes the components based on the preferred size of each component. So either setPreferredSize() and use pack, or leave your code like it is and do not use pack.

BestJewSinceJC 700 Posting Maven

Yeah, I know that. What I was saying is that if the C++ code was good to begin with, and the compiler optimized it well, whereas the assembly was poorly written....

BestJewSinceJC 700 Posting Maven

When you create a Scanner object, you have to do it with an input stream. The name of the file is not an input stream. Do this.

Scanner input = new Scanner(new FileInputStream(fname));

BestJewSinceJC 700 Posting Maven

I don't use drag and drop but if I understand you correctly, you're thinking about it the wrong way. When you click and drag it fires events, and certain methods handle those events. Also, read this, it will answer any basic questions you have

http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html

BestJewSinceJC 700 Posting Maven

From when I programmed in C, I remember that output stream redirection is done by


a.out > filename.txt
or a.out < filename.txt

I don't remember which. One is input redirection, the other is output. I think the first is output.

BestJewSinceJC 700 Posting Maven

Point taken, but my point was that a combination of unknown phrases adds a lot of ambiguity which makes it difficult to simply do a google search, combine definitions, then come to an understanding. It makes a lot more sense to explain things with some sort of clarity to begin with. And thats not a slight at s.o.s - he has definitely helped me in the past, and is overall a very helpful guy on this site. I'm just saying that its not out of laziness that I don't look those terms up -- its for the same reason that I wouldn't read a passage out of a French 300 textbook if I only knew basic sentences. It would take hours, maybe months, of work just to understand that passage. But maybe I shouldn't be taking the class in the first place. . or asking questions about reflection and expecting fairly simple answers. Lol. And yes, this analogy sucks. It could be applied in 100000 different ways.

BestJewSinceJC 700 Posting Maven

Here is a code example to answer a few of your questions;

//This creates a 'Scanner' object that is attached to the keyboard (since System.in) is attached, by default, to the keyboard. To learn how to use your Scanner object (I called it input), google 'Java Scanner' and look at the methods. You want to use one called nextInt() because it gets the nextInt from the user. 
Scanner input = new Scanner(System.in);


If we have a method called isEqualTo5, that returns 'true' if an integer = 5, we'd call it like this

boolean isItAnInteger = isEqualTo5(aValue);

I will leave it up to you to figure out how these examples apply to your problem. Keep in mind that all methods in Java can only be called in two ways, the above example being one of them.

BestJewSinceJC 700 Posting Maven

What I was saying is that I don't understand most of that terminology, so the point alone has no impact. I hope I wasn't rude - I wasn't trying to be.

BestJewSinceJC 700 Posting Maven

I read about data forwarding and according to my notes, a nop (no-op) is required before a beq operation and after a lw operation. What about sw?

BestJewSinceJC 700 Posting Maven

The person who posted above me is completely wrong. Assembly is faster than any other code if you use/code it correctly. It could be that the optimizations the compiler made for the C++ code were good optimizations, whereas the code you wrote was poorly designed and written.

BestJewSinceJC 700 Posting Maven

In the example Ezzaral gave, if he is using a different panel based on whats in the file, he would have to create an Object of the class that represented his panel. So how is it that reflection isn't used to create classes (I'm assuming you meant create objects, not create classes)?

BestJewSinceJC 700 Posting Maven

> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?

We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.

Can you elaborate somewhat on the first example? Do you mean that depending on what the contents are of the XML file, different panels would appear which are created from classes that have their own content... but that the type and size of the panel are always the same? Because I don't see how you could use different sized panels each time, that would mess up the layout. Unless, I suppose, you somehow dynamically figure out how big each panel was and did calculations based on that also. The second example seems to make sense - you have a table and its layout set ahead of time, and based on what Strings are input, that table looks up the classnames (presumably each String represents a classname?) then fills the table with each of those classes, treating a class as a 'column'? That example seems to make …

BestJewSinceJC 700 Posting Maven

If you make your object Serializable then you can store information about the object in String form. It won't be as readable as "germanShepard" but you could store objects serials somewhere to enter. Doesn't sound too practical.
Another thing you can do is make a factory class. The class would take certain strings and generate objects for you to use based on that string name. It's a common design pattern and I've seen it used while poking around with code at work.

s.o.s, no offense, but sifting through a ton of material to *maybe* answer my question doesn't sound too appealing. If reflection is indeed useful, there have to be some practical, simple explanations of why this is the case.

bionic: Making objects Serializable means you can write the objects to file in Binary form and read them back in this way, so that you can store and retrieve your Objects more easily than if you were to do text input and output. Maybe I misunderstood what you said, but it's actually much more practical than reading/writing Strings to a file.

Regarding your other point, you can also take Strings and make objects by using a simple if statement, so I don't see why that would be a good use of reflection.

BestJewSinceJC 700 Posting Maven

If you are simulating lots of circles bouncing off of each other, you would have to compute whether or not they are currently touching/adjacent by giving each circle a radius, and keeping the current position of the circle's center. Then, as the circle bounced, you could do a calculation between it and all the other circles to figure out if the circle is currently occupying space which is touching another circle's space. If so, bounce them in different directions. Thats the only way I can think to do this assignment. It would be much more difficult to treat each circle as having "multiple points" and then try to see if any of the points are touching than to use each circle's current center point as a marker for whether or not it is adjacent to any other circles (based on their center, radius, and area formulas).

BestJewSinceJC 700 Posting Maven

I don't know all that much on reflection, but I have used it before. I don't see how it is useful. I've seen plenty of examples of reflection, so I understand how it is used. Just not why. Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why? All the tutorials I see give examples of reflection, but they are never situations where reflection is necessary. For example, I saw reflection being used to print out hello world. Pointless.

BestJewSinceJC 700 Posting Maven

I think you answered my question correctly in your first post. I was just asking if it is possible to save a value into a String, then use that String as if it was the name of an Object (rather than being a String).

So, for example, if I had a String buttonName = "button1"; then I was asking if I could do

buttonName.whatever(), and have buttonName evaluate itself to see whether or not there was an Object named "button1" in the program. If so, it would call whatever().

Now obviously, this doesn't work as I wrote it, since Java treats buttonName as a String (as it should). I was just asking if there were any techniques that would do what I described above.

BestJewSinceJC 700 Posting Maven

I agree, but that isn't what I asked. Anyway, thanks for your help everybody. If anyone knows any languages where you can do this, please let me know, with a code example if you would. Otherwise consider this topic closed.

BestJewSinceJC 700 Posting Maven

Seconded on using Sockets. Unless the FTP thing is a requirement of your assignment. Here is where help on using Sockets can be found. http://java.sun.com/docs/books/tutorial/networking/sockets/

BestJewSinceJC 700 Posting Maven

Download 1.5 or higher. Honestly, how hard could it be to find a compiler and JVM? Lol

BestJewSinceJC 700 Posting Maven

I've used reflection before but I don't understand how it helps solve my problem. It just lets me know about certain properties of an Object, such as its classname. The concept of a Map is somewhat familiar, but it doesn't help avoid the work, does it? The primary reason I'd want to do this is b/c it'd be less work. For example, if I had 200 buttons, button1-button200, it'd be useful if I could do what I described in my first post. I guess this isn't possible in Java though.

BestJewSinceJC 700 Posting Maven

to do so you have to store it in memory. How do you plan to do this without use of a file?

BestJewSinceJC 700 Posting Maven

well, one problem is that you never added your myContainer to the frame. So nothing will show up. Also, I'm not sure about the use of
Container myContainer = getContentPane();

BestJewSinceJC 700 Posting Maven

1. You need to use code tags. Read the rules stickied at the top of the forum.

2. Read this.
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

BestJewSinceJC 700 Posting Maven

Why would you add an unnecessary level of abstraction (creating the structures) if you don't need to? The point of a structure is to group related data, not to shove **** together in order to reduce # of parameters

BestJewSinceJC 700 Posting Maven

Is there any way that I can take a String and somehow use it as if its the name of one of my declared Objects? For example, if I have an Animal named germanShephard, is there some way I could say String gerSh = "germanShephard"; and then treat gerSh as if it was the equivalent of saying germanShephard in my program?

BestJewSinceJC 700 Posting Maven

I think you should learn to write in English, but if this was an English Help Forum, I would still help you without criticizing you based on your horrible verb usage.

BestJewSinceJC 700 Posting Maven

Whoops! Lol. Thanks. I'll leave this open for now, since I don't want to create more unnecessary threads about the same topic if I have more problems. But I'll mark it as solved eventually.