Jump to content

looking for help on java

buklu

1. Be sure to double check the names of your variables (I see 'radius' and 'raidus', not sure if both are meant to be the same one).

2. On your "getRaidus" method, you declared this method as being a  'void' method, but you are using a return command. This doesn't match. You use 'void', if you are making a method that doesn't return anything, but you would use 'return' if you called on this method from somewhere else and needed to return a variable of some sorts.

 

I'm not sure what you are doing here, but I think in the 'getRaidus' method, you might just want to give your variable a value, or display it. Not use return.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

You are declaring  the "getRadus()" and "computeCir()" methods inside of the constructor "Ring(double raidus)". Move them after the closing "}" of the constructor.

My boring Github   /人◕ ‿‿ ◕人\

Link to comment
Share on other sites

Link to post
Share on other sites

This is what you are looking for:

public class Ring {
  // This is a field of Ring object
  private final double radius;

  // This is a contstructor
  public Ring(final double radius) {
    this.radius = radius;
  }

  // This is a method. Note the 'double' return type.
  public double getRadius() {
    return this.radius;
  }

  // This is also a method. Note the 'return' keyword.
  public double computeCir() {
    return 2 * Math.PI * this.radius;
  }
}
  1. Watch for typos. Method names and variable names must match between definition and access.
  2. Java does not allow nested method definitions.
  3. To avoid confusion, I recommend referring to instance variables (fields) with "this." prefix. 
  4. Things that are not supposed to mutate should be marked immutable explicitly using 'final' keyword.
  5. Methods must have return types. Your code sample was using void in places. Void means "returns nothing".
  6. Return keyword is mandatory in Java.

Also, try to write code incrementally while learning and avoid copy pasting - write small chunks, test if it works, repeat. Otherwise you end up with several unrelated issues that might be confusing to fix.

 

Working example: https://repl.it/repls/FatherlyFairAggregators

Link to comment
Share on other sites

Link to post
Share on other sites

Brackets brackets brackets. Your constructor has unclosed brackets. 

 

Void in the first function should be double. 

 

The last function has spelling error. Or rather, your instance variable has spelling error.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

This is exactly why i don't get devs that don't use an editor with intellisense of some sort.

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Franck said:

This is exactly why i don't get devs that don't use an editor with intellisense of some sort. 

Or atleast always write close <type> immediately when they write open <type>.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, Franck said:

This is exactly why i don't get devs that don't use an editor with intellisense of some sort.

Can you elaborate?

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Addvilz said:

Can you elaborate?

Autocorrect and completion show you these kind of errors right away.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×