From d5a0899c086c52cebb596cf401236aff5804b2f3 Mon Sep 17 00:00:00 2001 From: faisal375 <144740367+faisal375@users.noreply.github.com> Date: Sun, 17 Sep 2023 00:57:49 -0400 Subject: [PATCH 1/4] testing push from laptop --- src/uoft/csc207/week2/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uoft/csc207/week2/Main.java b/src/uoft/csc207/week2/Main.java index 648f0d3..844138f 100644 --- a/src/uoft/csc207/week2/Main.java +++ b/src/uoft/csc207/week2/Main.java @@ -1,3 +1,7 @@ +// password for something +// qq495142 +// ahKi9eegee + package uoft.csc207.week2; public class Main { From 08fe9b877cbe9ee7edbb3a798186067838b8960a Mon Sep 17 00:00:00 2001 From: Faisal Date: Sat, 23 Sep 2023 16:55:53 -0400 Subject: [PATCH 2/4] untracked .idea directory --- .idea/$PRODUCT_WORKSPACE_FILE$ | 19 ------------------- .idea/.gitignore | 2 -- .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 5 files changed, 41 deletions(-) delete mode 100644 .idea/$PRODUCT_WORKSPACE_FILE$ delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml 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 From ead17a4729a17c88acafc7a5ea7783013c1a15af Mon Sep 17 00:00:00 2001 From: Faisal Date: Sat, 23 Sep 2023 16:57:35 -0400 Subject: [PATCH 3/4] updated .gitignore list and changed Person's toString() method to a for loop from a while loop --- .gitignore | 3 ++- src/uoft/csc207/week2/Person.java | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) 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/src/uoft/csc207/week2/Person.java b/src/uoft/csc207/week2/Person.java index 24a57e3..f43708c 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; } @@ -32,10 +36,8 @@ public String toString(){ */ 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; + for (int i = 0; i < name.length - 1; i++) { + formattedName += this.name[i]; } return formattedName; From 9d0677d817d25ef1e0bff063ebb434c8515d57ca Mon Sep 17 00:00:00 2001 From: Faisal Date: Sat, 23 Sep 2023 17:15:36 -0400 Subject: [PATCH 4/4] added child class student, adjusted person's toString method, updated main to test these things --- src/uoft/csc207/week2/Main.java | 5 ++++- src/uoft/csc207/week2/Person.java | 9 +++++++-- src/uoft/csc207/week2/Student.java | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/uoft/csc207/week2/Student.java diff --git a/src/uoft/csc207/week2/Main.java b/src/uoft/csc207/week2/Main.java index 844138f..a5f08b0 100644 --- a/src/uoft/csc207/week2/Main.java +++ b/src/uoft/csc207/week2/Main.java @@ -7,8 +7,11 @@ 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 f43708c..fc7e176 100644 --- a/src/uoft/csc207/week2/Person.java +++ b/src/uoft/csc207/week2/Person.java @@ -35,9 +35,14 @@ public String toString() { * @return the name formatted as a str. */ String formatName() { - String formattedName = this.name[name.length - 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]; + 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; + } +}