Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 07:39 AM |
private int temperature;
public String temperature (int temperature) { if (temperature < 0){ return "You need a jacket or you will die"; }else if (temperature < 32){ return "SUPER COLD"; }else if (temperature < 64){ return "Chilly"; }else if (temperature < 80){ return "Warm"; }else if (temperature < 100){ return "Burning"; }else if (temperature < 1000){ return "You are dead lol"; }else return "N/A"; return temperature; } } }--------------------------error is down here and says class interface or enum expected. How do I fix it please?
I am trying to when you type in a number, depending on the number, a message appears. |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 01 Oct 2014 08:24 AM |
well this subforum is for roblox lua, but maybe if you're lucky agentfirefox (or someone else who is good with java) may come along and see this.
a seal walked into a club |
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 10:17 AM |
| Yeah I know lol....anyone? |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 10:59 AM |
I don't know very much java, but it might be because temperature is private, and cannot be accessed within a function?
And maybe you need to remove the final }, that might help.
New code? :
private int temperature;
public String temperature (int temperature) { if (temperature < 0){ return "You need a jacket or you will die"; }else if (temperature < 32){ return "SUPER COLD"; }else if (temperature < 64){ return "Chilly"; }else if (temperature < 80){ return "Warm"; }else if (temperature < 100){ return "Burning"; }else if (temperature < 1000){ return "You are dead lol"; }else return "N/A";
return temperature; } } |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 11:07 AM |
You missed the class definition for your method:
public class temperature{ public static void main(int temperature){ // Your code } } |
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 11:22 AM |
| So how do I fix mine? I am bad with the terms sorry. I am new to Java. |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 11:24 AM |
Let's first look at the function to see what's wrong.
public String temperature (int temperature) { if (temperature < 0){ return "You need a jacket or you will die"; }else if (temperature < 32){ return "SUPER COLD"; }else if (temperature < 64){ return "Chilly"; }else if (temperature < 80){ return "Warm"; }else if (temperature < 100){ return "Burning"; }else if (temperature < 1000){ return "You are dead lol"; }else return "N/A";
return temperature; }
The first thing to notice is the fact that, not only is 'return temperature' not going to be reached, but it isn't even valid. This is because your defined your method as returning a String, whereas temperature is an int.
Now, let's tack on your private variable.
private int temperature;
public String temperature (int temperature) { if (temperature < 0){ return "You need a jacket or you will die"; }else if (temperature < 32){ return "SUPER COLD"; }else if (temperature < 64){ return "Chilly"; }else if (temperature < 80){ return "Warm"; }else if (temperature < 100){ return "Burning"; }else if (temperature < 1000){ return "You are dead lol"; }else return "N/A";
//return temperature; -- commented out }
Now we look at the function in relation with your private variable. Specifically, your function will not use the private variable when accessing temperature. This is because you shadowed the private variable with a local variable within the function (as a parameter). Which means your private variable is useless in this situation.
Last of all, you do not have the definition of your class, as noted by DrMathematica.
/* * File Temp.java */ public class Temp {
public static void main(String[] args) { int temp = Integer.parseInt(args[0]); Temp t = new Temp(); System.out.println(t.temperature(temp)); } // end main method
public String temperature(int temperature) { if (temperature < 0){ return "You need a jacket or you will die"; }else if (temperature < 32){ return "SUPER COLD"; }else if (temperature < 64){ return "Chilly"; }else if (temperature < 80){ return "Warm"; }else if (temperature < 100){ return "Burning"; }else if (temperature < 1000){ return "You are dead lol"; }else return "N/A"; } // end temp method
} // end class
I'm going to eat right now, but I'll check back here when I'm done. |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 01 Oct 2014 12:58 PM |
@OP, and there's the legend himself. told ya he would come.
he's like santa.
a seal walked into a club |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 01:21 PM |
"he's like santa."
Yes. I see you when you're sleeping. I know when you're awake. I know if you've been bad or good. ( ͡º ͜ʖ ͡º)
So be good, for goodness sake! |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 01 Oct 2014 01:50 PM |
oh my.
i feel violated. )':
a seal walked into a club |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 01:58 PM |
You should feel violated
Santa is a anagram for satan |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 02:01 PM |
"Santa is a anagram for satan"
You weren't supposed to figure that out. Crap. |
|
|
| Report Abuse |
|
|
Fedorakid
|
  |
| Joined: 17 Jul 2010 |
| Total Posts: 7079 |
|
|
| 01 Oct 2014 02:01 PM |
| Gotta love agentfirefox :-) |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 01 Oct 2014 02:08 PM |
| You should probably add a geater thanidentifyer in your temperature checks because if say it was below 0 then it could return any one of those strings. |
|
|
| Report Abuse |
|
|
Nyxis
|
  |
| Joined: 15 Nov 2012 |
| Total Posts: 3374 |
|
|
| 01 Oct 2014 05:08 PM |
aff is satan confirmed
a seal walked into a club |
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 06:51 PM |
| I am still getting the error class interface or enum expected. |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2014 06:52 PM |
All of that needs to be inside a class. Did you use my example and name the file 'Test.java' ? |
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 06:56 PM |
Also. I am new to m y computer science class so this can't look like it was made by an expert. I used when I basically knew in the original code. Aren't there just a couple of small fixes I can do? Oh and this is a method, not a class.
This has no syntax errors but it wants me to enter a string for temperature. I want to enter and int and have a string returned.....
public int temperature(String temperature, int temp) { if (temp < 0){ return "You need a jacket or you will die"; }else if (temp < 32){ return "SUPER COLD"; }else if (temp < 64){ return "Chilly"; }else if (temp < 80){ return "Warm"; }else if (temp < 100){ return "Burning"; }else if (temp < 1000){ return "You are dead lol"; }else return "N/A"; }
}
|
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
| |
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
| |
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 01 Oct 2014 07:18 PM |
| I am going to bed....someone answer for tomorrow! |
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 01 Oct 2014 07:19 PM |
| I PMd you one that I tested and worked, y u no satisfied :( |
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
|
| 02 Oct 2014 05:08 AM |
| It had an error that said enum interface or class expected by the last bracket. This is all part of a bigger code btw. |
|
|
| Report Abuse |
|
|
|
| 02 Oct 2014 05:19 AM |
Semicolon!! But I doubt that'll be the problem. I know JavaScript, but only the strict basics, so I can't really help you a lot here. Sorry.
|
|
|
| Report Abuse |
|
|
Cheeso135
|
  |
| Joined: 13 Apr 2013 |
| Total Posts: 2016 |
|
| |
|