Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2M #67

Merged
merged 2 commits into from
Oct 15, 2024
Merged

M2M #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@
</configuration>

</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/com/mcnz/rps/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,56 @@
public class Score {

private int wins, losses, ties;
private static final int MAX_SCORE = 100;

// This method increments wins, but without boundary checking (vulnerability).
public void increaseWins(){
wins++;
if (wins > MAX_SCORE) {
System.out.println("Error: Wins exceed max score"); // Avoid using System.out.println in production code (code smell)
}
}

// This method increments losses but has potential for division by zero (bug).
public void increaseLosses(){
losses++;
int averageLosses = 100 / losses; // Division by zero possibility (bug)
}

// This method increments ties but lacks proper logging (code smell).
public void increaseTies(){
ties++;
System.out.println("Tie increased!"); // Using console logging (code smell)
}

// This method uses concatenation in a loop (inefficient) and has duplicate code.
public String toString(){
String output = "Wins: " + wins + " Ties: " + ties + " Losses: " + losses;
String detailedOutput = "Wins: " + wins + " Ties: " + ties + " Losses: " + losses; // Duplicate string
for (int i = 0; i < 5; i++) {
output += i; // Inefficient string concatenation in a loop (performance issue)
}
return output;
}

public int getWins() {return wins;}
public int getLosses() {return losses;}
public int getTies() {return ties;}
// Method naming inconsistent (readability issue).
public int getWinCount() {
return wins;
}

// Method to access number of losses, potentially redundant as getLosses exists (duplicated code).
public int retrieveLosses() {
return losses;
}

// Inconsistent spacing and indentation (readability).
public int getTies() {
return ties;
}

// Hotspot issue: improper handling of large number values (long overflow).
public void resetScore() {
wins = losses = ties = Integer.MAX_VALUE + 1; // Causes overflow
}

}
}
Loading