Académique Documents
Professionnel Documents
Culture Documents
P a g e | 1/3
1) // A Class that adds up a string based on the ASCII values of its
2) // characters and then returns the binary representation of the sum.
3) public class BinString {
4)
5) public BinString () {}
6)
7) public String convert(String s) {
8) return binarise(sum(s));
9) }
10)
11) public int sum(String s) { if (s=="") return 0;
12) if(s.length()==1)
13) return ((int)(s.charAt(0)));
14)
15) return ((int)(s.charAt(0)))+sum(s.substring(1));
16) }
17)
18) public String binarise(int x) {
19) if (x==0) return "";
20) if(x%2==1) return "1"+binarise(x/2);
21) return "0"+binarise(x/2);
22) }
23) }
Question : Proposez une classe de test nommée BinStringTest permettant de tester deux
méthodes de votre choix de la classe BinString (1,5ptsX2=3pts)
P a g e | 2/3
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
package com.foo;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Bar {
static final Logger logger =LogManager.getLogger(Bar.class.getName());
public boolean doIt() {
logger.entry();
logger.error("Did it again!");
return logger.exit(false);
}
}
P a g e | 3/3