-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.java
70 lines (69 loc) · 3.01 KB
/
script.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
65
66
67
68
69
70
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Random;
import java.awt.datatransfer.StringSelection;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
public class script {
public static void main(String[] args){
Random rm = new Random();
Scanner sc = new Scanner(System.in);
System.out.println("Entrez le mot que vous voulez : ");
String searched_name = sc.nextLine().toUpperCase();
List<String> found_words = new ArrayList<>();
try {
File filename = new File("ods9.txt");
Scanner readf = new Scanner(filename);
while (readf.hasNextLine())
{
String data = readf.nextLine();
if (data.contains(searched_name)){
found_words.add(data);
}
}
} catch (FileNotFoundException e ){
System.out.println("An error has occured !");
e.printStackTrace();
}
if (found_words.isEmpty())
{
System.out.println("Aucun jeu de mot n'a été trouvé avec le mot proposé !");
}
else {
int rd_nb = rm.nextInt(found_words.size());
String final_word = found_words.get(rd_nb);
System.out.println(final_word);
String ask_copy = "Voulez vous copiez votre jeu de mot ? {O:N}: ";
System.out.println(ask_copy);
String copy_answer = sc.nextLine().toUpperCase();
String s = final_word.toUpperCase() + ":" + final_word.toLowerCase();
if (Objects.equals(copy_answer, "O")){
StringSelection stringSelection = new StringSelection(s);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
System.out.println("Le mot a été copié avec succès !");
System.exit(0);
} else if (Objects.equals(copy_answer, "N")){
System.exit(0);
} while (!Objects.equals(copy_answer, "O") || !Objects.equals(copy_answer, "N"))
{
ask_copy = "Veuillez entrer une valeur correcte {O:N} : ";
System.out.println(ask_copy);
copy_answer = sc.nextLine().toUpperCase();
if (Objects.equals(copy_answer, "O")){
StringSelection stringSelection = new StringSelection(s);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
System.out.println("Le mot a été copié avec succès !");
System.exit(0);
} else if (Objects.equals(copy_answer, "N")){
System.exit(0);
}
}
}
}
}