Java x,y坐标的难度
我试图解决梁的书中的一个问题,我做了大部分工作,但我不理解x和y坐标的部分。我有两个类TestRegularPolygon,它是RegularPolygon的驱动程序类。该区域的公式目前不正确,我将稍后处理。我正在使用eclipse,代码正在编译和运行,如果有人能给我一些方法,我将不胜感激 几何图形:n边正多边形中的n边正多边形所有边 具有相同的长度且所有角度具有相同的度数,即多边形为 等边和等角的。设计一个名为RegularPolygon的类 包含: 名为n的专用int数据字段,用于定义多边形中的边数 默认值为3。 一个名为side的私有双数据字段,用于存储具有 默认值为1。 名为x的专用双数据字段,用于定义中心的x坐标 默认值为0的多边形的。 名为y的专用双数据字段,用于定义中心的y坐标 默认值为0的多边形的。 创建具有默认值的正多边形的无参数构造函数。 创建具有指定边数的正多边形的构造函数 边的长度,以0,0为中心。 创建具有指定边数的正多边形的构造函数, 边的长度以及x坐标和y坐标。 所有数据字段的访问器和mutator方法。 返回多边形周长的方法GetPermiture。 返回多边形面积的方法getArea。计算公式 计算正多边形的面积是非常困难的 绘制类的UML图。实现这个类。编写一个测试程序 创建三个常规多边形对象,使用无参数构造函数创建, 使用RegularPolygon 6,4和RegularPolygon 10,4,5.6, 7.8. 对于每个对象,显示其周长和面积Java x,y坐标的难度,java,Java,我试图解决梁的书中的一个问题,我做了大部分工作,但我不理解x和y坐标的部分。我有两个类TestRegularPolygon,它是RegularPolygon的驱动程序类。该区域的公式目前不正确,我将稍后处理。我正在使用eclipse,代码正在编译和运行,如果有人能给我一些方法,我将不胜感激 几何图形:n边正多边形中的n边正多边形所有边 具有相同的长度且所有角度具有相同的度数,即多边形为 等边和等角的。设计一个名为RegularPolygon的类 包含: 名为n的专用int数据字段,用于定义多边形
public class RegularPolygon
{
private int n; //number of sides of the polygon
private double side; //store the length of the side
private double x; // x coordinate
private double y; //y coordinate
RegularPolygon()
{
n = 3;
side = 1;
x = 0;
y = 0;
}
RegularPolygon(int n, double side)
{
this.n = n;
this.side = side;
x = 0;
y = 0;
}
RegularPolygon(int n, double side, double x, double y)
{
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
public void setN(int then)
{
n = then;
}
public int getN()
{
return n;
}
public void setSide(double theside)
{
side = theside;
}
public double getSide()
{
return side;
}
public void setX(int thex)
{
x = thex;
}
public double getX()
{
return x;
}
public void setY(int they)
{
y = they;
}
public double getY()
{
return y;
}
public double getPerimeter()
{
return n * side;
}
public double getArea()
{
return (n * side) * 5;
}
}
public class TestRegularPolygon
{
public static void main(String[] args)
{
RegularPolygon mypol = new RegularPolygon(6, 4);
System.out.println("the area is: " + mypol.getArea() + " the perimeter is " + mypol.getPerimeter());
RegularPolygon yourpol = new RegularPolygon(10, 4, 5.6, 7.8);
System.out.println("the area is: " + yourpol.getArea() + " the perimeter is " + yourpol.getPerimeter());
}
}
为什么要用x和y来计算呢
我希望你能管理好周边
至于x,y,这里的问题只是心理上的。您已经准备好了用于设置和获取的工具,但您并没有真正使用它们。按原样想象你的类稍后将用于。。。绘制多边形。然后您将需要这些x,y。首先,您应该处理问题的格式。第二,你应该更准确地回答你的问题:你在理解算法方面有问题吗?难道你不知道如何实现算法吗?大多数人在回答一个问题时可能会犹豫不决,因为问题很模糊,有些人只是发布了一系列需求和大量代码。你越精确越好,得到的答案也越多。你真正的问题是什么?您在上面的问题描述中所说的就是它和具有x和y坐标的零件。这表明你一开始并没有真正理解这个问题,这使得你很难清楚地提出关于这个问题的问题,这使得其他人无法回答你的问题。如果你不能提出比这更好的具体问题,如果你不明确地告诉一台计算机该做什么,你会非常失败的。人们,不要对他太严格。他诚实地编写了代码,但不明白它的用途。显然,他没有那么好的老师。让我们做得更好。我想建议你用一天的时间,用一个局外人的眼光重新阅读你的问题,这比你想象的要容易——你想要回答什么问题,具体来说?如果有一个真正的问号,这对我们有很大的帮助?在问题的某个地方,引导我们找到需要回答的一句话。我明白了,你的答案是正确的。有什么问题?我向你们投了一张不接近的票,我不知道x和y坐标的重复是如何工作的,问题只是心理上的。您设置了x,y,但实际上并没有使用它们。按原样想象你的类稍后将用于。。。绘制多边形。那么你需要这些x,y,干杯,甘努斯,我现在明白了。谢谢你们抽出时间,我真的很感激!
public class Exercise89A {
private int n; //number of sides of the polygon
private double side; //store the length of the side
private double x; // x coordinate
private double y; //y coordinate
public static void main(String[] args) {
Exercise89A defaultpol = new Exercise89A();
System.out.println("the area is: " + defaultpol.getArea() + " the perimeter is " + defaultpol.getPerimeter());
Exercise89A mypol = new Exercise89A(6, 4);
System.out.println("the area is: " + mypol.getArea() + " the perimeter is " + mypol.getPerimeter());
Exercise89A yourpol = new Exercise89A(10, 4, 5.6, 7.8);
System.out.println("the area is: " + yourpol.getArea() + " the perimeter is " + yourpol.getPerimeter());
}
Exercise89A() {
n = 3;
side = 1;
x = 0;
y = 0;
}
Exercise89A(int n, double side){
this.n = n;
this.side = side;
x = 0;
y = 0;
}
Exercise89A(int n, double side, double x, double y){
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
public void setN(int newn){
n = newn;
}
public int getN(){
return n;
}
public void setSide(double newside){
side = newside;
}
public double getSide(){
return side;
}
public void setX(int newx){
x = newx;
}
public double getX(){
return x;
}
public void setY(int newy){
y = newy;
}
public double getY(){
return y;
}
public double getPerimeter(){
return n * side;
}
public double getArea(){
double s2 = side * side;
double pin = Math.PI/n;
double tangent = Math.tan(pin);
return (n*s2)/(4*tangent);
}
}
public class Exercise89A {
private int n; //number of sides of the polygon
private double side; //store the length of the side
private double x; // x coordinate
private double y; //y coordinate
public static void main(String[] args) {
Exercise89A defaultpol = new Exercise89A();
System.out.println("the area is: " + defaultpol.getArea() + " the perimeter is " + defaultpol.getPerimeter());
Exercise89A mypol = new Exercise89A(6, 4);
System.out.println("the area is: " + mypol.getArea() + " the perimeter is " + mypol.getPerimeter());
Exercise89A yourpol = new Exercise89A(10, 4, 5.6, 7.8);
System.out.println("the area is: " + yourpol.getArea() + " the perimeter is " + yourpol.getPerimeter());
}
Exercise89A() {
n = 3;
side = 1;
x = 0;
y = 0;
}
Exercise89A(int n, double side){
this.n = n;
this.side = side;
x = 0;
y = 0;
}
Exercise89A(int n, double side, double x, double y){
this.n = n;
this.side = side;
this.x = x;
this.y = y;
}
public void setN(int newn){
n = newn;
}
public int getN(){
return n;
}
public void setSide(double newside){
side = newside;
}
public double getSide(){
return side;
}
public void setX(int newx){
x = newx;
}
public double getX(){
return x;
}
public void setY(int newy){
y = newy;
}
public double getY(){
return y;
}
public double getPerimeter(){
return n * side;
}
public double getArea(){
double s2 = side * side;
double pin = Math.PI/n;
double tangent = Math.tan(pin);
return (n*s2)/(4*tangent);
}
}