#Can someone help me with this Methods Exercise?
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
dont randomly tag ppl plz
your code is flawed versus your assignment
your required to write a method that returns a boolean 😉
do u know how to make a method ?
ok, now on your assignment, what does it say ?
int
uppercase types or usually wrappers of the normal one
so now u got your method, insert your code that u need in there and have it return a boolean
( which means your original int return type needs to change aswell )
depends on the check u code, either it will assume its always true, or always false
or if it's a single line code, just return the check
yep
the type to return must match the returning object / type
maybe because u forgot to copy the calculations over ?
do u see those red lines on the variables ? they either have no access are are unknown
so yeah, the sums are in the wrong area of the code
what's the life cycle of a variable ( basicly where does it end ? )
( dont need to google that, just say if u don't know )
a variable stops at the closing of the bracket or method
void foo(){
int bar;
}
bar only lives inside foo, and stops at }
so if u want to use those sums, u either place them in the method that they are needed, or u make them fields
a field is a variable that can be used over the entire class ( or more )
u probably wont have seen that yet
example is
private int foo;
You are defining the variables in a place where it is local to the main method
Try putting int sumAB, sumBC, sumAC, a, b, c; right before the public static void main(String[] args) { line
Then you won't even need parameters for the triangleCheak method (is that spelled incorrectly intentionally?)
LOL fair
So yeah, put the delcaration of variables right before the main method then remove the parameters inside the method, then try it
Oh, and don't forget to call the method at the end of the main method otherwise it won't execute
You can make the method public boolean triangleCheck()
I don't believe you need that method to be static
OK I got it to work
Make the int's static int a, b, c, . . . and make the triangleCheck() method static again
And remember to put triangleCheck(); in the main method and correct the method name typo
Remove the parameters inside the method declaration
Make it public static boolean triangleCheck() and not public static boolean triangleCheck(int a, int b, int c)
On line 23
Give me a shout when you do it
It's a warning saying you never use the return value of that method anywhere else
So you can probably get rid of return true; on line 29 and replace boolean with void on line 23
Returning void means you don't return anything
Don't get me wrong, you could still complile it, it would just keep that warning
thats just the default coloring from IntelliJ
if you're planning to use this Editor more you can change the Theme
Everyone has there own prefered Theme for these Editors so maby you can find yours :P
look at my colors for example
same code. totally different look
oh, in that way, woops
yea, purple means its a Class Fields
But if you want to look at this in more detail, what you can do is go to File > Settings > Editor > Color Scheme > java
there you find a list with all the defined colors, But also some sample code where you can click on it and see for yourself why it is the color it is