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
11 changes: 9 additions & 2 deletions Lab6-1160300314/src/ladder/LadderGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class LadderGenerator {
/*
Rep invariant:
numberOfLadders is equal to Params.n
numberOfLadders > 0
length is equal to Params.h
length > 0
Abstraction function:
represents a generator can generate ladders with same pedals on them.
Safety from rep exposure:
Expand All @@ -29,11 +31,14 @@ public class LadderGenerator {
/**
* Can generating Params.n ladders in config.
*
* @throws ConfigurationException if config is wrong.
* @throws Exception if config is wrong or length or numberOfLadders <= 0.
*/
public LadderGenerator() throws ConfigurationException {
public LadderGenerator() throws Exception {
this.length = ConfigReader.getConfig(Params.h);
this.numberOfLadders = ConfigReader.getConfig(Params.n);
if (this.length <= 0 || this.numberOfLadders <= 0) {
throw new Exception("length or numberOfLadders <= 0");
}
this.checkRep();
}

Expand All @@ -44,6 +49,8 @@ private void checkRep() {

assert length == numberOfPedals;
assert numberOfLadders == number;
assert number > 0;
assert numberOfPedals > 0;
} catch (ConfigurationException e) {
throw new RuntimeException(e);
}
Expand Down