Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package valentines;
- import java.io.*;
- import java.io.BufferedWriter;
- import java.awt.Component;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.io.IOException;
- import java.io.File;
- import java.io.FileNotFoundException;
- import javax.swing.ImageIcon;
- import javax.swing.JDialog;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.JRadioButton;
- import javax.swing.WindowConstants;
- import java.util.Scanner;
- /*
- @author Kendall Clancy
- */
- public class Valentines
- {
- public static void main(String[] args) throws FileNotFoundException
- {
- System.out.println("Hello! This is a Valentines Day program that takes your personal preference of a match and imports data and finds a match for everyone!");
- System.out.println("This program matches based on your encrypted student ID to other students");
- System.out.println("Note: I took out commas using Excel because I spent so many hours trying to use split for the first time and I eventually got stuck");
- System.out.println("My code only works on my slightly edited .txt files because of array sizes and such");
- System.out.println("");
- System.out.println("Correctly Sorts students into Arrays based on Grade:");
- Valentines bob = new Valentines();
- bob.One();
- }
- public void One () throws FileNotFoundException
- {
- String Name = ""; //1
- String Birthday = ""; //2
- String Grade = ""; //3
- String Gender = ""; //4
- String WhyHere = ""; //5
- String Look4InRel = ""; //6
- String ValTraits = ""; //7
- String LoveLanguage = ""; //8
- String Spontaneous = ""; //9
- String HowOpen = ""; //10
- String Politicz = ""; //11
- String IdealDate = ""; //12
- String DueDate = ""; //13
- String PetLove = ""; //14
- String SaturdayNight = ""; //15
- String Hobbies = ""; //16
- String Vacation = ""; //17
- String Spend = ""; //18
- String Music = ""; //19
- String HelloMatch = ""; //20
- String[] Valentines = {Name,Birthday,Grade,Gender,WhyHere,Look4InRel,ValTraits,LoveLanguage,Spontaneous,HowOpen,Politicz,IdealDate,DueDate,PetLove,SaturdayNight,Hobbies,Vacation,Spend,Music,HelloMatch};
- //String[] bob = {Name};
- Valentines AnnieBot = new Valentines();
- // AnnieBot.Startup();
- AnnieBot.Name(Valentines); //1
- AnnieBot.Birthday(Valentines); //2
- AnnieBot.Grade(Valentines); //3
- AnnieBot.Gender(Valentines); //4
- AnnieBot.WhyHere(Valentines); //5
- AnnieBot.Look4InRel(Valentines); //6
- AnnieBot.ValTraits(Valentines); //7
- AnnieBot.LoveLanguage(Valentines); //8
- AnnieBot.Spontaneous(Valentines); //9
- AnnieBot.HowOpen(Valentines); //10
- AnnieBot.Politicz(Valentines); //11
- AnnieBot.IdealDate(Valentines); //12
- AnnieBot.DueDate(Valentines); //13
- AnnieBot.PetLove(Valentines); //14
- AnnieBot.SaturdayNight(Valentines); //15
- AnnieBot.Hobbies(Valentines); //16
- AnnieBot.Vacation(Valentines); //17
- AnnieBot.Spend(Valentines); //18
- AnnieBot.Music(Valentines); //19
- AnnieBot.HelloMatch(Valentines); //20
- AnnieBot.ReadInFile();
- for (int x = 0; x < 19; x++)
- {
- // System.out.println(Valentines[x]);
- }
- // System.out.println(Valentines[19]);
- System.exit(0);
- }
- public String[] Name (String[] ChangeName)
- {
- String EditNamePane;
- EditNamePane = JOptionPane.showInputDialog //Question 1
- (
- "Enter your name."
- );
- ChangeName[0] = EditNamePane;
- return ChangeName;
- }
- public String[] Birthday(String[] ChangeBirthday)
- {
- JFrame frame = new JFrame("What day is your birthday on?"); //Question 2
- //Drop down menu (combo box)
- Object[] dates =
- {"The 1st",
- "The 2nd",
- "The 3rd",
- "The 4th",
- "The 5th",
- "The 6th",
- "The 7th",
- "The 8th",
- "The 9th",
- "The 10th",
- "The 11th",
- "The 12th",
- "The 13th",
- "The 14th",
- "The 15th",
- "The 16th",
- "The 17th",
- "The 18th",
- "The 19th",
- "The 20th",
- "The 21st",
- "The 22nd",
- "The 23rd",
- "The 24th",
- "The 25th",
- "The 26th",
- "The 27th",
- "The 28th",
- "The 29th",
- "The 30th",
- "The 31st"};
- String Day = (String) JOptionPane.showInputDialog(frame,
- "What day is your birthday on?",
- "Quesiton 2",
- JOptionPane.QUESTION_MESSAGE,
- null,
- dates,
- dates[30]);
- ChangeBirthday[1] = Day;
- return ChangeBirthday;
- }
- public String[] Grade(String ChangeGrade[])
- {
- JFrame frame = new JFrame(""); //Question 3
- //Drop down menu (combo box)
- Object[] Grades = {"Freshman",
- "Sophomore",
- "Junior",
- "Senior",};
- String GradeString = (String) JOptionPane.showInputDialog(frame,
- "What Grade are you in?",
- "Question 3",
- JOptionPane.QUESTION_MESSAGE,
- null,
- Grades,
- Grades[3]);
- ChangeGrade[2] = GradeString;
- return ChangeGrade;
- }
- public String[] Gender(String ChangeGender[])
- {
- JFrame frame = new JFrame("What grade are you in?"); //Question 4
- //Drop down menu (combo box)
- Object[] Genders = {"Male",
- "Female"};
- String Gender = (String) JOptionPane.showInputDialog(frame,
- "What is your gender?",
- "Question 4",
- JOptionPane.QUESTION_MESSAGE,
- null,
- Genders,
- Genders[1]);
- ChangeGender[3] = Gender;
- return ChangeGender;
- }
- public String[] WhyHere(String ChangeWhyHere[])
- {
- JFrame frame = new JFrame(""); //Question 5
- //Drop down menu (combo box)
- Object[] dates = {"Looking for a match",
- "Just having fun",
- "I lost a bet",};
- String Day = (String) JOptionPane.showInputDialog(frame,
- "Why are you looking to be paired with someone?",
- "Question 5",
- JOptionPane.QUESTION_MESSAGE,
- null,
- dates,
- dates[2]);
- ChangeWhyHere[4] = Day;
- return ChangeWhyHere;
- }
- public String[] Look4InRel(String ChangeLook4InRel[])
- {
- JFrame frame = new JFrame(""); //Question 6
- //Drop down menu (combo box)
- Object[] traits = {"Communicaton",
- "Trust",
- "Devotion",
- "Positivity",
- "Mutual Care",};
- String traitselect = (String) JOptionPane.showInputDialog(frame,
- "What do you most look for in a RELATIONSHIP?",
- "Question 6",
- JOptionPane.QUESTION_MESSAGE,
- null,
- traits,
- traits[4]);
- ChangeLook4InRel[5] = traitselect;
- return ChangeLook4InRel;
- }
- public String[] ValTraits(String EditValTraits[])
- {
- JFrame frame = new JFrame(""); //Question 7
- Object[] traits = {"Humor",
- "Intelligence",
- "Loyalty",
- "Courage",
- "Ambition",};
- String traitselect = (String) JOptionPane.showInputDialog(frame,
- "What do you most look for among PEERS?",
- "Question 7",
- JOptionPane.QUESTION_MESSAGE,
- null,
- traits,
- traits[4]);
- EditValTraits[6] = traitselect;
- return EditValTraits;
- }
- public String[] LoveLanguage(String ChangeLoveLanguage[])
- {
- JFrame frame = new JFrame(""); //Question 8
- Object[] languages = {"Quality Time",
- "Physical Touch",
- "Acts of Service",
- "Words of Affirmation",};
- String languageselect = (String) JOptionPane.showInputDialog(frame,
- "What love languge do you most identify with?",
- "Question 8",
- JOptionPane.QUESTION_MESSAGE,
- null,
- languages,
- languages[3]);
- ChangeLoveLanguage[7] = languageselect;
- return ChangeLoveLanguage;
- }
- public String[] Spontaneous(String ChangeSpontaneous[])
- {
- JFrame frame = new JFrame(""); //Question 9
- Object[] spontaneous = {"1 - Not very spontaneous.",
- "2",
- "3 - Somewhat spontaneous",
- "4",
- "5 - Very spontaneous"};
- String spontaneousrating = (String) JOptionPane.showInputDialog(frame,
- "How spontaneous would you say you are?",
- "Question 9",
- JOptionPane.QUESTION_MESSAGE,
- null,
- spontaneous,
- spontaneous[3]);
- ChangeSpontaneous[8] = spontaneousrating;
- return ChangeSpontaneous;
- }
- public String[] HowOpen (String[] ChangeHowOpen)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 10
- //Custom button text
- Object[] options = {"Incredibly Open",
- "More Open",
- "In the middle",
- "More Resilient",
- "Incredibly Resilient"};
- String HowOpen = (String) JOptionPane.showInputDialog(frame,
- "How open are you to new things?",
- "Question 10/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeHowOpen[9] = HowOpen;
- return ChangeHowOpen;
- }
- public String[] Politicz (String[] ChangePoliticz)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 11
- //Custom button text
- Object[] options = {"1-Strongly Liberal",
- "2-Leaning Liberal",
- "3-Centrist",
- "4-Leaning Conservative",
- "5-Strongly Conservative"};
- String Politicz = (String) JOptionPane.showInputDialog(frame,
- "What are your political views in terms of Liberalism to Conservatism? 1-5",
- "Question 11/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangePoliticz[10] = Politicz;
- return ChangePoliticz;
- }
- public String[] IdealDate (String[] IdealDateChange)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 12
- //Custom button text
- Object[] options = {"Movies",
- "Dinner",
- "Video Games",
- "Chill",
- "Walk in the Park"};
- String IdealDate = (String) JOptionPane.showInputDialog(frame,
- "What does your ideal date look like?",
- "Question 12/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- IdealDateChange[11] = IdealDate;
- return IdealDateChange;
- }
- public String[] DueDate (String[] DueDateChange)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 13
- //Custom button text
- Object[] options = {"Immediately.",
- "Later that night",
- "A few days after it's assigned",
- "A little bit before it's due.",
- "The morning of the day it's due."};
- String DueDate = (String) JOptionPane.showInputDialog(frame,
- "You have a large project due in 3 weeks, when do you do it?",
- "Question 13/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- DueDateChange[12] = DueDate;
- return DueDateChange;
- }
- public String[] PetLove (String[] ChangePetLove)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 14
- //Custom button text
- Object[] options = {"1-Animal Worshiper",
- "2-I really like them",
- "3-They're okay",
- "4-I don't like them",
- "5-Dog Catcher"};
- String PetLove = (String) JOptionPane.showInputDialog(frame,
- "1-5 how much of a pet lover are you?",
- "Question 14/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangePetLove[13] = PetLove;
- return ChangePetLove;
- }
- public String[] SaturdayNight (String[] ChangeSaturdayNight)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 15
- //Custom button text
- Object[] options = {"Bright and Early",
- "Noon",
- "Night",
- "Midnight",
- "Whenever I Feel Like"};
- String SaturdayNight = (String) JOptionPane.showInputDialog(frame,
- "If you’re doing something on a saturday, when do you do it?",
- "Question 15/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeSaturdayNight[14] = SaturdayNight;
- return ChangeSaturdayNight;
- }
- public String[] Hobbies (String[] ChangeHobbies)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 16
- //Custom button text
- Object[] options = {"Video Games",
- "Supporting Local Community",
- "Arts And Crafts",
- "Netflix and Relax :^)",
- "DJ"};
- String Hobbies = (String) JOptionPane.showInputDialog(frame,
- "Which of these is your most enjoyed hobby?",
- "Question 16/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeHobbies[15] = Hobbies;
- return ChangeHobbies;
- }
- public String[] Vacation (String[] ChangeVacation)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 17
- //Custom button text
- Object[] options = {"Sports",
- "Relax",
- "Eat Good Food",
- "Discover New Cultures",
- "Go to 5-Star Restaurants"};
- String Vacation = (String) JOptionPane.showInputDialog(frame,
- "What would you like to do on a vacation?",
- "Question 17/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeVacation[16] = Vacation;
- return ChangeVacation;
- }
- public String[] Spend (String[] ChangeSpend)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 18
- //Custom button text
- Object[] options = {"Electronics Store",
- "Grocery Store",
- "Book Store",
- "JCPenny (clothes)",
- "Fancy Restaurant"};
- String Spend = (String) JOptionPane.showInputDialog(frame,
- "If you had $100 what store would you spend it in?",
- "Question 18/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeSpend[17] = Spend;
- return ChangeSpend;
- }
- public String[] Music (String[] ChangeMusic)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 19
- //Custom button text
- ImageIcon Icon = new ImageIcon("C:\\Users\\k.clancy\\Desktop\\Background.jpg");
- Object[] options = {"Country",
- "Rap",
- "Rock",
- "Electronic",
- "Jazz",
- "Classical"};
- String Music = (String) JOptionPane.showInputDialog(frame,
- "What is your least favorite type of music?",
- "Question 19/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[4]);
- ChangeMusic[18] = Music;
- return ChangeMusic;
- }
- /*
- public String[] Populated (String ChangePopulated[])
- {
- JFrame frame = new JFrame("AnyThing");
- //Custom button text
- Object[] options = {"1-Country",
- "2-Small City",
- "3-Fayetteville | Mid Sized City",
- "4-Above Average Sized City",
- "5-New York City | Very Large City"};
- String Populated = (String) JOptionPane.showInputDialog(frame,
- //change that to a string
- "How populated would you like your city that you live in to be?",
- "Question 20/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[3]);
- ChangePopulated[19] = Populated;
- //no need for a temp var, just use what jopt pulls
- return ChangePopulated;
- }
- */
- public String[] HelloMatch (String[] ChangeHelloMatch)
- {
- JFrame frame = new JFrame("AnyThing"); //Question 20
- //Custom button text
- Object[] options = {"Be my Valentine",
- "You are one of a kind",
- "Happy Valentines Day",
- "<3",
- "XOXOXO",
- "You are neat!",
- "Love is in the air",
- "Roses are Red, Violets are Blue",
- };
- String HelloMatch = (String) JOptionPane.showInputDialog(frame,
- "What message would you like to send to your match?",
- "Question 20/20",
- JOptionPane.QUESTION_MESSAGE,
- null,
- options,
- options[7]);
- ChangeHelloMatch[19] = HelloMatch;
- return ChangeHelloMatch;
- }
- public void ReadInFile() throws FileNotFoundException
- {
- Valentines bob = new Valentines();
- /*
- try (Scanner ReaderTimes = new Scanner(new File("All.txt"))) //reads the All file
- {
- String[][] AllData = new String[2634][19]; //array but has 2635
- // setting values to 0
- int counter = 0;
- while (ReaderTimes.hasNextLine())
- {
- AllData [counter][] = (ReaderTimes.nextLine());
- // System.out.println(AllData[counter]);
- counter++;
- }
- }
- */
- try (Scanner ReaderTimes = new Scanner(new File("Kios.txt"))) //reads the Kios file
- {
- String[] KiosDataWithCommas = new String[210];
- String[][] KiosData = new String[192][19]; //array but has 193
- // setting values to 0
- int counter = 0;
- while (ReaderTimes.hasNextLine()) //CODE ONTO ARRAY
- {
- KiosDataWithCommas[counter] = ReaderTimes.nextLine();
- // System.out.println(KiosDataWithCommas[counter]);
- counter++;
- }
- counter = 0;
- String temporary;
- for(int XX = 0; XX <189; XX++) //THIS TRANSFERS THE STUDENT ID
- {
- temporary = KiosDataWithCommas[XX].substring(0,5);
- KiosData[XX][0] = temporary;
- // System.out.println(temporary);
- }
- int FirstPosition =6; int SecondPosition = 7; String TempString; //THIS IGNORES STUDENT ID
- for(int ZZ = 0; ZZ < 189; ZZ++) //THIS IS GOING TO TRANSFER THE OTHER 19 POSITIONS 6,7 to 8,9
- {
- FirstPosition=6;SecondPosition=7;
- for(int WW = 1; WW < 19; WW++)
- {
- TempString = KiosDataWithCommas[ZZ].substring(FirstPosition,SecondPosition); //TEMP STRING EXTRACTING
- KiosData[ZZ][WW] = TempString; //TRANSFER OF EXTRACTION TO MOTHER ARRAY
- FirstPosition+=2;SecondPosition+=2; //INCREASES COORDINATES FOR NEXT EXTRACTION
- }
- }
- bob.Sort_Into_Grades(KiosData);
- } //end try
- }
- public void WriteToFile() throws FileNotFoundException, IOException
- {
- File fout = new File("out.txt");
- FileOutputStream fos = new FileOutputStream(fout);
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
- for (int i = 0; i < 10; i++)
- {
- bw.write("");
- bw.newLine();
- }
- bw.close();
- }
- /* list of names that can match odd balls with celebrities
- Lady Gaga
- Oprah
- Madonna
- Mark Cuban
- Shawn Mendes
- */
- public String[][] Sort_Into_Grades (String[][] KiosData)
- {
- Valentines AnnieBot = new Valentines();
- int Countaire1 = 0;
- int Countaire2 = 0;
- int Countaire3 = 0;
- int Countaire4 = 0;
- for(int Counter = 0; Counter<189; Counter++) //WHILE LOOP TO COUNT HOW MANY ARE OF EACH GRADE
- {
- String WhatGrade = KiosData[Counter][2];
- // System.out.println(WhatGrade);
- if (WhatGrade.equals("1"))
- {
- Countaire1++;
- }
- if (WhatGrade.equals("2"))
- {
- Countaire2++;
- }
- if (WhatGrade.equals("3"))
- {
- Countaire3++;
- }
- if (WhatGrade.equals("4"))
- {
- Countaire4++;
- }
- else if(WhatGrade.equals(null))
- {
- System.out.println("TRERE IS A NULL");
- }
- }
- /*
- System.out.println("HHHHHHHHHHHHHHHHHH");
- System.out.println(Countaire1);
- System.out.println(Countaire2);
- System.out.println(Countaire3);
- System.out.println(Countaire4);
- */
- System.out.println("This is the amount of Freshman Data: " +Countaire1);
- System.out.println("This is the amount of Sophomore Data: " +Countaire2);
- System.out.println("This is the amount of Junior Data: " +Countaire3);
- System.out.println("This is the amount of Senior Data: " +Countaire4);
- System.out.println("");
- System.out.println("26+ hours of my own free time later.. still getting out of bounds errors that kill my program");
- String[][] Grade1 = new String[Countaire1+10][19]; //MAKING ARRAYS BASED ON THE SIZE I FOUND OF GRADES
- String[][] Grade2 = new String[Countaire2+10][19];
- String[][] Grade3 = new String[Countaire3+10][19];
- String[][] Grade4 = new String[Countaire4+10][19];
- Countaire1=0;Countaire2=0;Countaire3=0;Countaire4=0; // RESETS COUNTERS
- for( int Counter = 0; Counter<189;Counter++) //THIS ARRAY MOVES THE PEOPLE INTO DIFFERENT ARRAYS
- {
- String WhatGrade = KiosData[Counter][2];
- if (WhatGrade.equals("1"))
- {
- // int Countaire1_For_Loop = 0;
- for (int Countaire1_For_Loop = 0;Countaire1_For_Loop<19;Countaire1_For_Loop++)
- {
- Grade1[Countaire1][Countaire1_For_Loop] = KiosData[Counter][Countaire1_For_Loop];
- }
- Countaire1++;
- }
- //////////////////////////////
- if (WhatGrade.equals("2"))
- {
- int Countaire2_For_Loop = 0;
- for (int x = 0;x<19;x++)
- {
- Grade2[Countaire2][Countaire2_For_Loop] = KiosData[Counter][Countaire2_For_Loop];
- }
- Countaire2++;
- }
- ///////////////////////////////
- if (WhatGrade.equals("3"))
- {
- int Countaire3_For_Loop = 0;
- for (int y = 0;y<19;y++)
- {
- Grade3[Countaire3][Countaire3_For_Loop] = KiosData[Counter][Countaire3_For_Loop];
- }
- Countaire3++;
- }
- ///////////////////////////////////
- if (WhatGrade.equals("4"))
- {
- int Countaire4_For_Loop = 0;
- for (int z = 0;z<19;z++)
- {
- Grade4[Countaire1][Countaire4_For_Loop] = KiosData[Counter][Countaire4_For_Loop];
- // System.out.println(Grade4[Countaire1]);
- }
- }
- Countaire4++;
- Counter++;
- } //end copying people into different grade arrays! --
- //So now I'm going to print every array and make sure they're working ********************
- ////////////////////////////////THIS IS THE MATCHING PART OK?
- /////////////////////////////// MATCHING FOR GRADE 1
- String TempPlaceHolder1 = "";
- String TempPlaceHolder2 = "";
- int CountMatchPoints = 0; //28 of 1, 75 of 2, 17 of 3, 69 of 4,
- int CountMatchPointsTry = 0;
- String[][] TempMatcher = new String[1][19]; //As of now my plan is to keep one string 1d data in this 2d array and then compare another thing in the second position of the array
- for(int Totes = 0; Totes < 27;Totes++) //THIS IS GOING TO LOOP THE MATCHER TO GRADE ROW LENGTH
- { //start For 1
- for(int a = 0; a <1;a++)
- { //start For 2
- for(int b = 0; b <19;b++)
- { //Start For 3
- TempMatcher[a][b] = Grade1[a][b];
- } //End For 3
- //System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGH" + TempMatcher[0][19]);
- } //End For 2
- ///As of now the 2 pieces of data are in the array, we will begin to match the first piece of data and find the CountMatchPoints score.
- TempPlaceHolder1 = "";
- TempPlaceHolder2 = "";
- for(int Column =0; Column<19;Column++)
- {//Start For 4
- TempPlaceHolder1 = TempMatcher[0][Column];
- // TempPlaceHolder2 = TempMatcher[1][Column];
- if (TempPlaceHolder1.equals(TempPlaceHolder2))
- {
- CountMatchPointsTry++;
- //System.out.println(CountMatchPointsTry);
- }
- }//End For 4
- //Insert if-statement shit regarding counter points
- if (CountMatchPoints < CountMatchPointsTry)
- {
- System.out.println("Altered Best Match!");
- CountMatchPoints = CountMatchPointsTry;
- int BestMarkForMatch = Totes;
- }
- } //End For 1
- return KiosData;
- } //END METHOD
- } //END CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement