这是个算圆周的java 把这个程序的calC,calA, displayXY方法编进一个新的class
这个新的class里有fieldr,这个新的class里应该每一个parameter都有个constructor来把半径的值存进r原java如下:publicclassC...
这个新的class里有field r,这个新的class里应该每一个parameter都有个constructor来把半径的值存进r
原java如下:
public class CircleMethod {
public static void main(String[] args) {
double r = Double.parseDouble(args[0]);
double t = Double.parseDouble(args[1]);
System.out.println("r = " + r + ", t = " +t);
double C = calC(r);
double A = calA(r);
System.out.println("C = " + C);
System.out.println("A = " + A);
displayXY(r, t);
}
public static double calC(double r){
return 2*Math.PI*r;
}
public static double calA(double r){
return Math.PI*r*r;
}
public static void displayXY(double r, double t){
double x = r*Math.cos(t);
double y = r*Math.sin(t);
System.out.println("x = " + x +", "+"y = "+y);
}
}
怎么写那个新的class 用如下java程序运行呢:
public class CircleObjApp {
public static void main(String[] args) {
double r = Double.parseDouble(args[0]);
double t = Double.parseDouble(args[1]);
System.out.println("r = " + r + ", t = " +t);
Circle myCircle = new Circle(r);
double C = myCircle.calC();
double A = myCircle.calA();
System.out.println("C = " + C);
System.out.println("A = " + A);
myCircle.displayXY(t); }
}
我意思是新建一个Circle.java然后在那个Circle.java里写这个新的class
求解怎么写这个Circle.java 展开
原java如下:
public class CircleMethod {
public static void main(String[] args) {
double r = Double.parseDouble(args[0]);
double t = Double.parseDouble(args[1]);
System.out.println("r = " + r + ", t = " +t);
double C = calC(r);
double A = calA(r);
System.out.println("C = " + C);
System.out.println("A = " + A);
displayXY(r, t);
}
public static double calC(double r){
return 2*Math.PI*r;
}
public static double calA(double r){
return Math.PI*r*r;
}
public static void displayXY(double r, double t){
double x = r*Math.cos(t);
double y = r*Math.sin(t);
System.out.println("x = " + x +", "+"y = "+y);
}
}
怎么写那个新的class 用如下java程序运行呢:
public class CircleObjApp {
public static void main(String[] args) {
double r = Double.parseDouble(args[0]);
double t = Double.parseDouble(args[1]);
System.out.println("r = " + r + ", t = " +t);
Circle myCircle = new Circle(r);
double C = myCircle.calC();
double A = myCircle.calA();
System.out.println("C = " + C);
System.out.println("A = " + A);
myCircle.displayXY(t); }
}
我意思是新建一个Circle.java然后在那个Circle.java里写这个新的class
求解怎么写这个Circle.java 展开
1个回答
展开全部
public class Circle {
private double r;
public Circle(double r) {
this.r = r;
}
public Circle() {
}
public double calC(){
return 2*Math.PI*r;
}
public double calA(){
return Math.PI*r*r;
}
public void displayXY(double r, double t){
double x = r*Math.cos(t);
double y = r*Math.sin(t);
System.out.println("x = " + x +", "+"y = "+y);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询