From 450f277dfcfd1a2315e12efbf66ea2039ab05b49 Mon Sep 17 00:00:00 2001 From: Hai Dang <hai-dang.le@etu.univ-amu.fr> Date: Sat, 19 Sep 2020 16:32:05 +0200 Subject: [PATCH] =?UTF-8?q?Updated=20Crossword=20Valeur=20des=20variables?= =?UTF-8?q?=20rows=20et=20collums=20d=C3=A9termin=C3=A9,=20construction=20?= =?UTF-8?q?d'un=20tableau=20de=20dimension=20:rows*collums,=20utilisation?= =?UTF-8?q?=20du=20constructeur=20de=20Crossword=20dans=20la=20class=20Mai?= =?UTF-8?q?n,=20enfin=20visualisation=20du=20tableau=20possible=20grace=20?= =?UTF-8?q?a=20la=20m=C3=A9thode=20display.=20TACHE=201=20FAIT.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tp2/Crossword.java | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tp2/Crossword.java b/tp2/Crossword.java index 110a866..9466705 100644 --- a/tp2/Crossword.java +++ b/tp2/Crossword.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.Scanner; import java.io.*; @@ -22,12 +23,34 @@ public class Crossword ** Updates <rows> and <columns> to height and width of the array. */ public Crossword(File file) throws IOException { + if(!file.exists()){ + System.out.println("le fichier n'existe pas"); + return; + } // Code pour calculer la taille du tableau et initialiser les variables d'instance "rows" et "columns" - + + Scanner scan = new Scanner(file); + + columns = scan.next().length(); + while (scan.hasNextLine()) { + rows++; + scan.nextLine(); + } + // Code pour créer le tableau "array" - - // Code pour remplir "array" avec les caractères du Fichier "file" - + char[][] array = new char[rows][columns]; + + // Code pour remplir "array" avec les caractères du Fichier "file" + Scanner scanner = new Scanner(file); + for (int i = 0; i < rows; i++) { + String fileLine = scanner.nextLine(); + for (int j = 0; j < columns; j++) { + char nextChar = fileLine.charAt(j); + array[i][j] = nextChar; + } + } + this.array = array; + } -- GitLab