this my coding for question 2. Is it correct what the question wants? thanks for helping. what is abstract class and what it use for?
CODE
public class Vector {
protected double x;
protected double y;
protected Vector()
{
}
public Vector(double X, double Y)
{
x = X;
y = Y;
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public void setXY(double X, double Y)
{
x = X;
y = Y;
}
}
public class StandardVector extends Vector {
public StandardVector()
{
}
public StandardVector(double X, double Y)
{
super(X,Y);
}
public double magnitude()
{
double total, magnitude;
double X = getX();
double Y = getY();
total = Math.pow(x,2)+Math.pow(y, 2);
return magnitude = Math.sqrt(total);
}
}
public class OtherVector extends Vector {
public OtherVector()
{
}
public OtherVector(double X, double Y)
{
super(X,Y);
}
public double magnitude()
{
double X = Math.abs(getX());
double Y = Math.abs(getY());
return x + y;
}
}
public class Test {
public static void main (String[] args)
{
double x,y;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter value for x:");
x = scanner.nextDouble();
System.out.println("Enter value for y:");
y = scanner.nextDouble();
StandardVector myVECTOR = new StandardVector(x,y);
System.out.println(myVECTOR.magnitude());
OtherVector newVECTOR = new OtherVector(x,y);
System.out.println(newVECTOR.magnitude());
}
}
This post has been edited by redzuan: 24 Jul, 2008 - 08:44 PM