Skip to content

Commit

Permalink
primer commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ezequieljsosa committed Dec 28, 2020
1 parent 5e94401 commit 92da8c7
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 1 deletion.
187 changes: 187 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,162 @@
# Created by https://www.toptal.com/developers/gitignore/api/java-web,maven,intellij+all,eclipse,netbeans,java
# Edit at https://www.toptal.com/developers/gitignore?templates=java-web,maven,intellij+all,eclipse,netbeans,java

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Annotation Processing
.apt_generated/
.apt_generated_test/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project

### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Java ###
# Compiled class file
*.class

Expand All @@ -21,3 +180,31 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Java-Web ###
## ignoring target file
target/

### Maven ###
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

### NetBeans ###
**/nbproject/private/
**/nbproject/Makefile-*.mk
**/nbproject/Package-*.bash
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

# End of https://www.toptal.com/developers/gitignore/api/java-web,maven,intellij+all,eclipse,netbeans,java
7 changes: 6 additions & 1 deletion README.md
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"
```
25 changes: 25 additions & 0 deletions pom.xml
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>
26 changes: 26 additions & 0 deletions src/main/java/ar/org/cpci/encuesta/Encuesta.java
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;
}
}
92 changes: 92 additions & 0 deletions src/main/java/ar/org/cpci/encuesta/Main.java
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");
}

}
31 changes: 31 additions & 0 deletions src/main/java/ar/org/cpci/encuesta/Pregunta.java
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;
}
}
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);
}
}
Loading

0 comments on commit 92da8c7

Please sign in to comment.