I need help with documentation and comments for this two class code below Any ex
ID: 3836644 • Letter: I
Question
I need help with documentation and comments for this two class code below
Any expert! can anyone help? please!
Documentation, Style
1) Make sure you have documented your classes well. From this assignment on, we will be using JavaDoc style comments for class and method descriptions.
2) Use appropriate style that we've discussed in class. This includes (but not limited to) named constants, indenting, etc.
Here are the two class code
public class GPS
{
private Heading direction;
private CSC142Point location;
public GPS(Heading currentDir, CSC142Point currentLoc)
{
if(currentDir == null || currentLoc == null)
{
direction = currentDir;
location = currentLoc;
}
else throw new NullPointerException();
}
public void move(double units)
{
if(units<0)
throw new IllegalArgumentException();
else{
double deltaX = units*Math.sin(Math.toRadians(direction.getHeading()));
double deltaY = units*Math.cos(Math.toRadians(direction.getHeading()));
location.setX(location.getX() + deltaX);
location.setY(location.getY() + deltaY);
}
}
public void turn(double degrees)
{
if(degrees<-180 || degrees>180)
throw new IllegalArgumentException();
else
direction.setHeading(direction.getHeading() + degrees);
}
public Heading getHeading()
{
return direction;
}
public CSC142Point getLocation() {
return location;
}
}
Here the second one
public class Heading {
private double degree;
public Heading(double initialDegrees) {
setHeading(initialDegrees);
}
public double getHeading() {
return degree;
}
public void setHeading(double update)
{
if(update <0 || update> 360){
throw new IllegalArgumentException();
}
else {
this.degree = update;
}
}
public String getBearing()
{
String bearing = "";
if(degree<180){
bearing += "S ";
}
else {
bearing += "N ";
}
if(degree<180){
bearing += (180 - degree) + " ";
}
else{
bearing += (360 - degree) + " ";
}
if(degree>=90&& degree <270) {
bearing += "E";
}
else {
bearing += "W";
}
return bearing;
}
public String toString()
{
return "compass degree = " + degree;
}
}
Explanation / Answer
------------------------------------------------------------------
Heading Class
/**
* The Heading Class which holds degree and return
* bearing from the degree.
*
* @author (Name of the author)
* @version 1.0
* @since 2017-05-09(your class created date)
*/
public class Heading {
// this param store value of degree
private double degree;
/**
* Constructor which stores initialDegrees to degree.
* @param initialDegrees This will assign to degree for later use.
* @return Nothing.
*/
public Heading(double initialDegrees) {
setHeading(initialDegrees);
}
/**
* This method returns degree when requested.
* @param Nothing.
* @return degree.
*/
public double getHeading() {
return degree;
}
/**
* This method first check condition and then store given data to degree
* If condition becomes true than it will throw an IllegalArgumentException.
* @param update Value that is assign to degree.
* @return Nothing.
* @exception IllegalArgumentException If update falls in given condition.
*/
public void setHeading(double update)
{
if(update <0 || update> 360){
throw new IllegalArgumentException();
} else {
this.degree = update;
}
}
/**
* This is the method which returns bearing according to the degree.
* @param Nothing.
* @return bearing bearing which calculated from degree.
*/
public String getBearing()
{
String bearing = "";
if(degree<180){
bearing += "S ";
} else {
bearing += "N ";
}
if(degree<180){
bearing += (180 - degree) + " ";
} else{
bearing += (360 - degree) + " ";
}
if(degree>=90&& degree <270) {
bearing += "E";
} else {
bearing += "W";
}
return bearing;
}
/**
* This method returns string representation of the degree in specific format.
* @param Nothing.
* @return String degree with some text.
*/
public String toString()
{
return "compass degree = " + degree;
}
}
------------------------------------------------------------------
GPS Class
/**
* The GPS Class
*
* @author (Name of the author)
* @version 1.0
* @since 2017-05-09(your class created date)
*/
public class GPS
{
// direction to hold the current direction
private Heading direction;
// 2-dimensional CSC142Point to store location
private CSC142Point location;
/**
* Constructor which stores current direction and current location.
* @param currentDir This will assign to direction for later use.
* @param currentLoc This will assign to location for later use.
* @return Nothing.
* @exception NullPointerException If currentDir and currentLoc both are not null.
*/
public GPS(Heading currentDir, CSC142Point currentLoc)
{
if(currentDir == null || currentLoc == null)
{
direction = currentDir;
location = currentLoc;
}
else throw new NullPointerException();
}
/**
* This is the method which measures new location points(x, y) based in units provided.
* @param units Used for measure new location.
* @return Nothing.
* @exception IllegalArgumentException If units < 0.
*/
public void move(double units)
{
if(units<0)
throw new IllegalArgumentException();
else {
double deltaX = units*Math.sin(Math.toRadians(direction.getHeading()));
double deltaY = units*Math.cos(Math.toRadians(direction.getHeading()));
location.setX(location.getX() + deltaX);
location.setY(location.getY() + deltaY);
}
}
/**
* This method first check condition and then store given data to direction heading
* If condition becomes true than it will throw an IllegalArgumentException.
* @param degrees Will add to direction heading.
* @return Nothing.
* @exception IllegalArgumentException If degrees falls in given condition.
*/
public void turn(double degrees)
{
if(degrees<-180 || degrees>180)
throw new IllegalArgumentException();
else
direction.setHeading(direction.getHeading() + degrees);
}
/**
* This method return current direction.
* @param Nothing.
* @return direction returns current direction.
*/
public Heading getHeading()
{
return direction;
}
/**
* This method return current location.
* @param Nothing.
* @return location returns current location.
*/
public CSC142Point getLocation() {
return location;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.