being lab 03, TODO: override equals + hashCode
This commit is contained in:
9 files changed
+289
-25
No files matched your search
@@ -0,0 +1 @@
|
||||
/out/*
|
||||
Generated
+3
-1
@@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" project-jdk-name="24" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" project-jdk-name="24" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+45
-24
@@ -6,11 +6,6 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="4481728b-524b-48ee-9d70-e414a15f05bd" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Creature.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Creature.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/DamageException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/DamageException.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Date.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Date.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Dragon.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/Dragon.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/HealingException.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/code/ca/bcit/comp2522/lab02/HealingException.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -39,31 +34,52 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/home/flami/Projects/comp2522",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Application.Main.executor": "Run",
|
||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "main",
|
||||
"kotlin-language-version-configured": "true",
|
||||
"last_opened_file_path": "/home/flami/Projects/comp2522",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"nodejs_package_manager_path": "npm",
|
||||
"project.structure.last.edited": "Project",
|
||||
"project.structure.proportion": "0.15",
|
||||
"project.structure.side.proportion": "0.2",
|
||||
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyClassDialog.RECENTS_KEY">
|
||||
<recent name="ca.bcit.comp2522.lab02" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="ca.bcit.comp2522.lab03.Main" />
|
||||
<module name="comp2522" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="ca.bcit.comp2522.lab03.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Application.Main" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
@@ -86,6 +102,11 @@
|
||||
<workItem from="1757986074841" duration="318000" />
|
||||
<workItem from="1758045661655" duration="660000" />
|
||||
<workItem from="1758156443615" duration="6374000" />
|
||||
<workItem from="1758221692281" duration="40000" />
|
||||
<workItem from="1758221863793" duration="810000" />
|
||||
<workItem from="1758254368145" duration="997000" />
|
||||
<workItem from="1758294307794" duration="4368000" />
|
||||
<workItem from="1758342126924" duration="1015000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public abstract class IDevice {
|
||||
private final String purpose;
|
||||
|
||||
IDevice(final String purpose) {
|
||||
this.purpose = purpose;
|
||||
}
|
||||
|
||||
abstract void printDetails();
|
||||
|
||||
protected String getPurpose() {
|
||||
return this.purpose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.purpose;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public class IPad extends IDevice {
|
||||
private final boolean hasCase;
|
||||
private final String OSVersion;
|
||||
|
||||
IPad(
|
||||
final boolean hasCase,
|
||||
final String OSVersion
|
||||
) {
|
||||
super("learning");
|
||||
|
||||
this.hasCase = hasCase;
|
||||
this.OSVersion = OSVersion;
|
||||
}
|
||||
|
||||
protected void printDetails() {
|
||||
final StringBuilder details;
|
||||
|
||||
details = new StringBuilder();
|
||||
|
||||
details.append("Has case: ");
|
||||
details.append(this.hasCase);
|
||||
details.append(" OS Version: ");
|
||||
details.append(this.OSVersion);
|
||||
|
||||
System.out.println(details.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " " + this.hasCase + " " + this.OSVersion;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public class IPhone extends IDevice {
|
||||
private final double remainingPhonePlanMinutes;
|
||||
private final String carrier;
|
||||
|
||||
IPhone(
|
||||
final double remainingPhonePlanMinutes,
|
||||
final String carrier
|
||||
) {
|
||||
super("talking");
|
||||
|
||||
this.remainingPhonePlanMinutes = remainingPhonePlanMinutes;
|
||||
this.carrier = carrier;
|
||||
}
|
||||
|
||||
protected void printDetails() {
|
||||
final StringBuilder details;
|
||||
|
||||
details = new StringBuilder();
|
||||
|
||||
details.append(this.remainingPhonePlanMinutes);
|
||||
details.append(" remaining minutes (");
|
||||
details.append(this.carrier);
|
||||
details.append(")");
|
||||
|
||||
System.out.println(details.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " " + this.remainingPhonePlanMinutes + " " + this.carrier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public class IPhone16 extends IPhone {
|
||||
final boolean highResolutionCamera;
|
||||
final int memoryGB;
|
||||
|
||||
IPhone16(
|
||||
final double remainingPhonePlanMinutes,
|
||||
final String carrier,
|
||||
final boolean highResolutionCamera,
|
||||
final int memoryGB
|
||||
) {
|
||||
super(remainingPhonePlanMinutes, carrier);
|
||||
|
||||
this.highResolutionCamera = highResolutionCamera;
|
||||
this.memoryGB = memoryGB;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public class IPod extends IDevice {
|
||||
private final int numberOfSongs;
|
||||
private final double maxVolumeDecibels;
|
||||
|
||||
IPod(
|
||||
final int numberOfSongs,
|
||||
final double maxVolumeDecibels
|
||||
) {
|
||||
super("music");
|
||||
|
||||
this.numberOfSongs = numberOfSongs;
|
||||
this.maxVolumeDecibels = maxVolumeDecibels;
|
||||
}
|
||||
|
||||
protected void printDetails() {
|
||||
final StringBuilder details;
|
||||
|
||||
details = new StringBuilder();
|
||||
|
||||
details.append(this.numberOfSongs);
|
||||
details.append(" songs, ");
|
||||
details.append(this.maxVolumeDecibels);
|
||||
details.append(" dB.");
|
||||
|
||||
System.out.println(details.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " " + this.numberOfSongs + " " + this.maxVolumeDecibels;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package ca.bcit.comp2522.lab03;
|
||||
|
||||
public class Main {
|
||||
public static void main(final String[] args) {
|
||||
// Create IPod objects
|
||||
final IPod ipod1;
|
||||
final IPod ipod2;
|
||||
final IPod ipod3;
|
||||
|
||||
ipod1 = new IPod(300, 80.0); // 300 songs, max volume 80.0 dB
|
||||
ipod2 = new IPod(400, 85.0); // 400 songs, max volume 85.0 dB
|
||||
ipod3 = new IPod(300, 70.0); // 300 songs, max volume 70.0 dB
|
||||
|
||||
// Test equality and inequality for IPod
|
||||
System.out.println("IPod Equality Test:");
|
||||
if (!ipod1.equals(ipod2)) {
|
||||
System.out.println("CORRECT: ipod1 is not equal to ipod2");
|
||||
} else {
|
||||
System.out.println("INCORRECT: ipod1 should not be equal to ipod2");
|
||||
}
|
||||
|
||||
if (ipod1.equals(ipod3)) {
|
||||
System.out.println("CORRECT: ipod1 is equal to ipod3");
|
||||
} else {
|
||||
System.out.println("INCORRECT: ipod1 should be equal to ipod3");
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
|
||||
// Create IPad objects
|
||||
final IPad ipad1;
|
||||
final IPad ipad2;
|
||||
final IPad ipad3;
|
||||
|
||||
ipad1 = new IPad(true, "iPadOS 15"); // Has case, OS version iPadOS 15
|
||||
ipad2 = new IPad(false, "iPadOS 14"); // No case, OS version iPadOS 14
|
||||
ipad3 = new IPad(true, "iPadOS 15"); // Has case, OS version iPadOS 15
|
||||
|
||||
// Test equality and inequality for IPad
|
||||
System.out.println("IPad Equality Test:");
|
||||
|
||||
if (!ipad1.equals(ipad2)) {
|
||||
System.out.println("CORRECT: ipad1 is not equal to ipad2");
|
||||
} else {
|
||||
System.out.println("INCORRECT: ipad1 should not be equal to ipad2");
|
||||
}
|
||||
|
||||
if (ipad1.equals(ipad3)) {
|
||||
System.out.println("CORRECT: ipad1 is equal to ipad3");
|
||||
} else {
|
||||
System.out.println("INCORRECT: ipad1 should be equal to ipad3");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
// Create IPhone objects
|
||||
final IPhone iphone1;
|
||||
final IPhone iphone2;
|
||||
final IPhone iphone3;
|
||||
iphone1 = new IPhone(120.0, "Verizon"); // 120 minutes, carrier Verizon
|
||||
iphone2 = new IPhone(180.0, "T-Mobile"); // 180 minutes, carrier T-Mobile
|
||||
iphone3 = new IPhone(120.0, "AT&T"); // 120 minutes, carrier AT&T
|
||||
|
||||
// Test equality and inequality for IPhone
|
||||
System.out.println("IPhone Equality Test:");
|
||||
if (!iphone1.equals(iphone2)) {
|
||||
System.out.println("CORRECT: iphone1 is not equal to iphone2");
|
||||
} else {
|
||||
System.out.println("INCORRECT: iphone1 should not be equal to iphone2");
|
||||
}
|
||||
if (iphone1.equals(iphone3)) {
|
||||
System.out.println("CORRECT: iphone1 is equal to iphone3");
|
||||
} else {
|
||||
System.out.println("INCORRECT: iphone1 should be equal to iphone3");
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
// Create IPhone16 objects
|
||||
final IPhone16 iphone16_1;
|
||||
final IPhone16 iphone16_2;
|
||||
final IPhone16 iphone16_3;
|
||||
|
||||
iphone16_1 = new IPhone16(100.0, "Verizon", true, 512); // 100 minutes, high-res camera, 512 GB
|
||||
iphone16_2 = new IPhone16(100.0, "Verizon", true, 256); // 100 minutes, high-res camera, 256 GB
|
||||
iphone16_3 = new IPhone16(100.0, "Verizon", false, 512); // 100 minutes, no high-res camera, 512 GB
|
||||
|
||||
// Test equality and inequality for IPhone16
|
||||
System.out.println("IPhone16 Equality Test:");
|
||||
if (iphone16_1.equals(iphone16_2)) {
|
||||
System.out.println("CORRECT: iphone16_1 is equal to iphone16_2");
|
||||
} else {
|
||||
System.out.println("INCORRECT: iphone16_1 should be equal to iphone16_2");
|
||||
}
|
||||
if (!iphone16_1.equals(iphone16_3)) {
|
||||
System.out.println("CORRECT: iphone16_1 is not equal to iphone16_3");
|
||||
} else {
|
||||
System.out.println("INCORRECT: iphone16_1 should not be equal to iphone16_3");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user