Need help on this assignment

+1 mahmood attia · November 25, 2014
Write a Point class. A point is represented by (x coordinate, y coordinate) 2 integer variables.
Your class should contain a no-arg constructor and a constructor that takes x and y as
parameters, implement all setters and getters, and override the toString method to print class’s
data.
An ellipse and a line can be viewed as points
Write the Ellipse class that inherits the point class and is represented by 2 foci points, semi-major
axis (half the longest diameter), semi-minor axis (half the shortest diameter) and an eccentricity.
Implement a no-arg constructor, a constructor that takes x1, y1, x2, y2, semi-major and semiminor
axis values as parameters and a constructor that takes 2 Point objects and semi-major and
semi-minor axis values as parameters. Implement the setters and getters, write a getArea()
method and override the toString method to print the class’s data
A circle is a special type of an ellipse
Write the Circle Java class that inherits the Ellipse class. The two foci points of a circle are the
same (so there’s one focus point). The semi-minor axis and semi-major axis are of equal value(
only 1 radius). The eccentricity of a circle is equal to 0. Create the no-arg constructor with
default values, a constructor that takes a radius, x and y as parameters and a third constructor
that takes radius and point object as parameters. Implement the setters and getters
appropriately, override the toString method to return the circle’s radius and its center point. Do
NOT override the getArea() method.
Write the Line class that inherits the point class. A line is represented by a starting point and an
ending point. Your class should inherit the start point and have an instance variable point object
for the end point. Implement a no-arg constructor, a constructor that takes x1, y1, x2, y2 values
as parameters and a constructor that takes 2 point objects as parameters. Implement the setters
and getters and a getDistance() method that computes the length of the line.
Write a test program that creates objects of an Ellipse, a Circle and a Line. Set the needed values
for all of them, call the getArea() method for both the ellipse and the circle, call the getDistance()
method of the line and the toString method of the 3 objects.

Post a Reply

Replies

Oldest  Newest  Rating
0 mahmood attia · November 25, 2014
My problem is that i dont really know whats a semi major/minor axis and the eccentricity.
0 mahmood attia · November 25, 2014
here is my code for the point class :




public class Point {
public int x;
public int y;

public Point () {

x=0;
y=0;
}

public Point (int X,int Y){
X=x;
Y=y;

}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}


public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}


}
0 mahmood attia · November 25, 2014
and this what i wrote for the ellipse class :
public class Ellipse extends Point {

void foci1 (int x1,int y1){
x = x1;
y=y1;


}

void foci2 (int x2,int y2){
x = x2;
y=y2;
}
0 mahmood attia · November 25, 2014
thanks man btw I'm done with that assignment but the program isnt working 
here are the codes

public class Point {
public int x;
public int y;

public Point () {

this.x=0;
this.y=0;
}


public Point(int x, int y) {

this.x = x;
this.y = y;
}


public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}


public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}


}





public class Ellipse extends Point {
public int x1,x2,y1,y2;
public Object foci1(int X,int Y){
x1=X;
return y1=Y;

}
public  Object foci2(int X,int Y){

x2=X;
return y2=Y;
}
public double  semiMajorAxis= Math.sqrt((Math.pow((x2+x1), 2))+(Math.pow((y2+y1),2)));

public double  semiMinorAxis= Math.sqrt((Math.pow((x2+x1), 2))+(Math.pow((y2+y1),2)));

public  double eccentricity=Math.sqrt((1-(Math.pow(semiMinorAxis, 2))/(Math.pow(semiMajorAxis, 2))));

public Ellipse(){
x1=0;
y1=0;
x2=0;
y2=0;
}


public Ellipse(int x, int y, int x1, int x2, int y1, int y2,
double semiMajorAxis, double semiMinorAxis) {
super(x, y);
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
this.semiMajorAxis = semiMajorAxis;
this.semiMinorAxis = semiMinorAxis;
}


public Ellipse( double semiMajorAxis,
double semiMinorAxis, int i, int j) {
super();

this.semiMajorAxis = semiMajorAxis;
this.semiMinorAxis = semiMinorAxis;
}


public int getX1() {
return x1;
}


public void setX1(int x1) {
this.x1 = x1;
}


public int getX2() {
return x2;
}


public void setX2(int x2) {
this.x2 = x2;
}


public int getY1() {
return y1;
}


public void setY1(int y1) {
this.y1 = y1;
}


public int getY2() {
return y2;
}


public void setY2(int y2) {
this.y2 = y2;
}




public double getSemiMajorAxis() {
return semiMajorAxis;
}


public void setSemiMajorAxis(double semiMajorAxis) {
this.semiMajorAxis = semiMajorAxis;
}


public double getSemiMinorAxis() {
return semiMinorAxis;
}


public void setSemiMinorAxis(double semiMinorAxis) {
this.semiMinorAxis = semiMinorAxis;
}


public double getEccentricity() {
return eccentricity;
}


public void setEccentricity(double eccentricity) {
this.eccentricity = eccentricity;
}


public double getArea(){
return Math.PI* getSemiMinorAxis()*getSemiMajorAxis();

}

public String toString() {
return "Ellipse [x1=" + x1 + ", x2=" + x2 + ", y1=" + y1 + ", y2=" + y2
+ ", semiMajorAxis=" + semiMajorAxis + ", semiMinorAxis="
+ semiMinorAxis + ", eccentricity=" + eccentricity
+ ", getX1()=" + getX1() + ", getX2()=" + getX2()
+ ", getY1()=" + getY1() + ", getY2()=" + getY2()
+ ", getSemiMajorAxis()=" + getSemiMajorAxis()
+ ", getSemiMinorAxis()=" + getSemiMinorAxis()
+ ", getEccentricity()=" + getEccentricity() + "]";
}





}





public class Circle extends Ellipse {


public int x,y;
public double radius,focus;
public Circle() {
x1=0;
y1=0;
x2=0;
y2=0;
}
public Circle(int x1, int y1, int x2, int y2) {
super();
this.x = x;
this.y = y;
}
public Circle(double radius, double focus) {
super();
this.radius = radius;
this.focus = focus;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getFocus() {
return focus;
}
public void setFocus(double focus) {
this.focus = focus;
}

public String toString() {
return "Circle [x=" + x + ", y=" + y + ", radius=" + radius
+ ", focus=" + focus + "]";
}

public double getArea(){
return Math.PI* getRadius();

}




}


public class Line extends Point {
public int x1,x2,y1,y2;
public Object startPoint(int X,int Y){
x1=X;
return y1=Y;

}
public  Object endPoint(int X,int Y){

x2=X;
return y2=Y;
}
public Line() {
x1=0;
y1=0;
x2=0;
y2=0;

}

public Line(int x, int y, int x1, int x2) {
super(x, y);
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
public Line(Object i,Object j) {
i= startPoint(x1, 0);
j=endPoint(x2, 0);


}
    




public int getX1() {
return x1;
}
public void setX1(int x1) {
this.x1 = x1;
}
public int getX2() {
return x2;
}
public void setX2(int x2) {
this.x2 = x2;
}
public int getY1() {
return y1;
}
public void setY1(int y1) {
this.y1 = y1;
}
public int getY2() {
return y2;
}
public void setY2(int y2) {
this.y2 = y2;
}

public double getDistance(){

return Math.sqrt((Math.pow((x2+x1), 2))+(Math.pow((y2+y1),2)));


}

}



public class Test {

public static void main ( String args[]){
Line lineObject = new Line(2,1,2,4);
Ellipse EllipseObject = new Ellipse(2,1,2,4);
Circle CircleObject= new Circle(2,1,2,4);

lineObject.toString();
EllipseObject.toString();
CircleObject.toString();

lineObject.getDistance();
EllipseObject.getArea();
CircleObject.getArea();




}




}
  • 1

Java / Android Development

107,026 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator