diff --git a/.gitignore b/.gitignore index 21b4487..dcdceb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Project exclude paths -/out/ \ No newline at end of file +/out/ +.idea diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ deleted file mode 100644 index 3733e0d..0000000 --- a/.idea/$PRODUCT_WORKSPACE_FILE$ +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - 1.8 - - - - - - - - \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 5c98b42..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index e208459..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 00b2095..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/uoft/csc207/week2/Main.java b/src/uoft/csc207/week2/Main.java index 648f0d3..a5f08b0 100644 --- a/src/uoft/csc207/week2/Main.java +++ b/src/uoft/csc207/week2/Main.java @@ -1,10 +1,17 @@ +// password for something +// qq495142 +// ahKi9eegee + package uoft.csc207.week2; public class Main { public static void main(String[] args) { - String[] name = {"First", "Middle", "Last"}; + String[] name = {"Ark", "Jo", "K"}; Person p = new Person(name, "moogah"); + String[] name2 = {"faisal"}; + Person s = new Student(name2, "fai", "1095"); System.out.println(p); + System.out.println(s); } } diff --git a/src/uoft/csc207/week2/Person.java b/src/uoft/csc207/week2/Person.java index 24a57e3..fc7e176 100644 --- a/src/uoft/csc207/week2/Person.java +++ b/src/uoft/csc207/week2/Person.java @@ -6,22 +6,26 @@ class Person { /** The person's name (family name last). */ - String[] name; /** The person's UTORid */ String utorid; + String[] name; /** The person's name */ + String utorid; + /** * Initialize this Person named name with UTORid utorid. * * @param name the person's name (family name last) * @param utorid the person's UTORid */ - Person - (String[] name, String utorid){this.name=name;this.utorid=utorid;} + Person (String[] name, String utorid) { + this.name=name; + this.utorid=utorid; + } /** * Return a string representation of this person with this format: * 'last name, other names: utorid' * @return a string representation of this person */ - public String toString(){ + public String toString() { return this.formatName()+": "+this.utorid; } @@ -31,11 +35,14 @@ public String toString(){ * @return the name formatted as a str. */ String formatName() { - String formattedName = this.name[name.length - 1] + ","; - int i = 0; - while (i != this.name.length - 1) { formattedName = - formattedName+" "+this.name[i]; - i += 1; + String formattedName = this.name[name.length - 1]; + + if (name.length > 1) { + formattedName += ","; + } + + for (int i = 0; i < name.length - 1; i++) { + formattedName += " " + this.name[i]; } return formattedName; diff --git a/src/uoft/csc207/week2/Student.java b/src/uoft/csc207/week2/Student.java new file mode 100644 index 0000000..bb05da4 --- /dev/null +++ b/src/uoft/csc207/week2/Student.java @@ -0,0 +1,15 @@ +package uoft.csc207.week2; + +public class Student extends Person { + + String studentID; + + Student(String[] name, String utorid, String studentID) { + super(name, utorid); + this.studentID = studentID; + } + + public String toString () { + return super.toString() + ", " + this.studentID; + } +}