What's wrong with my codes

I tried to look again and again at my codes but I couldn't figure out where I was wrong because the result always be displayed by 0

publicclass Circle

{

staticfinaldouble PI=3.14;

privateint radius;

privatedouble area;

public Circle (int r)

{

r=radius;

}

publicvoid setRadius(int rad)

{

rad=radius;

}

publicdouble calculateArea()

{

area=radius*radius*PI;

return area;

}

publicint getRadius()

{

return radius;

}

}

And the driver here

import javax.swing.*;

publicclass TestCircle

{

publicstaticvoid main (String [] args)

{

String input;

int r;

input=JOptionPane.showInputDialog("Enter the radius");

r=Integer.parseInt(input);

Circle myCircle=new Circle(r);

int display =myCircle.getRadius();

double area=myCircle.calculateArea();

System.out.println("Radius is "+display+"\nArea is "+area);

myCircle.setRadius(10);

display =myCircle.getRadius();

area=myCircle.calculateArea();

System.out.println("Radius is "+display+"\nArea is "+area);

}

}

[2695 byte] By [Emotionsa] at [2007-11-27 9:49:25]
# 1
Your setRadius method is broken. You're assinging the field to the argument, when you ought to assign the argument to the field.
paulcwa at 2007-7-13 0:17:55 > top of Java-index,Java Essentials,Java Programming...
# 2
r=radius;?
prometheuzza at 2007-7-13 0:17:55 > top of Java-index,Java Essentials,Java Programming...
# 3
> Your setRadius method is broken. ...And constructor.
prometheuzza at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 4
> Your setRadius method is broken. You're assinging> the field to the argument, when you ought to assign> the argument to the field.Oh yeah, stupid mistakeThanks all you guys :)
Emotionsa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 5

Suggestion: to avoid these mistakes in the future ...

//bad:

class Example {

private int elbow;

public Example (int arse) {

arse = elbow;

}

}

//good:

class Example {

private int elbow;

public Example (int elbow) {

this.elbow = elbow;

}

}

BigDaddyLoveHandlesa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 6
lol **** < = elbow...... ^v^(hey unfair i can't type a r s e but you could in the code?)Message was edited by: roytchaikowsky
roytchaikowskya at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 7

> lol **** < = elbow...... ^v^

> (hey unfair i can't type a r s e but you could in the code?)

The cuss filter doesn't filter within [code] tags:

if (shit.equals(crap)) {

damn = fuck;

} else {

cunt = null;

}

BigDaddyLoveHandlesa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 8
Why can't you type arse? It works fine for me.
_helloWorld_a at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 9
HTML entity trick?
BigDaddyLoveHandlesa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 10
> HTML entity trick?Yep, learned it from cotton.m.
_helloWorld_a at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 11
> > HTML entity trick?> > Yep, learned it from cotton.m.For the record, one types, for example:&#97;rse http://www.w3schools.com/tags/ref_ascii.asp
BigDaddyLoveHandlesa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 12

> > > HTML entity trick?

> >

> > Yep, learned it from cotton.m.

>

> For the record, one types, for example:

>

> arse

>

> http://www.w3schools.com/tags/ref_ascii.asp

Hehe, silly me. I can swear a lot faster now.

_helloWorld_a at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 13

> Suggestion: to avoid these mistakes in the future

> ...

> > //bad:

> class Example {

>private int elbow;

>public Example (int arse) {

>arse = elbow;

>

> }

>

> //good:

> class Example {

>private int elbow;

>public Example (int elbow) {

>this.elbow = elbow;

>

> }

>

Perfect solution, many thanks :)

Emotionsa at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 14
> Perfect solution, many thanks :)Have a read of this which explain one of the problems you were having: http://java.sun.com/docs/books/tutorial/java/javaOO/thiskey.html
_helloWorld_a at 2007-7-13 0:17:56 > top of Java-index,Java Essentials,Java Programming...
# 15

> Perfect solution, many thanks :)

Just curious. Have you completed any homework assignments that you have not posted in the forums?

It's just that too much posting here may stiffle your ability to think on your own, a critical characteristic to have if you want to continue coding in the future.

Message was edited by:

petes1234

petes1234a at 2007-7-21 23:10:05 > top of Java-index,Java Essentials,Java Programming...