Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version simplissime #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Bonjour,

J'ai fait concis... Un peu aride, m�me... Il y a pas de po�sie
dans mon code... C'est vraiment un truc bateau... En revanche
�a Foo Bar au Qix ce week-end.

Sur ce, bonne nuit...

PS: pour lancer le bidule, ./foobarqix sous Unix, �a devrait le
faire (euh... chmod +x foobarqix avant, j'avoue que j'ai pas fait
de Maven... Pour tout dire, j'ai pass� plus de temps sur le script
que sur le Java).

Je crois que j'ai -1 point pour la derni�re remarque :-)

Ah, au fait, c'est la premi�re fois que j'utilise GIT :-) Trop cool...

William.

6 changes: 6 additions & 0 deletions foobarqix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
mkdir bin 2>/dev/null
javac -d bin -encoding ISO8859-1 src/ch/genevajug/FooBarQix.java
cd bin
java ch.genevajug.FooBarQix
cd ..
49 changes: 49 additions & 0 deletions src/ch/genevajug/FooBarQix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package ch.genevajug;

public class FooBarQix {

static public final String FOO = "Foo";
static public final String BAR = "Bar";
static public final String QIX = "Qix";

/**
* Calcule la cha�ne bas�e sur la r�gle du jeu.
* <p>
* <ul>
* <li>Si le nombre est divisible par 3 ou contient 3, �crire "Foo" � la place de 3.</li>
* <li>Si le nombre est divisible par 5 ou contient 5, �crire "Bar" � la place de 5.</li>
* <li>Si le nombre est divisible par 7 ou contient 7, �crire "Qix" � la place de 7.</li>
* </ul>
* </p>
*
* @param i le nombre � calculer
* @return la cha�ne correspondante.
*
*/
public String compute( int i ){
StringBuffer buf = new StringBuffer();
if (i % 3 == 0) buf.append( FOO );
if (i % 5 == 0) buf.append( BAR );
if (i % 7 == 0) buf.append( QIX );

String str = String.valueOf(i);
if (str.indexOf("3") >= 0) buf.append( FOO );
if (str.indexOf("5") >= 0) buf.append( BAR );
if (str.indexOf("7") >= 0) buf.append( QIX );

return (buf.length() > 0 ? buf.toString() : str);
}

/**
* Simply run this to have your FooBarQix...
*
* @param No arguments expected.
*/
public static void main(String[] args) {
FooBarQix fbq = new FooBarQix();
for(int i = 1; i <= 100; i++ ){
System.out.println( fbq.compute( i ) );
}
}

}