From 60ddc77b58abcedbed7b4934271b32642d4a75fa Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 10 Nov 2020 14:17:32 +0700 Subject: [PATCH] add method comments --- Assignment11/bin/Witch.class | Bin 2350 -> 2350 bytes Assignment11/bin/WitchGame.class | Bin 2155 -> 2155 bytes Assignment11/src/Witch.java | 95 +++++++++++++++++++++++++++++++ Assignment11/src/WitchGame.java | 1 - 4 files changed, 95 insertions(+), 1 deletion(-) diff --git a/Assignment11/bin/Witch.class b/Assignment11/bin/Witch.class index b0aab2ce807cbebf8be16e539e04efb370551626..fec746510acd69e0930b4a0d389abf8f37afb556 100644 GIT binary patch delta 237 zcmWNMJukyy6vcl}^4#ZNrAX_kR>eZSZR&0L8$?VjBDG3t)5Sm{7WJ~S+(g2TB56!s z!nd$Ue3mBec5}};zns&_ck-{|#pB6o)^En5UBhH4F-VyrBaBherr(ZLQzq$Qihiak zFhhk|{qZNUX39K$EHK0(qbxDOvNmMht!i6pZbSbhb#*O;)a`0Lq_S^`rrv}VIYc

?%;?bjl3W~6flxG>tKt|eP?Wu9xjP4?WKc9TZ=o?afv@n|jE*6@ic&(`Zjk244H V%{cFt_^<_^w&9C$zO|c~`v*WtE?58n delta 237 zcmWNL%SwV#6otPNXP;lqZrZV5EgM)kXb?$3!EYDJLD0>li&7ICHfb2W#)hCba3sA; zlb~l2+LOg*e|xRHCZ$Q~TfEHR$!o!1#G*}e6qsj`1uCWumh{#4W7)_ud7`ljWmc$@ z>W}}3H6wM3tQuc4ZLq<*j->0FI+nI;>7Qh7OVg0KZM_Sb?3!awKSM|M5f1b>+{esz z9Ri1zbY#DeE$u{4lb)Q}O;^8?7k94HWK_LmmMd#{P09^5dTeq_i@v_+-r|GhJep%* O-G@|pqRF#Pb36ZLvm}E6 diff --git a/Assignment11/bin/WitchGame.class b/Assignment11/bin/WitchGame.class index 09ec89182575c9e43e94af5599a8f825bf33787e..dce09d5e5b5049ea1128de4da8eada986e3429d6 100644 GIT binary patch delta 75 zcmaDY@LFJl54)-`Lp6g4!vqF#hM5c!4D%Tz8MZLUFkE1eW%$IPz{tm-$SBUBG`Wy{ fy{HO<0)rZZC4&Zo9fKA_ID-yDB!kLiQw}o#U`GxT delta 75 zcmaDY@LFJl54)-eLp6ga!vqEihM5eK4D%VJ7`8CTGF)JgWBA0N$jHZ_#3;_7Jh_m4 fy{IaK0)sk(C4(k|9fLMQID;-jB!lW?Qw}o#Vv7zU diff --git a/Assignment11/src/Witch.java b/Assignment11/src/Witch.java index e704bd9..2fd9e50 100644 --- a/Assignment11/src/Witch.java +++ b/Assignment11/src/Witch.java @@ -1,14 +1,24 @@ public class Witch { + + // Static Fields private static int totalWitches = 0; + // Non-Static Fields private String name; private String school; private int magicPower; + // Static Constants static final int MAX_LEVEL = 100; static final int MIN_LEVEL = 0; // Constructors + /** + * This is the default constructor + * + * @category constructor + * @param None This constructor takes no parameter + */ public Witch() { this.name = "no one"; this.school = "unknown school"; @@ -16,6 +26,14 @@ public class Witch { Witch.totalWitches++; } + /** + * Initialize this witch object with data from parameter + * + * @category constructor + * @param name The name of the witch + * @param school The school that the witch belong to + * @param magicPower The magicPower of the witch + */ public Witch(String name, String school, int magicPower) { this.name = name; this.school = school; @@ -23,6 +41,12 @@ public class Witch { Witch.totalWitches++; } + /** + * Initialize this witch object with data from w + * + * @category constructor + * @param w Witch to clone from + */ public Witch(Witch w) { this.magicPower = w.getMagicPower(); this.name = w.getName(); @@ -31,31 +55,74 @@ public class Witch { } // Getters + /** + * Get the number of witch created + * + * @category getter + * @return totalWitches The total number of witch created + */ public static int getTotalWitches() { return Witch.totalWitches; } + /** + * Get the name of the witch + * + * @category getter + * @return name name of the witch + */ public String getName() { return this.name; } + /** + * Get the magic power of the witch + * + * @category getter + * @return magicPower The magic power of the witch + */ public int getMagicPower() { return this.magicPower; } + /** + * Get the school of the witch + * + * @category getter + * @return school The school of the witch + */ public String getSchool() { return this.school; } // Setters + /** + * Set the totalWitches field + * + * @category setter + * @param totalWitches The value of totalWitches to set + */ public static void setTotalWitches(int totalWitches) { Witch.totalWitches = totalWitches; } + /** + * Set the name of the witch + * + * @category setter + * @param name The name of the witch to set + */ public void setName(String name) { this.name = name; } + /** + * Set the magic power of the witch + * + * @category setter + * @param magicPower the magic power to set (0<=magicPower<=100), numbers out of + * range will be rounded up/down to MAX_LEVEL and MIN_LEVEL + */ public void setMagicPower(int magicPower) { if (magicPower < MIN_LEVEL) magicPower = MIN_LEVEL; @@ -64,15 +131,36 @@ public class Witch { this.magicPower = magicPower; } + /** + * Set the school of the witch + * + * @category setter + * @param school The school that the witch belong to. + */ public void setSchool(String school) { this.school = school; } // Utilities + /** + * Return the object as a formatted string + * + * @category utility + * @Override java.lang.Object.toString() + * @return WitchString The formatted string containing all field of Object Witch + */ + @Override public String toString() { return String.format("Witchname: %s, School: %s, Magic Power: %s", this.name, this.school, this.magicPower); } + /** + * Compare the power level of this witch to witch w + * + * @category utility + * @param w The second witch object + * @return intPowerCompare 1 if this>w, 2 if this==w, 3 if this w.magicPower) return 1; @@ -83,6 +171,13 @@ public class Witch { return 9999; // This statement should not be called } + /** + * Increase the witch's magicPower + * + * @category utility + * @param increase a positive integer to increase the level of the witch by + * (this.magicPower+increase must be less than MAX_LEVEL) + */ public void levelUp(int increase) { if (increase < 0) return; diff --git a/Assignment11/src/WitchGame.java b/Assignment11/src/WitchGame.java index bcb2b3a..982c2ce 100644 --- a/Assignment11/src/WitchGame.java +++ b/Assignment11/src/WitchGame.java @@ -15,7 +15,6 @@ public class WitchGame { witch1.setName("Hermione Granger"); witch1.setSchool("Hogwarts"); witch1.setMagicPower(85); - //compareTo(Witch w) test System.out.format("%s%n%s%n%s%n", LINE_BREAK, "Printing the comparison", LINE_BREAK); System.out.format("%s%n", parseCompareTo(witch1,witch2));