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

Une solution pour le projet. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 25 additions & 16 deletions src/main/java/com/openclassrooms/ideinstall/QuizExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,40 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.commons.codec.binary.Base64;
import java.util.ArrayList;
import java.util.Random;

import ij.IJ;
import ij.ImagePlus;

public class QuizExample {

public static void main(String[] args) throws IOException, InterruptedException {
final int compteARebours = 5;
System.out.println("Compte à rebours !")
for (int i = compteARebours; i <= compteARebours; i--) {
System.out.println("--> " + i);
Thread.sleep(1000);
}
final Path cheminImage = cheminFichier(choixSecret());
ArrayList<String> animals = new ArrayList<String>();
animals.add("hibou");
animals.add("lama");
animals.add("lapin");
animals.add("oiseau");
animals.add("renard");

final Path cheminImage = cheminFichier(animals.get(choixSecret()));
final ImagePlus imp = IJ.openImage(cheminImage.toString());
imp.show();Files.delete(cheminImage);Files.delete(cheminImage.getParent());
imp.show();
Files.delete(cheminImage);
Files.delete(cheminImage.getParent());
}

public static String choixSecret() {return new String(Base64.decodeBase64("bGFwaW4="));}
public static int choixSecret() {
return (int) (Math.random() * 4.99); // Mettre 5 aurait pu lancer une Exception, (� tr�s faible probabilit�, si
// Math.RANDOM = 1 .) JAVA tronque le r�sultat, ce qui garantit
// un r�sultat de maximum 4.
}

public static Path cheminFichier(String image) throws IOException {
final String nomImage = image + ".jpg";
final Path tmpDir = Files.createTempDirectory(image);
final Path cheminFichier = tmpDir.resolve(nomImage);
Files.copy(QuizExample.class.getClassLoader().getResourceAsStream(nomImage), cheminFichier);
return cheminFichier;}
final String nomImage = image + ".jpg";
final Path tmpDir = Files.createTempDirectory(image);
final Path cheminFichier = tmpDir.resolve(nomImage);
Files.copy(QuizExample.class.getClassLoader().getResourceAsStream(nomImage), cheminFichier);
return cheminFichier;
}
}