Révision 4 petri/src/element/Place.java

Voir les différences:

Place.java
1 1
package element;
2 2

  
3

  
4

  
3 5
public class Place {
4 6
	
5 7
	private int token;
6 8
	
7
	public Place(int token) {
9
	@SuppressWarnings("serial")
10
	public class UndefinedToken extends Exception{
11
		public UndefinedToken() {
12
			super("the token cannot take a value <0");
13
		}
14
		
15
	}
16

  
17
	public Place(int token) throws UndefinedToken{
18
		if(token<0) {
19
			throw new UndefinedToken();
20
		}
8 21
		this.token=token;
9 22
	}
10 23
	
......
31 44
			return false;
32 45
		}
33 46
	}
34
	public static void main(String[] args) {
35
		System.out.println("TEST METHODS PLACE");
36
		
37
		System.out.println(" => method isEmpty()");
38
		Place emptyPlace = new Place(0);
39
		System.out.println("true : "+emptyPlace.isEmpty());
40
		Place notEmptyPlace = new Place(2);
41
		System.out.println("true : "+notEmptyPlace.isEmpty());
42
	
43
		System.out.println(" => method changeToken(int i)");
44
		Place place3 = new Place(3);
45
		place3.changeToken(5);
46
		System.out.println("3 + 5 = "+place3.getToken());
47
		place3.changeToken(-4);
48
		System.out.println("8 - 4 = "+place3.getToken());
49
		
50
		System.out.println(" => method equals()");
51
		Place place1 = new Place(0);
52
		Place place2 = new Place(0);
53
		System.out.println("true : "+place1.equals(place1));
54
		System.out.println("false : "+place1.equals(place2));
55
	}
56 47

  
57 48
}

Formats disponibles : Unified diff