作业帮 > 综合 > 作业

求java程序 输出一个圆的圆心是(3.4) 半径是5

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/16 10:56:01
求java程序 输出一个圆的圆心是(3.4) 半径是5
public class Circle{
Point center;
int radius;
public Circle(Point center,int radius){
this.center=center;
this.radius=radius;
}
public int getCenter(){
return this.center;
}
pubic int getRadius(){
return this.radius;
}
public void setCenter(point center){
this.center=center;
}
public void setRadius(int radius){
this.radius=radius;
}
public void printInfo(){
System.out.println()
} 这是程序前半部分 后面要输出圆心是(3.4)半径是5
求java程序 输出一个圆的圆心是(3.4) 半径是5
public void printInfo(){
System.out.println("圆心("+center.x+","+center.y+") 半径:"+radius);
}

public class Test{

public static void main(String[] args){
Circle circle=new Circle(new Point(3,4),5);
circle.printInfo();
}
}
再问: 我前面程序有错吗,怎么编译好多错啊
再答: 完整的如下,记得导入包,我这就不写了 public class Circle { Point center; int radius; public Circle(Point center, int radius) { this.center = center; this.radius = radius; } public Point getCenter() { return this.center; } public int getRadius() { return this.radius; } public void setCenter(Point center) { this.center = center; } public void setRadius(int radius) { this.radius = radius; } public void printInfo() { System.out.println("圆心(" + center.x + "," + center.y + ") 半径:" + radius); } }
再问: 编译时说找不到符号
再答: package com.my.tt;//改为你的包名 import java.awt.Point;//你用的什么包,就导入下面的Point public class Circle { Point center; int radius; public Circle(Point center, int radius) { this.center = center; this.radius = radius; } public Point getCenter() { return this.center; } public int getRadius() { return this.radius; } public void setCenter(Point center) { this.center = center; } public void setRadius(int radius) { this.radius = radius; } public void printInfo() { System.out.println("圆心(" + center.x + "," + center.y + ") 半径:" + radius); } public static void main(String[] args) { Circle circle = new Circle(new Point(3, 4), 5); circle.printInfo(); } }