Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with documentation and comments on this two class code can anyone he

ID: 3836387 • Letter: I

Question

                                  I need help with documentation and comments on this two class code

                                      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. Please see the documentation and style guidlines on the class website.

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

The documentation and style guidelines to be followed here is not provided.

I have tried to answer this with general JavaDoc guidelines.

For the class, please write a 2 line description about the
class in the comments section.
Similarly, for the methods, write the comments in the respective
comments at the top of the method.

/**
* This is a GPS program
* @author
* @version
* @since
*/

public class GPS
{
   private Heading direction;
   private CSC142Point location;

   /**
   * This is the constructor for this class initializing the
   * member variables.
   */
   public GPS(Heading currentDir, CSC142Point currentLoc)
{
       if(currentDir == null || currentLoc == null)
       {
           direction = currentDir;
           location = currentLoc;
       }
       else throw new NullPointerException();
   }

   /**
   * Move method -------
   * @param units This is the only input parameter to this method.
   * @return void This method does not return anything.
   */
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);
       }
   }
  
   /**
   * Turn Method -----------------
   * @param   degrees This is the only input parameter to this method.
   * @return void This method does not return anything.
   */
   public void turn(double degrees)
{
       if(degrees<-180 || degrees>180)
           throw new IllegalArgumentException();
       else
           direction.setHeading(direction.getHeading() + degrees);
   }
  
   /**
   * Heading Method -------------
   * Get the Heading Information.
   */
   public Heading getHeading()
   {
       return direction;
}

   /**
   * getLocation Method ------------
   * Get the Location information
   */
   public CSC142Point getLocation(){
       return location;
   }
}

Here the second one

/**
* This is the Heading class.
*/
public class Heading {
private double degree;
  
   /**
   * Heading Method - sets the Heading based on the
   * input degree value.
   * @param initialDegrees Only input parameter here
   * @return void - Does not return anything.
   */
   public void Heading(double initialDegrees) {
setHeading(initialDegrees);
}
  
   /**
   * getHeading Method - Returns the degree information.
   */
public double getHeading() {
return degree;
}

   /**
   * setHeading Method - Sets the degree value
   * based on the update.
   * @param update New degree value
   * @return - Returns nothing.
   */
public void setHeading(double update)
{
if(update <0 || update >360){
throw new IllegalArgumentException();
}
else {
this.degree = update;
}
}
  
   /**
   * getBearing Method - Returns information about the bearing value.
   */
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;
}
  
   /**
   * toString - Overloaded Method to convert the input based on our requirement.
   * @return - String
   */
public String toString()
{
return "compass degree = " + degree;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote