Avatar of Legend

Status

User has no status, yet

Bio

User has no bio, yet

Most Recent Posts

<Snipped quote by Legend>

True, but I prided myself on helping the people next to me when they had trouble so it hurts double that I can't with this.


At least it doesn't hurt int.



But you don't know Java, so it's extra not a big deal.
Okay Sven, since that solution kind of opened up a can of worms, I went ahead and repaired all static issues and implemented Perimeter and Area methods in circle. This has been tested with all three shapes and produces correct results.











The only downside is that I don't know what coding practices your class is supposed to follow, but I tried modeling it after what you already had. There are some constructors/methods that do nothing, but those were there before. I tried leaving everything as intact as possible, unless you want me to go in and pull out some of the extraneous stuff.
<Snipped quote by Legend>

Ah, that does make more sense. I figured making new variables would work better, but I totally missed that they were static in the first place.
Geez I always feel like I'm back in class when you come up with a much simpler solution. Bad memories of making a long bit of code for something there was a function in the language for. :/


Yeah, but also analyzing other peoples' code is difficult. The problem is easy to miss when you aren't familiar with the internals.
<Snipped quote by GalaxyRaider>

Well for one, you might be better off getting the length and width in the same place.
Secondly, this might be a different thing with java than I learned, but personally I'd put "width * 2" and "length * 2" instead of "2*width" and "2*length". Not really a problem per say unless java has a hard time with the way you put it.
Third, you're defining length and width as 0. Instead of "templength" and "tempwidth" I'd suggest creating new variables and pulling those instead of trying to apply them back to length and width.
Fourth, it could be an issue of order. Having Rectangle(double length, double width) after defining them as zero could be the problem. Again, I suggest new variables entirely than ones you've already used.
But since I'm not much for Java I bet none of this is applicable.


It's because static methods. They have to be instance methods because otherwise, the class looks at static variables length and width. I mean, you could technically pass this into the static method as a parameter, but that's super convoluted. Otherwise, the static method has absolutely no way to see instances of your class.
Your static methods can't access the members of a class; they can only access static variables. You need to make your methods public but not static so they can be used by instances of the class. Also, the keyword this is not required, but feel free to use it if you want.
Time for Please Help Me Find Out What's Wrong With My Code Because It Is Killing Me 2!
If you don't mind it.
I'm mainly concerned with Shape and Rectangle right now. If I get those, I'll be fine. I get no errors when running this, but my values for the Area and Perimeter are always 0.0 no matter what I do.





Did you not import or initialize the scanner in Circle or Square?
<Snipped quote by Legend>

I won't do much but get in the way.


Only with that attitude!
<Snipped quote by Legend>

Oh, no. That's the level of shenanigans in there. My level is meh.


Meh is still pretty good.
<Snipped quote by Legend>

Reeeaaaaally high.


If your level is high, what do you have to worry about?
<Snipped quote by Legend>

I don't think so. Sounds from here like it's not something on my level.


What level is that?
© 2007-2026
BBCode Cheatsheet