Skip to content

Commit a262548

Browse files
authored
Merge pull request #1 from gms0817/Version-1.0---Barebones
Version 1.0 - Barebones
2 parents 2336ca2 + 4956fa4 commit a262548

File tree

4 files changed

+347
-0
lines changed

4 files changed

+347
-0
lines changed

Central.java

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
import java.text.SimpleDateFormat;
3+
import java.util.Date;
4+
5+
public class Central {
6+
private String input,output;
7+
private String[][] dialogue = new String [20][2];
8+
private static String aiName = "Hope";
9+
private User user = new User();
10+
11+
//Post-Condition: Default constructor
12+
public Central() {
13+
input = "";
14+
output = "";
15+
}
16+
17+
//Post-Condition: Overloaded constuctor
18+
public Central(String i) {
19+
this.input = i;
20+
findResponse();
21+
}
22+
23+
//Post-Condition: Returns dialogue values in array
24+
public String[][] dialogueArray () {
25+
//initialize all elements to 0
26+
int row,col;
27+
for (row = 0; row < dialogue.length; row++)
28+
for(col = 0; col < dialogue[row].length; col++)
29+
dialogue[row][col] = "";
30+
31+
//#1 - Time of day
32+
dialogue[0][0] = "time is";
33+
dialogue[0][1] = String.format("The time is currently: " + getTime());
34+
dialogue[1][0] = "the time";
35+
dialogue[1][1] = String.format("The time is currently: " + getTime());
36+
37+
//#2 - the date
38+
dialogue[2][0] = "day is";
39+
dialogue[2][1] = String.format("Today is: " + getDate());
40+
dialogue[3][0] = "today's date";
41+
dialogue[3][1] = String.format("Today is: " + getDate());
42+
dialogue[4][0] = "today's date";
43+
dialogue[4][1] = String.format("Today is: " + getDate());
44+
45+
//#3 - what is ai name
46+
dialogue[5][0] = "your name";
47+
dialogue[5][1] = String.format("My name is " + getAiName() + ", of course!");
48+
49+
//#4 - what is the user's name
50+
dialogue[6][0] = "my name";
51+
dialogue[6][1] = String.format("Your name is " + user.getName() + ".");
52+
dialogue[7][0] = "who am i";
53+
dialogue[7][1] = String.format("Your name is " + user.getName() + ".");
54+
55+
//#5 - whomade the ai
56+
dialogue[8][0] = "who created you";
57+
dialogue[8][1] = "My creator is Gabriel Serrano.";
58+
dialogue[9][0] = "who made you";
59+
dialogue[9][1] = "My creator is Gabriel Serrano.";
60+
dialogue[10][0] = "who is your";
61+
dialogue[10][1] = "My creator is Gabriel Serrano.";
62+
63+
return dialogue;
64+
}
65+
66+
//Post-Condition: Filters through dialogue elements and returns output
67+
public void findResponse() {
68+
//obtains dialogue array
69+
dialogueArray();
70+
71+
int col = 0;
72+
for(int row = 0; row < dialogue.length; row++) {
73+
//System.out.printf("%d, %d\n",row,col);
74+
if(input.contains(dialogue[row][col])) {
75+
output = dialogue[row][col + 1];
76+
System.out.println(dialogue[row][col + 1]);
77+
break;
78+
}
79+
}
80+
}
81+
82+
83+
//Post-Condition: Returns current time
84+
public String getTime() {
85+
//Uses date class to return date and time
86+
Date date = new Date();
87+
88+
//formats time
89+
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
90+
91+
//displays time
92+
return formatter.format(date);
93+
}
94+
95+
//Post-Condition: Returns current time
96+
public String getDate() {
97+
//Uses date class to return date and time
98+
Date date = new Date();
99+
100+
//formats time
101+
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy.");
102+
103+
//displays time
104+
return formatter.format(date);
105+
}
106+
107+
//Post-Condition: returns ai name
108+
public static String getAiName() {
109+
return aiName;
110+
}
111+
112+
//Post-Condition: Re-assigns a new name to ai
113+
public static void setAiName(String n) {
114+
aiName = n;
115+
}
116+
}

Main.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*Version 1.0 - Welcome to Project Hope
2+
* Current Features:---------------------------------------------------
3+
* 5 Console-Based Interactions with Hope/iris
4+
* Single user per device
5+
* Save user input to computer
6+
*/
7+
8+
import java.util.*; //import java utilities package
9+
10+
public class Main {
11+
//creates scanner
12+
static Scanner input = new Scanner(System.in);
13+
14+
public static void main(String[] args) {
15+
String userInput = ""; //used for later user input
16+
User user = new User(); //temp user
17+
if(User.fileExists() == false) {
18+
newUser();
19+
communicate();
20+
}
21+
22+
else {
23+
System.out.printf("%s, %s.\n","Welcome back",user.getName());
24+
communicate();
25+
26+
}
27+
}
28+
29+
//Post-Condition: Prompts user communication and only stops when user says 'bye'
30+
public static void communicate() {
31+
String userInput;
32+
boolean continueConvo = true;
33+
System.out.println("How may I help you today? ");
34+
do {
35+
userInput = input.nextLine();
36+
if(userInput.contains("bye") || userInput.contains("no")) {
37+
System.out.println("It was nice speaking with you. See you next time!");
38+
continueConvo = false;
39+
}
40+
else {
41+
Central input = new Central(userInput);
42+
//ADD FEATURE: RANDOMIZE DIFFERENT CONTINUE CONVO PHRASES TO REMOVE 'STALE' FEELING
43+
System.out.println("Is there anything I can help you with today?\n");
44+
}
45+
}while(continueConvo);
46+
}
47+
48+
//Post-Condition: Creates new user
49+
public static User newUser() {
50+
//initialize variables
51+
int a;
52+
String n,g;
53+
54+
//Collect basic information from user
55+
System.out.print("Welcome to Project Hope.\nMy Name is Hope, what's your preferred name? ");
56+
n = input.nextLine();
57+
58+
//CHANGE: currently only supporting THREE genders. will add more in future to accommodate.
59+
System.out.print("\nNice to meet you, " + n + ".\nIf you don't mind me asking, what gender do you identify with? ");
60+
g = input.nextLine();
61+
62+
//CHANGE: ADD LIMITER TO 110 MAX
63+
System.out.print("\nNice! Last Question! How old are you? ");
64+
a = input.nextInt();
65+
66+
//create user object
67+
User user = new User(n,g,a);
68+
return user;
69+
}
70+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# Project-Iris
22
Personal AI Companion
3+
/*Version 1.0 - Welcome to Project Hope
4+
* Current Features:---------------------------------------------------
5+
* 5 Console-Based Interactions with Hope/iris
6+
* Single user per device
7+
* Save user input to computer
8+
*/

User.java

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//This is where we will create and process user data
2+
import java.io.File;
3+
import java.io.FileInputStream;
4+
import java.io.FileOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.io.OutputStream;
8+
import java.util.*;
9+
import java.util.prefs.*;
10+
11+
public class User {
12+
//Private fields
13+
private String name;
14+
private Properties userInfo = new Properties();
15+
private Properties aiInfo = new Properties();
16+
private Preferences prefs;
17+
private String gender;
18+
private int age;
19+
20+
//default constructor
21+
public User() {
22+
name = "Unknown";;
23+
gender = "Unknown";
24+
age = 0;
25+
}
26+
27+
//Post-Condition: calls setUser() to assign values to object
28+
public User(String n,String g, int a) {
29+
setUser(n,g,a);
30+
setData(n,g,a);
31+
}
32+
33+
//Post-Condition: Overloaded constructor to store user information and instantiate user object
34+
public void setUser(String n,String g, int a) {
35+
//assigns data to current object's variables
36+
this.name = n;
37+
this.gender = g;
38+
this.age = a;
39+
}
40+
41+
//Post-Condition: Stores data fields into file for later use
42+
public void setData(String name,String gender, int age) {
43+
//set output location
44+
45+
//create string variable using age values to save data
46+
String strAge = "" + age;
47+
48+
//tries to save data / throws exception if failed
49+
try (OutputStream output = new FileOutputStream("user.properties")){
50+
//sets property values
51+
userInfo.setProperty("name", name);
52+
userInfo.setProperty("gender", gender);
53+
userInfo.setProperty("age", strAge);
54+
55+
//saves properties to root folder
56+
userInfo.store(output,null);
57+
58+
/*prints properties
59+
System.out.println(userInfo);*/
60+
61+
} catch (IOException io) {
62+
io.printStackTrace();
63+
}
64+
65+
//stores ai data
66+
try (OutputStream aiOutput = new FileOutputStream("ai.properties")){
67+
//set property values
68+
aiInfo.setProperty("aiName", Central.getAiName());
69+
70+
//save properties file to root folder
71+
aiInfo.store(aiOutput, null);
72+
73+
} catch (IOException io) {
74+
io.printStackTrace();
75+
}
76+
77+
}
78+
79+
//Post-Condition: reads data files and builds object using their values
80+
public void getData() {
81+
try (InputStream input = new FileInputStream("user.properties")) {
82+
//load user properties file
83+
userInfo.load(input);
84+
85+
//assigns values from properties file to current object
86+
this.name = userInfo.getProperty("name");
87+
this.gender = userInfo.getProperty("gender");
88+
String strAge = userInfo.getProperty("age");
89+
this.age = Integer.parseInt(strAge);
90+
Central.getAiName();
91+
92+
} catch (IOException ex) {
93+
ex.printStackTrace();
94+
}
95+
//load ai properties file
96+
try (InputStream input = new FileInputStream("ai.properties")) {
97+
//load properties file
98+
aiInfo.load(input);
99+
100+
//assigns values from properties file to current object
101+
this.name = userInfo.getProperty("name");
102+
Central.setAiName(aiInfo.getProperty("aiName"));
103+
104+
} catch (IOException ex) {
105+
ex.printStackTrace();
106+
}
107+
108+
}
109+
110+
/* //Post-Conditions: assigns default values of settings
111+
public void setPreferences() {
112+
prefs = Preferences.userRoot();
113+
//sets the value
114+
prefs.put();
115+
prefs.put("Gender",gender);
116+
prefs.putInt("Age", age);
117+
}
118+
*/
119+
//Post-Condition: Return boolean value true or false if file exists
120+
public static boolean fileExists() {
121+
File temp = new File("user.properties");
122+
File temp2 = new File("ai.propeties");
123+
boolean exists = (temp.exists() || temp2.exists());
124+
125+
return exists;
126+
}
127+
//Post-Condition: returns the name of the user
128+
public String getName() {
129+
if(fileExists())
130+
getData();
131+
132+
return name;
133+
}
134+
135+
//Post-Condition: returns the gender of the user
136+
public String getGender() {
137+
if(fileExists())
138+
getData();
139+
return gender;
140+
}
141+
142+
//Post-Condition: returns the age of the user
143+
public int getAge() {
144+
if(fileExists())
145+
getData();
146+
return age;
147+
}
148+
149+
//Post-Condition: toString method
150+
public String toString() {
151+
String str = "";
152+
153+
return str;
154+
}
155+
}

0 commit comments

Comments
 (0)