JAVA定义一个圆获取半径类
答案:5 悬赏:30 手机版
解决时间 2021-02-17 16:27
- 提问者网友:不爱我么
- 2021-02-17 13:12
JAVA定义一个圆获取半径类
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-02-17 13:49
package mycircle.subCircle; //创建包
import java.io.*;
public class CircleClass
{
public static void main(String args[])
{
myCircle cir1=new myCircle(10,10);
mySubCircle subCir=new mySubCircle(20,20,20);
System.out.println("父类中坐标为:" + cir1.getX() + "和" + cir1.getY());
subCir.setR(120);
System.out.println("子类中" + subCir.toString());
}
}
class myCircle
{
float x;
float y;
float r;
myCircle()
{
}
myCircle(float px,float py)
{
x=px;
y=py; //设置圆心位置
r=1; //设置默认半径为1
}
float getY()
{
return y;
}
float getX()
{
return x;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
class mySubCircle extends myCircle
{
mySubCircle(float px,float py,float pr)
{
x=px;
y=py;
r=pr;
}
void setR(float pr)
{
this.r=pr;
}
float getR()
{
return this.r;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
运行成功,运行环境JDK+WinXP
import java.io.*;
public class CircleClass
{
public static void main(String args[])
{
myCircle cir1=new myCircle(10,10);
mySubCircle subCir=new mySubCircle(20,20,20);
System.out.println("父类中坐标为:" + cir1.getX() + "和" + cir1.getY());
subCir.setR(120);
System.out.println("子类中" + subCir.toString());
}
}
class myCircle
{
float x;
float y;
float r;
myCircle()
{
}
myCircle(float px,float py)
{
x=px;
y=py; //设置圆心位置
r=1; //设置默认半径为1
}
float getY()
{
return y;
}
float getX()
{
return x;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
class mySubCircle extends myCircle
{
mySubCircle(float px,float py,float pr)
{
x=px;
y=py;
r=pr;
}
void setR(float pr)
{
this.r=pr;
}
float getR()
{
return this.r;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
运行成功,运行环境JDK+WinXP
全部回答
- 1楼网友:持酒劝斜阳
- 2021-02-17 17:29
package mycircle.subCircle; //创建包
import java.io.*;
public class CircleClass
{
public static void main(String args[])
{
myCircle cir1=new myCircle(10,10);
mySubCircle subCir=new mySubCircle(20,20,20);
System.out.println("父类中坐标为:" + cir1.getX() + "和" + cir1.getY());
subCir.setR(120);
System.out.println("子类中" + subCir.toString());
}
}
class myCircle
{
float x;
float y;
float r;
myCircle()
{
}
myCircle(float px,float py)
{
x=px;
y=py; //设置圆心位置
r=1; //设置默认半径为1
}
float getY()
{
return y;
}
float getX()
{
return x;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
class mySubCircle extends myCircle
{
mySubCircle(float px,float py,float pr)
{
x=px;
y=py;
r=pr;
}
void setR(float pr)
{
this.r=pr;
}
float getR()
{
return this.r;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
import java.io.*;
public class CircleClass
{
public static void main(String args[])
{
myCircle cir1=new myCircle(10,10);
mySubCircle subCir=new mySubCircle(20,20,20);
System.out.println("父类中坐标为:" + cir1.getX() + "和" + cir1.getY());
subCir.setR(120);
System.out.println("子类中" + subCir.toString());
}
}
class myCircle
{
float x;
float y;
float r;
myCircle()
{
}
myCircle(float px,float py)
{
x=px;
y=py; //设置圆心位置
r=1; //设置默认半径为1
}
float getY()
{
return y;
}
float getX()
{
return x;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
return s;
}
}
class mySubCircle extends myCircle
{
mySubCircle(float px,float py,float pr)
{
x=px;
y=py;
r=pr;
}
void setR(float pr)
{
this.r=pr;
}
float getR()
{
return this.r;
}
public String toString()
{
String s="位置为:" + x + "," + y
+"半径为:" + r;
- 2楼网友:七十二街
- 2021-02-17 17:17
分少,不干了。其实这个稍微看看自己都能解决,特别简单啊!
- 3楼网友:往事隔山水
- 2021-02-17 16:14
欢迎广大java爱好者加入群一起讨论:22418652
- 4楼网友:独钓一江月
- 2021-02-17 14:49
分太少了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯