-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRope.java
64 lines (54 loc) · 1.46 KB
/
Rope.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* The Rope class represents a single coil of rope.
* DO NOT MODIFY THE EXISTING METHODS, You may add additional methods if you wish
*
* @author John Colquhoun & Rouaa Yassin-Kassab
* @since 30/10/2017
* extended by @author
*/
public class Rope {
private int length; //current length of the rope
/**
* A Rope constructor to set the length specified by the manufacturer.
* @param length of the new coil of rope
*
*/
public Rope (int length)
{
if(length <= 0) {
throw new IllegalArgumentException("Length can't be <= 0");
}
this.length = length;
}
/**
* @return current length of the rope
*/
public int getLength ()
{
return length;
}
/**
* set a length of the rope
*/
public void setLength (int len)
{
this.length = len;
}
/**
* This method is used to cut the rope by a specified
* amount. This amount would represent a customer order
* @param amountToCut: This is the length of rope to be cut
* @return true if the rope was cut correctly, false if the amount to cut is bigger than the length of the rope
* IMPORTANT: if the method returns false, the rope is not cut
*/
public boolean cut (int amountToCut)
{
//rope can't be negative length so check the amount to cut is not longer than the rope itself
if (amountToCut <= length)
{
length = length - amountToCut;
return true;
}
return false;
}
}