-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterStringChanger.java
64 lines (52 loc) · 1.58 KB
/
CharacterStringChanger.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class Change {
// private int numberOfChanges;
private final char from;
private final char replaced;
public Change (char fromCharacter, char toCharacter) {
// this.numberOfChanges = 0;
this.from = fromCharacter;
this.replaced = toCharacter;
}
public String change(String characterString) {
return characterString.replace(from, replaced);
}
}
import java.util.ArrayList;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class Changer {
private final ArrayList<Change> listChanges;
public Changer() {
listChanges = new ArrayList<Change>();
}
public void addChange(Change change) {
listChanges.add(change);
}
public String change(String charaterString) {
// String returnedString = "";
for (Change ch : listChanges) {
// returnedString = ch.change(charaterString);
charaterString = ch.change(charaterString);
}
// return returnedString;
return charaterString;
}
}
// would not change the first character when temporarily assigning a new String value
// had to change passed in value to change in place.... no idea why