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

Hibajavitas #3

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions src/main/java/hu/bme/mit/spaceship/TorpedoStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TorpedoStore {
private double FAILURE_RATE = 0.0; //NOSONAR

private int torpedoCount = 0;

Random generator = new Random();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ez itt egy komment. Valamit írj majd át.


public TorpedoStore(int numberOfTorpedos){
this.torpedoCount = numberOfTorpedos;
Expand All @@ -31,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
Loading