Skip to content

Commit

Permalink
Merge pull request #3 from Peter200204/errors
Browse files Browse the repository at this point in the history
Errors fixed
  • Loading branch information
Peter200204 authored Apr 26, 2024
2 parents fb824e2 + 4c9a08e commit 9609372
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,7 @@ public class TorpedoStore {

private int torpedoCount = 0;

private Random generator = new Random(); //Random won't cause problem here
public TorpedoStore(int numberOfTorpedos){
this.torpedoCount = numberOfTorpedos;

Expand All @@ -30,18 +31,18 @@ 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 9609372

Please sign in to comment.