-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e94401
commit 92da8c7
Showing
9 changed files
with
414 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# cpci-encuesta | ||
# cpci-encuesta | ||
|
||
``` | ||
mvn compile | ||
mvn exec:java -Dexec.mainClass="ar.org.cpci.encuesta.Main" -Dexec.args="src/main/resources test1" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>cpci-encuesta</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.11.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ar.org.cpci.encuesta; | ||
|
||
import java.util.List; | ||
|
||
public class Encuesta { | ||
|
||
private String nombre; | ||
private List<Pregunta> preguntas; | ||
|
||
|
||
public String getNombre() { | ||
return nombre; | ||
} | ||
|
||
public void setNombre(String nombre) { | ||
this.nombre = nombre; | ||
} | ||
|
||
public List<Pregunta> getPreguntas() { | ||
return preguntas; | ||
} | ||
|
||
public void setPreguntas(List<Pregunta> preguntas) { | ||
this.preguntas = preguntas; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package ar.org.cpci.encuesta; | ||
|
||
import ar.org.cpci.encuesta.repository.EncuestaFindException; | ||
import ar.org.cpci.encuesta.repository.EncuestaRepository; | ||
|
||
import java.io.Console; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Scanner; | ||
|
||
|
||
public class Main { | ||
|
||
public static void main(String [] args) { | ||
|
||
// Inicio del programa y carga de datos iniciales | ||
|
||
|
||
//TODO validar precencia de parametros y existencia de los archivos | ||
String dirEncuestas = args[0]; | ||
String nombreEncuesta = args[1]; | ||
|
||
|
||
// Carga de el/los repositorios y consola | ||
|
||
EncuestaRepository repo = new EncuestaRepository(new File(dirEncuestas)); | ||
Scanner console = new Scanner(System.in); | ||
|
||
|
||
|
||
Encuesta encuesta = null; | ||
try { | ||
encuesta = repo.findEncuestaByName(nombreEncuesta); | ||
} catch (FileNotFoundException fileNotFoundException) { | ||
System.err.println( fileNotFoundException.getLocalizedMessage()); | ||
System.exit(1); | ||
} catch (EncuestaFindException encuestaFindException) { | ||
encuestaFindException.printStackTrace(); | ||
System.err.println( "error reading json"); | ||
System.exit(1); | ||
} | ||
// | ||
|
||
|
||
List<Integer> respuestas = new ArrayList<Integer>(); | ||
|
||
Iterator<Pregunta> iterator = encuesta.getPreguntas().iterator(); | ||
|
||
Pregunta pregunta = iterator.next(); | ||
while (true) { | ||
System.err.println(pregunta.getTexto()); | ||
|
||
List<String> opciones = pregunta.getOpciones(); | ||
opciones.forEach(option -> { | ||
System.err.println( (opciones.indexOf(option) + 1) + ". " + option); | ||
}); | ||
String selected = console.nextLine(); | ||
try { | ||
int selectedOption = Integer.parseInt(selected); | ||
if (selectedOption > 0 && selectedOption <= pregunta.getOpciones().size()){ | ||
respuestas.add(selectedOption); | ||
if(iterator.hasNext()){ | ||
pregunta = iterator.next(); | ||
} else { | ||
break; | ||
} | ||
} else { | ||
System.err.println( "opcion invalida"); | ||
} | ||
} catch (NumberFormatException e) { | ||
System.err.println( "opcion invalida"); | ||
|
||
} | ||
|
||
} | ||
|
||
System.out.println( encuesta.getNombre() ); | ||
respuestas.stream().forEach(x -> { | ||
System.out.println( x ); | ||
}); | ||
|
||
|
||
|
||
|
||
System.err.println("programa terminado"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ar.org.cpci.encuesta; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Pregunta { | ||
|
||
private String texto; | ||
private List<String> opciones; | ||
|
||
public Pregunta() { | ||
this.opciones = new ArrayList<String>(); | ||
} | ||
|
||
public List<String> getOpciones() { | ||
return opciones; | ||
} | ||
|
||
public void setOpciones(List<String> opciones) { | ||
this.opciones = opciones; | ||
} | ||
|
||
public String getTexto() { | ||
return texto; | ||
} | ||
|
||
public void setTexto(String texto) { | ||
this.texto = texto; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/ar/org/cpci/encuesta/repository/EncuestaFindException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ar.org.cpci.encuesta.repository; | ||
|
||
import java.io.IOException; | ||
|
||
public class EncuestaFindException extends Exception { | ||
public EncuestaFindException(IOException ioException) { | ||
super(ioException); | ||
} | ||
} |
Oops, something went wrong.