Skip to content

Commit

Permalink
Merge pull request #3 from simanm02/sonarbranch
Browse files Browse the repository at this point in the history
Sonarbranch
  • Loading branch information
simanm02 authored May 3, 2024
2 parents 1f09036 + f4fe253 commit 97ae5f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/hu/bme/mit/spaceship/TorpedoStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class TorpedoStore {

private int torpedoCount = 0;

private Random generator = new Random();

public TorpedoStore(int numberOfTorpedos){
this.torpedoCount = numberOfTorpedos;

Expand All @@ -30,18 +32,17 @@ public TorpedoStore(int numberOfTorpedos){

public boolean fire(int numberOfTorpedos){
if(numberOfTorpedos < 1 || numberOfTorpedos > this.torpedoCount){
new IllegalArgumentException("numberOfTorpedos");
throw new IllegalArgumentException("numberOfTorpedos");
}

boolean success = false;

// simulate random overheating of the launcher bay which prevents firing
Random generator = new Random();
double r = generator.nextDouble();

if (r >= FAILURE_RATE) {
// successful firing
this.torpedoCount =- numberOfTorpedos;
this.torpedoCount -= numberOfTorpedos;
success = true;
} else {
// simulated failure
Expand Down
Binary file modified target/classes/hu/bme/mit/spaceship/TorpedoStore.class
Binary file not shown.

0 comments on commit 97ae5f0

Please sign in to comment.