Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class PointCP { / / Instance variables * * * * * * * * * * * * * * * * *
public class PointCP
Instance variables
Contains Cartesian or Polar to identify the type of
coordinates that are being dealt with.
private char typeCoord;
Contains the current value of X or RHO depending on the type
of coordinates.
private double xOrRho;
Contains the current value of Y or THETA value depending on the
type of coordinates.
private double yOrTheta;
Constructors
Constructs a coordinate object, with a type identifier.
public PointCPchar type, double xOrRho, double yOrTheta
iftype C && type P
throw new IllegalArgumentException;
this.xOrRho xOrRho;
this.yOrTheta yOrTheta;
typeCoord type;
Instance methods
public double getX
iftypeCoord C
return xOrRho;
else
return MathcosMathtoRadiansyOrTheta xOrRho;
public double getY
iftypeCoord C
return yOrTheta;
else
return MathsinMathtoRadiansyOrTheta xOrRho;
public double getRho
iftypeCoord P
return xOrRho;
else
return MathsqrtMathpowxOrRho Math.powyOrTheta;
public double getTheta
iftypeCoord P
return yOrTheta;
else
return Math.toDegreesMathatanyOrTheta xOrRho;
Converts Cartesian coordinates to Polar coordinates.
public void convertStorageToPolar
iftypeCoord P
Calculate RHO and THETA
double temp getRho;
yOrTheta getTheta;
xOrRho temp;
typeCoord P; Change coord type identifier
Converts Polar coordinates to Cartesian coordinates.
public void convertStorageToCartesian
iftypeCoord C
Calculate X and Y
double temp getX;
yOrTheta getY;
xOrRho temp;
typeCoord C; Change coord type identifier
Calculates the distance in between two points using the Pythagorean
theorem C A B Not needed until E
@param pointA The first point.
@param pointB The second point.
@return The distance between the two points.
public double getDistancePointCP pointB
Obtain differences in X and Y sign is not important as these values
will be squared later.
double deltaX getX pointB.getX;
double deltaY getY pointB.getY;
return Math.sqrtMathpowdeltaX Math.powdeltaY;
Rotates the specified point by the specified number of degrees.
Not required until E
@param point The point to rotate
@param rotation The number of degrees to rotate the point.
@return The rotated image of the original point.
public PointCP rotatePointdouble rotation
double radRotation Math.toRadiansrotation;
double X getX;
double Y getY;
return new PointCPC
MathcosradRotation XMathsinradRotation Y
MathsinradRotation XMathcosradRotation Y;
Returns information about the coordinates.
@return A String containing information about the coordinates.
public String toString
return "Stored as typeCoord C
"Cartesian getX getY
: "Polar getRho getTheta
; this is pointcp.java file public class PointCPTest
Class methods
This method is responsible for the creation of the PointCP
object. This can be done in two ways; the first, by using the
command line and running the program using java
PointCPTest
and the second by getting the program to prompt the user.
If the user does not enter a valid sequence at the command line,
the program will prompte him or her.
@param args The coordinate type. P for polar and C for
cartesian.
@param args The value of X or RHO.
@param args The value of Y or THETA.
public static void mainString args
PointCP point;
System.out.printlnCartesianPolar Coordinates Conversion Program";
Check if the user input coordinates from the command line
If he did, create the PointCP object from these arguments.
If he did not, prompt the user for them.
try
point new PointCPargstoUpperCasecharAt
Double.valueOfargsdoubleValue this is pointcp testImplementation of D
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started