Shane McKenzie

Greenhorn
+ Follow
since Jun 24, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shane McKenzie

Man, does recursion get on my nerves. :-) Here's my problem, and I have literally no idea where to even start, or I'd post a code snippet. I'm just about to take a final exam in a programming class, and I've had no trouble with anything to this point, except recursion. It drives me mad. What I need to do is create a method called remainder(int a, int b), that calculates the remainder (a % b) WITHOUT using the % operator. I pointed out the presence of the static methjod Math.pow() to my professor, and he was nonplussed. :-| Can anyone point me in the right direction???

shane
16 years ago
Hi all, hope you can help here. I have no idea what the issue is. here is the code, please advise if you need more....

public void actionPerformed(ActionEvent aE)
{
//create buttonpressed object
Object buttonPressed = aE.getSource();

//figure out which field was entered and
//fill the other two fields accordingly


if (celsiusField.getText() != null && buttonPressed == convert)
{
//grabs input and changes to a double
String inputStr = celsiusField.getText();
double inputTemp = Double.parseDouble(inputStr);

//sets the other fields to the proper calculated value
fahrenheitField.setText("" + TemperatureConverter.CtoF(inputTemp));
kelvinField.setText("" + TemperatureConverter.CtoK(inputTemp));
}


else if (fahrenheitField.getText() != null && buttonPressed == convert)
{
//grabs input and changes to a double
String inputStr = fahrenheitField.getText();
double inputTemp = Double.parseDouble(inputStr);

//sets the other fields to the proper calculated value
celsiusField.setText("" + TemperatureConverter.FtoC(inputTemp));
kelvinField.setText("" + TemperatureConverter.FtoK(inputTemp));

}

else if (kelvinField.getText() != null && buttonPressed == convert)
{
//grabs input and changes to a double
String inputStr = kelvinField.getText();
double inputTemp = Double.parseDouble(inputStr);

//sets the other fields to the proper calculated value
celsiusField.setText("" + TemperatureConverter.KtoC(inputTemp));
fahrenheitField.setText("" + TemperatureConverter.KtoF(inputTemp));
}

I've tested the individual methods (they are statics, in a class called TemperatureConverter), the implementation is ok. The trouble is that in my GUI, the only one that works is the first if, neither of the else ifs work at all, they sinply don't place any data in the other two textAreas. It's driving me mad. Can anyone help me?

shane
16 years ago
hi all,

question about using FlowLayout. I read that it is supposed to go left to right, top to bottom, adding components lower down as a "line" (for lack of a better word) became full. however, I've been trying it out, and i cannot seem to get it to drop down. am I missing soemthing really simple here? any help'd certainly be valued!

thanks,

shane
16 years ago
Hi all,

I like arrays as much as the next guy, the reason I don't want to use them in this case is that I'm doing the exercises from a java book, and this question appear at the end of chapter 4, BEFORE arrays and vectors and lists are ever introduced, which implied to me that one should use another method (pardon the pun) to execute the task. I'm assuming that the reason is to give someone a really good appreciation of arrays when they're brought into play, which is in chapter 5, much to my consternation. ;-)
17 years ago
Hi all,

I have to make a program that will take fouyr strings, received through JOptionPane, and print to screen these 4 strings in both ascending and descending alphabetic sequence. I'm sure it's simple, but it's giving me trouble. Ideally what I'd like to do is read in the strings, store them, then pass those 4 strings as arguments to construct a "word" object. Then call methods on this object which will fulfill the requirements.

It's these methods that are giving me trouble. I DON'T want to use an array at all, so havings aid that, I gather I'd use the method string1.compareToIgnoreCase(string2), which makes perfect sense. However, how do I make this work properly without simply hardcoding in a multitude of if statements that address every possible permutation? Though that would work, I can't think of anything uglier. ;-)

Any help here would be greatly appreciated. I haven't posted any code, as all I have is literally the method headers with no implementation code within them! Thanks in advance!

shane
17 years ago
Hi,

Were I you, I would google "java tutorials" or "java programming exercises". I did that when I first started learning it, and I got lots of sites with great examples. Also, java books are good. I recommend "Problem Solving with Java, 2nd Edition," by Koffman and Wolz. Also, I found this site, and it helped me ALOT when I first started.

http://chortle.ccsu.ctstateu.edu/CS151/cs151java.html

Give that a try, it should help.

Shane
17 years ago
Thanks Jeff, I appreciate the help. Such a rookie mistake, but there ya go! Anyway, that seems to have worked ok, it runs properly now. Thanks again mate!
17 years ago
I'd like to know why this won't work; it seems as though it should...I overrode the init() method so that the user can type a choice in JOptionPane, and that works when the html file is opened, but then regardless of user input, NO drawing elements appear! My sanity is slipping.....

HTML:

<HTML>
<applet code = Test.class width = 200 height = 200>
</applet>
</HTML>

Applet file:

import java.awt.*;
import java.applet.Applet;
import javax.swing.JOptionPane;

public class Test extends Applet
{
//data fields
private String shapeChoice;

public void init()
{
shapeChoice =
JOptionPane.showInputDialog( "Please enter C, S, or R:" );
}

public void paint(Graphics g)
{
if (shapeChoice == "c")
{
g.setColor(Color.black);
g.drawLine(0, 0, 100, 100);
}

else if (shapeChoice == "r")
{
g.setColor(Color.black);
g.drawLine(0, 0, 50, 50);
}

}

}// end class test

Any help here would be greatly appreciated!

shane
17 years ago
Hi Tonya,
I know what you mean about it being tough. I recall all too well the stress I went through when i first tried to learn this stuff. Just hang in there. Like the other poster said, if you have specific questions, post them; it's a lot easier to lend a hand that way. Your tutor idea is good, but also check out this website...
http://chortle.ccsu.ctstateu.edu/cs151/cs151java.html
It's an awesome Java tutorial that helped me out so much, and I'm sure it'd help you out also.
Good luck.
19 years ago
Hello....I read this fellow's question, as well as the answers given...I myself would also like to creat an IM app in java....I'd like to see the tutorial you mention Dirk, but I looked on both google and IBM's page, and I can't seem to find it. Any further info on this? It seem like a cool thing to undertake! Thanks in advance for any help any of you can send my way!
19 years ago