import java.awt.*;
import java.io.*;
import java.util.*;
import java.io.FileWriter;
public class OutlineTest{
public static final int ROWS = 10; //you may change this value
public static final int COLS = 7; //you may change this value
public static final int SIZE = 85; //you may change this value
public static final int WAIT = 1000; //you may change this value
public static final int QUESTION = 10; //This is the total number of questions in the survey.
public static final int IDENTLOCALE = 0;
public static final Color IDENTCOLOR = Color.WHITE;
public static final String[] identifiers = {"charname", "V_VS_DV", "SHOES","INVIS_FLY", "LIFE_FREE",
"COLSANDERS","VEY_APOLLO","LAK_CELTIC","CS_MAJOR","SMILE","LOVEFIRST"};
public static void main(String[] args)throws FileNotFoundException {
File inFile = new File("C:/Users/Irena/Desktop/Homework2/sampleinput1.txt");
Scanner scanner;
try {
scanner = new Scanner(inFile);
} catch (Exception e){
System.err.println("File not found: " + e.toString());
return;
}
//OPENS CANVAS: Works correctly
//Mosaic.open(ROWS,COLS,SIZE,SIZE);
//METHOD: LABEL QUESTIONS: Works correctly
//labelQuestions();
ArrayList<String[]> userSurveyData = new ArrayList<String[]>();
String[] userTempSurveyData = new String[11];
while(scanner.hasNextLine()){ //keeps looping until we reach EOF
String[] line = scanner.nextLine().split(": ");
for(int i = 0; i < identifiers.length; i++){
if(line[0].equals(identifiers[i]) && !line[1].equals("")){
userTempSurveyData[i] = line[1]; //stores the data into the correct slot
System.out.print(userTempSurveyData[i]+" ");
}
}
if (line[0].equals("request") && line[1].equals("Submit the survey")) {
userSurveyData.add(userTempSurveyData); //once we have reached the submit, then add the array to the array list.
System.out.println();
for (int j=0; j < 10; j++)
userTempSurveyData[j] = "";
}
}
//newloop(scanner);
//METHOD: SENDS ANSWERS TO CANVAS: Does not work.
//colorAnswers();
//METHOD: WRITEFILE: Does not work.
//exportCSVFile(scanner);
}//end of main
public static void labelQuestions(){
for(int i = 0; i < QUESTION; i++){
Mosaic.drawLabel(i, 0, identifiers[i], IDENTCOLOR);
}
}
/*The following method has two Strings added manually for the sake of testing. If you run it, you'll see
the animation as its supposed to run. In the real version of this method, I want ansers to represent
the answers given to any one of the ten questions asked. I guess that means that answers and names would be more dynamic.
I don't really know how to do this, though, but the testing at the very least shows that my idea of how to get
the colored rectangles to look like they're growing more opaque seems to be correct.*/
public static void colorAnswers(){
String[] answers = {"4", "5", "5", "1", "4", "1"};
String[] names = {"Darth Vader", "Alfredo", "IDK?", "Pancho Villa", "Miguel Hidalgo", "Bob"};
for(int i = 1; i < 7; i++){
if(answers[i-1]=="0"){
Mosaic.getBlue(0,1);
Mosaic.setColor(0, 1, 0, 0, Mosaic.getBlue(0,1)+25);
Mosaic.drawLabel(0, 1, names[i-1], IDENTCOLOR);
}
if(answers[i-1]=="1"){
Mosaic.getBlue(0,2);
Mosaic.setColor(0, 2, 0, 0, Mosaic.getBlue(0,2)+25);
Mosaic.drawLabel(0, 2, names[i-1], IDENTCOLOR);
}
if(answers[i-1]=="2"){
Mosaic.getBlue(0,1);
Mosaic.setColor(0, 3, 0, 0, Mosaic.getBlue(0,3)+25);
Mosaic.drawLabel(0, 3, names[i-1], IDENTCOLOR);
}
if(answers[i-1]=="3"){
Mosaic.getBlue(0,2);
Mosaic.setColor(0, 4, 0, 0, Mosaic.getBlue(0,4)+25);
Mosaic.drawLabel(0, 4, names[i-1], IDENTCOLOR);
}
if(answers[i-1]=="4"){
Mosaic.getBlue(0,1);
Mosaic.setColor(0, 5, 0, 0, Mosaic.getBlue(0,5)+25);
Mosaic.drawLabel(0, 5, names[i-1], IDENTCOLOR);
}
if(answers[i-1]=="5"){
Mosaic.getBlue(0,2);
Mosaic.setColor(0, 6, 0, 0, Mosaic.getBlue(0,6)+25);
Mosaic.drawLabel(0, 6, names[i-1], IDENTCOLOR);
}
Mosaic.delay(WAIT);
}
}//end of colorAnswers
public static void exportCSVFile(Scanner scanner){
//I do not know how to write an array into a CSV file yet, but the following is the information I would want
//to be written in the csv file.
//There would also be a line here, asking for the user to input the name of the csv file to be written.
String[] results = {"","", "", "", "", "", "", "", "", "", ""};
while(scanner.hasNextLine()){
String[] line = scanner.nextLine().split(": ");
for(int i = 0; i < identifiers.length; i++){
if(line[0].equals(identifiers[i])){
if(!(results[i].equals("")))
results[i] += ", ";
results[i] += line[1];
}
}
}
for(int i = 0; i < identifiers.length; i++){
System.out.println(identifiers[i] + ": " + results[i]);
}
}
}//end of class