Skip to content

Commit

Permalink
fixing code format
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonayoder committed Mar 7, 2024
1 parent 27c8b4b commit 9cc1203
Showing 1 changed file with 86 additions and 82 deletions.
168 changes: 86 additions & 82 deletions Docs/grading_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,61 +83,64 @@ Remember: EVERY class must be documented! Above each class, you should include a
## Example of Good Documentation

Here is an example that shows a simple class with “good” style and documentation. This represents complete documentation which will clearly receive full credit on any assignment when style/documentation is part of the grading rubric for the assignment (meaning you wrote 50% or more of the file):

/**
* Class: GoodExample
* @author John Doe
* Purpose: This class demonstrates the proper coding style.
* It contains a method to double any integer value
*
* Use:
* GoodExample firstExample = new GoodExample();
* int doubledValue = firstExample.doubleThatValue(5); //doubledValue should be 10
*/
public class GoodExample {
// This method returns the value passed in doubled
public int doubleThatValue(int incomingVariable) {
return incomingVariable * 2;
}
}//end class GoodExample
```
/**
* Class: GoodExample
* @author John Doe
* Purpose: This class demonstrates the proper coding style.
* It contains a method to double any integer value
*
* Use:
* GoodExample firstExample = new GoodExample();
* int doubledValue = firstExample.doubleThatValue(5); //doubledValue should be 10
*/
public class GoodExample {
// This method returns the value passed in doubled
public int doubleThatValue(int incomingVariable) {
return incomingVariable * 2;
}
}//end class GoodExample
```
## Example of Acceptable Documentation

Here is an example that shows a simple class with “acceptable” style and documentation. This represents the minimum documentation to receive full credit on any assignment when style/documentation is part of the grading rubric for the assignment (meaning you wrote 50% or more of the file):

/**
* Class: GoodExample
* @author John Doe
* Purpose: This class demonstrates the proper coding style and
* contains a method to double any integer value
*/
public class GoodExample {
public int doubleThatValue(int incomingVariable) {
return incomingVariable * 2;
}
}

```
/**
* Class: GoodExample
* @author John Doe
* Purpose: This class demonstrates the proper coding style and
* contains a method to double any integer value
*/
public class GoodExample {
public int doubleThatValue(int incomingVariable) {
return incomingVariable * 2;
}
}
```

## Example of Bad/Good Names

Take a look at the code below and try to determine what is happening.

public int a(int b, int c) {
return (b < c) ? c : b;
}
```
public int a(int b, int c) {
return (b < c) ? c : b;
}
```

This code is not readable. Now consider the same method with better coding conventions:

public int max(int num1, int num2) {
int maxValue = num1;
if(maxValue < num2) {
maxValue = num2;
}
return maxValue;
}
```
public int max(int num1, int num2) {
int maxValue = num1;
if(maxValue < num2) {
maxValue = num2;
}
return maxValue;
}
```

## Example of Method Length

Expand All @@ -146,45 +149,46 @@ For the size of methods, this can be tricky sometimes. Researching this topic on
Also, remember that a method should complete only one task. If you are attempting to do too much in one method, it can quickly grow to an unmanageable mess. In assuring that each method only completes one task, you also assure that the method size remains manageable.

For example, consider the following method to return a letter grade given an array of double values:

public static char getLetterGrade(double[] grades) {
double total = 0;
for (double grade : grades) {
total += grade;
}
double avg = total/grades.length;
char gradeToReturn;
if (avg >= 90.0) {
gradeToReturn = 'A';
} else if (avg >= 80.0) {
gradeToReturn = 'B';
} else {
gradeToReturn = 'F';
}
return gradeToReturn;
}
```
public static char getLetterGrade(double[] grades) {
double total = 0;
for (double grade : grades) {
total += grade;
}
double avg = total/grades.length;
char gradeToReturn;
if (avg >= 90.0) {
gradeToReturn = 'A';
} else if (avg >= 80.0) {
gradeToReturn = 'B';
} else {
gradeToReturn = 'F';
}
return gradeToReturn;
}
```

Even though this method is still quite small, it is apparent that more than this method contains more than just one task. The following better represents the proper coding style when splitting methods:
```
private static double getAvg(double[] grades) {
double total = 0;
for (double grade : grades) {
total += grade;
}
return total/grades.length;
}
public static char getLetterGrade(double[] grades) {
double avg = getAvg(grades);
char gradeToReturn;
if (avg >= 90.0 ) {
gradeToReturn = 'A';
} else if (avg >= 80.0) {
gradeToReturn = 'B';
} else {
gradeToReturn = 'F';
}
return gradeToReturn;
}
private static double getAvg(double[] grades) {
double total = 0;
for (double grade : grades) {
total += grade;
}
return total/grades.length;
}
public static char getLetterGrade(double[] grades) {
double avg = getAvg(grades);
char gradeToReturn;
if (avg >= 90.0 ) {
gradeToReturn = 'A';
} else if (avg >= 80.0) {
gradeToReturn = 'B';
} else {
gradeToReturn = 'F';
}
return gradeToReturn;
}
```

0 comments on commit 9cc1203

Please sign in to comment.