Skip to content
Open
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
13 changes: 10 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,8 +14,11 @@ public class TorpedoStore {

private int torpedoCount = 0;

private Random generator;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was good change in the code


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

// update failure rate if it was specified in an environment variable
String failureEnv = System.getenv("IVT_RATE");
Expand All @@ -28,20 +31,24 @@ public TorpedoStore(int numberOfTorpedos){
}
}

/**
* @param numberOfTorpedos
* @return
*/
public boolean fire(int numberOfTorpedos){
if(numberOfTorpedos < 1 || numberOfTorpedos > this.torpedoCount){
new IllegalArgumentException("numberOfTorpedos");
throw new IllegalArgumentException("numberOfTorpedos");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was good that you noticed this

}

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 =this.torpedoCount- numberOfTorpedos;
success = true;
} else {
// simulated failure
Expand Down