diff --git a/.idea/misc.xml b/.idea/misc.xml index e208459..53f706d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/src/uoft/csc207/week2/Main.java b/src/uoft/csc207/week2/Main.java index 648f0d3..07435ed 100644 --- a/src/uoft/csc207/week2/Main.java +++ b/src/uoft/csc207/week2/Main.java @@ -5,6 +5,7 @@ public class Main { public static void main(String[] args) { String[] name = {"First", "Middle", "Last"}; Person p = new Person(name, "moogah"); + Person s = new Student(name, "frooble", "1234567890"); System.out.println(p); } } diff --git a/src/uoft/csc207/week2/Person.java b/src/uoft/csc207/week2/Person.java index 24a57e3..0f05b0c 100644 --- a/src/uoft/csc207/week2/Person.java +++ b/src/uoft/csc207/week2/Person.java @@ -5,8 +5,15 @@ */ class Person { - /** The person's name (family name last). */ - String[] name; /** The person's UTORid */ String utorid; + /** + * The person's name (family name last). + */ + String[] name; + /** + * The person's UTORid + */ + String utorid; + /** * Initialize this Person named name with UTORid utorid. * @@ -14,27 +21,33 @@ class Person { * @param utorid the person's UTORid */ Person - (String[] name, String utorid){this.name=name;this.utorid=utorid;} + (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(){ - return this.formatName()+": "+this.utorid; + public String toString() { + return this.formatName() + ": " + this.utorid; } /** * Return the name formatted as a str. The last name is first, then a * comma, then the rest of the names. + * * @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]; + int i = 0; + while (i != this.name.length - 1) { + formattedName = + formattedName + " " + this.name[i]; i += 1; } diff --git a/src/uoft/csc207/week2/Student.java b/src/uoft/csc207/week2/Student.java new file mode 100644 index 0000000..1ef4f0e --- /dev/null +++ b/src/uoft/csc207/week2/Student.java @@ -0,0 +1,10 @@ +package uoft.csc207.week2; + +public class Student extends Person { + private final String studentid; + + public Student(String[] name, String utorid, String studentid) { + super(name, utorid); + this.studentid = studentid; + } +}