diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3478de4..7a20347 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,16 +5,12 @@ - - - - - - - - - - + + + + + + diff --git a/src/code/ca/bcit/comp2522/lab03/IDevice.java b/src/code/ca/bcit/comp2522/lab03/IDevice.java index 00b3f5a..f441b2b 100644 --- a/src/code/ca/bcit/comp2522/lab03/IDevice.java +++ b/src/code/ca/bcit/comp2522/lab03/IDevice.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab03; * devices and common functionality. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public abstract class IDevice { + private final String purpose; /** @@ -15,6 +18,8 @@ public abstract class IDevice { * @param purpose of IDevice */ public IDevice(final String purpose) { + + // TODO: validate String inputs this.purpose = purpose; } diff --git a/src/code/ca/bcit/comp2522/lab03/IPad.java b/src/code/ca/bcit/comp2522/lab03/IPad.java index 9a4fc46..e8ea924 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPad.java +++ b/src/code/ca/bcit/comp2522/lab03/IPad.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab03; * such as operating system version, and if it has a case. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class IPad extends IDevice { + private final boolean hasCase; private final String OSVersion; @@ -22,6 +25,7 @@ public class IPad extends IDevice { ) { super("learning"); + // TODO: validate String inputs this.hasCase = hasCase; this.OSVersion = OSVersion; } @@ -39,6 +43,7 @@ public class IPad extends IDevice { * and which operating system version it is running */ public void printDetails() { + final StringBuilder details; details = new StringBuilder(); @@ -49,6 +54,7 @@ public class IPad extends IDevice { details.append(this.OSVersion); System.out.println(details.toString()); + } /** @@ -57,7 +63,19 @@ public class IPad extends IDevice { */ @Override public String toString() { - return super.toString() + " " + this.hasCase + " " + this.OSVersion; + + final StringBuilder details; + + details = new StringBuilder(); + + details.append(super.toString()); + details.append(" "); + details.append(this.hasCase); + details.append(" "); + details.append(this.OSVersion); + + return details.toString(); + } /** @@ -68,6 +86,7 @@ public class IPad extends IDevice { */ @Override public boolean equals(final Object o) { + // Ensure object exists if (o == null) { return false; @@ -83,6 +102,7 @@ public class IPad extends IDevice { otherIPad = (IPad) o; return otherIPad.getOSVersion().equals(this.OSVersion); + } /** diff --git a/src/code/ca/bcit/comp2522/lab03/IPhone.java b/src/code/ca/bcit/comp2522/lab03/IPhone.java index be17fca..3ea41a0 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPhone.java +++ b/src/code/ca/bcit/comp2522/lab03/IPhone.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab03; * how many minutes remain on the phone plan. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class IPhone extends IDevice { + private static final int IPHONE_HASH = 11; private static final int IPHONE_HASH_CODE = 101; @@ -25,6 +28,7 @@ public class IPhone extends IDevice { ) { super("talking"); + // TODO: validate String inputs, possibly other inputs too this.remainingPhonePlanMinutes = remainingPhonePlanMinutes; this.carrier = carrier; } @@ -42,6 +46,7 @@ public class IPhone extends IDevice { * phone plan minutes */ public void printDetails() { + final StringBuilder details; details = new StringBuilder(); @@ -52,6 +57,7 @@ public class IPhone extends IDevice { details.append(")"); System.out.println(details.toString()); + } /** @@ -60,10 +66,11 @@ public class IPhone extends IDevice { */ @Override public String toString() { + + // TODO: convert to StringBuilder, refer to IPad return super.toString() + " " + this.remainingPhonePlanMinutes + " " + this.carrier; } - /** * equals check if a given IPhone has the same remaining * phone plan minutes as this IPhone. @@ -72,6 +79,7 @@ public class IPhone extends IDevice { */ @Override public boolean equals(final Object o) { + // Ensure object exists if (o == null) { return false; @@ -87,6 +95,7 @@ public class IPhone extends IDevice { otherIPhone = (IPhone) o; return otherIPhone.getRemainingPhonePlanMinutes() == this.remainingPhonePlanMinutes; + } /** @@ -95,8 +104,12 @@ public class IPhone extends IDevice { */ @Override public int hashCode() { + int hash; + hash = IPHONE_HASH_CODE * IPHONE_HASH * (int) this.remainingPhonePlanMinutes; + return hash; + } } diff --git a/src/code/ca/bcit/comp2522/lab03/IPhone16.java b/src/code/ca/bcit/comp2522/lab03/IPhone16.java index a16b68e..8099d8e 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPhone16.java +++ b/src/code/ca/bcit/comp2522/lab03/IPhone16.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab03; * features. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class IPhone16 extends IPhone { + private static final int IPHONE_HASH_WITH_HIGH_RES = 103; final boolean highResolutionCamera; @@ -28,6 +31,8 @@ public class IPhone16 extends IPhone { ) { super(remainingPhonePlanMinutes, carrier); + // TODO: validate memoryGB input? + this.highResolutionCamera = highResolutionCamera; this.memoryGB = memoryGB; } @@ -46,6 +51,7 @@ public class IPhone16 extends IPhone { */ @Override public String toString() { + final StringBuilder builder; builder = new StringBuilder(); @@ -56,6 +62,7 @@ public class IPhone16 extends IPhone { builder.append(this.memoryGB); return builder.toString(); + } /** @@ -67,6 +74,7 @@ public class IPhone16 extends IPhone { */ @Override public boolean equals(final Object o) { + // Ensure object exists if (o == null) { return false; @@ -84,10 +92,11 @@ public class IPhone16 extends IPhone { final boolean matchingMinutes; final boolean matchingCameraResolution; - matchingMinutes = otherIPhone.getRemainingPhonePlanMinutes() == this.getRemainingPhonePlanMinutes(); + matchingMinutes = otherIPhone.getRemainingPhonePlanMinutes() == this.getRemainingPhonePlanMinutes(); matchingCameraResolution = this.highResolutionCamera && otherIPhone.getHighResolutionCamera(); return matchingMinutes && matchingCameraResolution; + } /** @@ -96,6 +105,7 @@ public class IPhone16 extends IPhone { */ @Override public int hashCode() { + int hash; hash = super.hashCode(); @@ -105,5 +115,6 @@ public class IPhone16 extends IPhone { } return hash; + } } diff --git a/src/code/ca/bcit/comp2522/lab03/IPod.java b/src/code/ca/bcit/comp2522/lab03/IPod.java index 9f6219a..dc2ac84 100644 --- a/src/code/ca/bcit/comp2522/lab03/IPod.java +++ b/src/code/ca/bcit/comp2522/lab03/IPod.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab03; * volume in decibels. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class IPod extends IDevice { + private static final int IPOD_HASH = 7; private static final int IPOD_HASH_CODE = 97; @@ -25,6 +28,8 @@ public class IPod extends IDevice { ) { super("music"); + // TODO: validate numberOfSongs input + this.numberOfSongs = numberOfSongs; this.maxVolumeDecibels = maxVolumeDecibels; } @@ -34,6 +39,7 @@ public class IPod extends IDevice { * and max volume in decibels. */ public void printDetails() { + final StringBuilder details; details = new StringBuilder(); @@ -44,6 +50,7 @@ public class IPod extends IDevice { details.append(" dB."); System.out.println(details.toString()); + } /** @@ -60,6 +67,8 @@ public class IPod extends IDevice { */ @Override public String toString() { + + // TODO: change this to StringBuilder, refer to IPad return super.toString() + " " + this.numberOfSongs + " " + this.maxVolumeDecibels; } @@ -71,6 +80,7 @@ public class IPod extends IDevice { */ @Override public boolean equals(final Object o) { + // Ensure object exists if (o == null) { return false; @@ -86,6 +96,7 @@ public class IPod extends IDevice { otherIPod = (IPod) o; return otherIPod.getNumberOfSongs() == this.numberOfSongs; + } /** @@ -94,8 +105,12 @@ public class IPod extends IDevice { */ @Override public int hashCode() { + int hash; + hash = IPOD_HASH_CODE * IPOD_HASH + this.numberOfSongs; + return hash; + } } diff --git a/src/code/ca/bcit/comp2522/lab03/Main.java b/src/code/ca/bcit/comp2522/lab03/Main.java index 7ad972c..f7d5a55 100644 --- a/src/code/ca/bcit/comp2522/lab03/Main.java +++ b/src/code/ca/bcit/comp2522/lab03/Main.java @@ -4,6 +4,8 @@ package ca.bcit.comp2522.lab03; * Main class to test IDevice classes, and abstract concepts. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class Main {