WorldScape Blitz

Off Topic => General (OT) => Topic started by: nate on September 12, 2013, 03:22:49 AM

Title: Trouble with javascript homework
Post by: nate on September 12, 2013, 03:22:49 AM
(http://i41.tinypic.com/x4299f.png)


It compiles, and the first dialog box pops up.

(http://i44.tinypic.com/317fm9c.png)

I enter "Air" into it (minus the "), and it gives me this error.

(http://i41.tinypic.com/2qlvmur.png)
Title: Re: Trouble with javascript homework
Post by: James on September 12, 2013, 08:43:16 AM
Dats some ugly code you got their Nate :)
Title: Re: Trouble with javascript homework
Post by: nate on September 12, 2013, 03:54:46 PM
Quote from: James on September 12, 2013, 08:43:16 AM
Dats some ugly code you got their Nate :)

sorry, im currently in my 3rd week of ever using java in my life haha
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 12, 2013, 04:14:13 PM
Ummm you don't have anything defined as "value"... You make a case for something being "air" if you haven't defined it.
Title: Re: Trouble with javascript homework
Post by: nate on September 12, 2013, 08:00:51 PM
Quote from: Kryptonite on September 12, 2013, 04:14:13 PM
Ummm you don't have anything defined as "value"... You make a case for something being "air" if you haven't defined it.

I dont really know how to define it :p. Could you just show me what I need to add to it?
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 13, 2013, 12:15:12 AM
Quote from: nate on September 12, 2013, 08:00:51 PM
Quote from: Kryptonite on September 12, 2013, 04:14:13 PM
Ummm you don't have anything defined as "value"... You make a case for something being "air" if you haven't defined it.

I dont really know how to define it :p. Could you just show me what I need to add to it?

Um okay, so you have "double air = 1100;" that's defining a double named "air" and setting the value as 1100. You need to do something similar for "value", so wherever that "value" is supposed to be coming from (I don't know where you want this), do something like you did with the air and stuff except name it value.
Title: Re: Trouble with javascript homework
Post by: nate on September 13, 2013, 08:01:35 PM
I updated the first post
Title: Re: Trouble with javascript homework
Post by: James on September 13, 2013, 10:39:29 PM
Quote from: nate on September 13, 2013, 08:01:35 PM
I updated the first post

You spelled integer wrong.






8)
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 14, 2013, 12:43:00 AM
Quote from: James on September 13, 2013, 10:39:29 PM
Quote from: nate on September 13, 2013, 08:01:35 PM
I updated the first post

You spelled integer wrong.






8)
Lol you noob nate.
Title: Re: Trouble with javascript homework
Post by: nate on September 14, 2013, 04:07:58 PM
shhhhhhhh!  ;)

ok so now that I changed that, I get this error. havent changed anything else but interger to integer.

Still a little confused because I have initialized distance and time as a int. I tried also doing

String time;
String distance;

but that don't work :p

(http://i41.tinypic.com/8x1xqc.png)
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 14, 2013, 10:10:16 PM
Can you update your first post again?
Title: Re: Trouble with javascript homework
Post by: nate on September 15, 2013, 03:51:46 PM
updated
Title: Re: Trouble with javascript homework
Post by: Predator on September 15, 2013, 04:21:25 PM
Quote from: James on September 12, 2013, 08:43:16 AM
Dats some ugly code you got their Nate :)

James! you code so he gets A++++ ON TEST!
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 15, 2013, 07:32:12 PM
Ok nate, for the error you posted in your first post, you're trying to convert the string "Air" into an integer, but "air" is all letters.

I wrote one possible solution for you. After the end of your void "main", (right before the last bracket), add this int (i hope you know how to do this for gods sake):



private static int GetNumericalType(String input) {
if (input.equalsIgnoreCase("Air"))
return Air;
if (input.equalsIgnoreCase("Water"))
return Water;
if (input.equalsIgnoreCase("Steel"))
return Steel;
}


This transforms your string input into the numbers that you defined. Now, switch this in your class (line 20 in your picture, where you're having troubles):


type = Integer.parseInt(input);


replace that with this:


type = GetNumericalType(input);



Then you should be good to go. I may have made a slight mistake because I wrote this stuff down in a crappy editing program. If you get any errors after this let me know.

Also, if you're still getting "Variable distance might not have been initialized" error, instead of defining distance as


int distance;


write it as


int distance = 69; //yolo


I think I covered everything......
Title: Re: Trouble with javascript homework
Post by: nate on September 15, 2013, 09:37:56 PM
THANKS SO MUCH IT FINALLY WORKED ;D ;D
Title: Re: Trouble with javascript homework
Post by: Kryptonite on September 16, 2013, 12:29:55 AM
Yay :D