diff --git a/Solutions/whiteWeed/Game Shop/3/Armor.java b/Solutions/whiteWeed/Game Shop/3/Armor.java new file mode 100644 index 0000000..c350fa6 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/Armor.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Armor
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 29.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Armor extends Item { + private int defence; + + public Armor(String name, String description, int weight, int value, int defence){ + super(name, description, weight, value); + this.defence = defence; + } + + public void describe(){ + super.describe(); + System.out.println("Defence = " + this.defence); + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/Item.java b/Solutions/whiteWeed/Game Shop/3/Item.java new file mode 100644 index 0000000..85ddf1c --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/Item.java @@ -0,0 +1,35 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Item
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 18.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Item { + protected String name, description; + protected int weight, value; + + public Item(String name, String description, int weight, int value){ + this.name = name; + this.description = description; + this.weight = weight; + this.value = value; + } + + public void describe(){ + System.out.println("Name = " + this.name); + System.out.println("Description = " + this.description); + System.out.println("Weight = " + this.weight + " lbs"); + System.out.println("Value = " + this.value + " gold coins"); + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/ItemTest.java b/Solutions/whiteWeed/Game Shop/3/ItemTest.java new file mode 100644 index 0000000..e5cc9b8 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/ItemTest.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_ItemTest
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 18.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class ItemTest { + public static void main(String[] args) { + Item[] items = { + new Item("Excalibur", "The legendary sword of King Arthur", 12, 1024), + new Item("Steel Armor", "Protective covering made by steel", 15, 805) + }; + + for(Item item : items){ + item.describe(); + System.out.println(); + } + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/ItemTest2.java b/Solutions/whiteWeed/Game Shop/3/ItemTest2.java new file mode 100644 index 0000000..244ae14 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/ItemTest2.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_ItemTest2
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 29.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class ItemTest2 { + public static void main(String[] args) { + Item[] items = { + new Weapon("Excalibur", "The legendary sword of King Arthur", 12, 1024, 24), + new Armor("Steel Armor", "Protective covering made by steel", 15, 805, 18) + }; + + for(Item item : items){ + item.describe(); + System.out.println(); + } + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/Potion.java b/Solutions/whiteWeed/Game Shop/3/Potion.java new file mode 100644 index 0000000..b1534dd --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/Potion.java @@ -0,0 +1,33 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Potion
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 5.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Potion extends Item { + String type; + int capacity; + + public Potion(String name, String description, int weight, int value, String type, int capacity){ + super(name, description, weight, value); + this.type = type; + this.capacity = capacity; + } + + public void describe(){ + super.describe(); + System.out.println("Type = " + this.type); + System.out.println("Capacity = " + this.capacity); + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/Shop.java b/Solutions/whiteWeed/Game Shop/3/Shop.java new file mode 100644 index 0000000..446d3e5 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/Shop.java @@ -0,0 +1,35 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Shop
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 5.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Shop { + String name; + Item[] items; + + public Shop(String name, Item[] items){ + this.name = name; + this.items = items; + } + + public void showItemList(){ + System.out.println("Welcome to " + this.name + " Shop!"); + System.out.println("- Item List -"); + for(Item item : items){ + item.describe(); + System.out.println(); + } + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/ShopTest.java b/Solutions/whiteWeed/Game Shop/3/ShopTest.java new file mode 100644 index 0000000..8897234 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/ShopTest.java @@ -0,0 +1,72 @@ +/** + * + */ +package whiteWeed.gameShop; + +import java.util.*; + +/** + *
+ * whiteWeed.gameShop
+ *   |_ShopTest
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 5.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class ShopTest { + private static Item[][] items = { + { + new Weapon("Sword", "Medium DMG", 3, 10, 10), + new Armor("Cap", "Light Armor", 1, 5, 5), + new Armor("Gloves", "Light Armor", 1, 5, 5), + new Weapon("Axe", "High DMG", 5, 15, 15), + new Armor("Boots", "Light Armor", 1, 5, 5) + }, + { + new Potion("Small Health Potion", "Recovery 100 HP", 2, 5, "Health", 100), + new Potion("Small Mana Potion", "Recovery 50 MP", 1, 30, "Mana", 50), + new Potion("Medium Health Potion", "Recovery 200 HP", 4, 120, "Health", 200), + new Potion("Medium Mana Potion", "Recovery 100 MP", 2, 75, "Mana", 100), + new Potion("Large Health Potion", "Recovery 300 HP", 6, 200, "Health", 300) + } + }; + private static Shop[] shops = { + new Shop("Weapon/Armor", items[0]), + new Shop("Potion", items[1]) + }; + + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + boolean end = true; + while(end) { + end = select(); + } + sc.close(); + } + + public static boolean select(){ + System.out.println("- Shop Select -"); + System.out.println(" 1. Weapon/Armor Shop"); + System.out.println(" 2. Potion Shop"); + System.out.println(" 3. Exit"); + System.out.println(); + System.out.println("Select : "); + int selection = sc.nextInt(); + sc.reset(); + + if(selection > 3 || selection <= 0){ + System.out.println("Invalid number! Try again."); + return true; + } + else if(selection <= 2){ + shops[selection - 1].showItemList(); + return true; + } + return false; + } +} diff --git a/Solutions/whiteWeed/Game Shop/3/Weapon.java b/Solutions/whiteWeed/Game Shop/3/Weapon.java new file mode 100644 index 0000000..a291c6d --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/Weapon.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Weapon
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 29.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Weapon extends Item { + private int damage; + + public Weapon(String name, String description, int weight, int value, int damage){ + super(name, description, weight, value); + this.damage = damage; + } + + public void describe(){ + super.describe(); + System.out.println("Damage = " + this.damage); + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/Armor.java b/Solutions/whiteWeed/Game Shop/4/Armor.java new file mode 100644 index 0000000..e98baea --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/Armor.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Armor
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 29.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Armor extends Item { //ㅁㄴㅇㄹ + private int defence; + + public Armor(String name, String description, int weight, int value, int defence){ + super(name, description, weight, value); + this.defence = defence; + } + + public void describe(){ + super.describe(); + System.out.println("Defence = " + this.defence); + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/Item.java b/Solutions/whiteWeed/Game Shop/4/Item.java new file mode 100644 index 0000000..5c3b46a --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/Item.java @@ -0,0 +1,35 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Item
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 18.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Item { //ㅁㄴㅇㄹ + protected String name, description; + protected int weight, value; + + public Item(String name, String description, int weight, int value){ + this.name = name; + this.description = description; + this.weight = weight; + this.value = value; + } + + public void describe(){ + System.out.println("Name = " + this.name); + System.out.println("Description = " + this.description); + System.out.println("Weight = " + this.weight + " lbs"); + System.out.println("Value = " + this.value + " gold coins"); + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/Potion.java b/Solutions/whiteWeed/Game Shop/4/Potion.java new file mode 100644 index 0000000..f3fb3a9 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/Potion.java @@ -0,0 +1,33 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Potion
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 5.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Potion extends Item { //ㅁㄴㅇㄹ + String type; + int capacity; + + public Potion(String name, String description, int weight, int value, String type, int capacity){ + super(name, description, weight, value); + this.type = type; + this.capacity = capacity; + } + + public void describe(){ + super.describe(); + System.out.println("Type = " + this.type); + System.out.println("Capacity = " + this.capacity); + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/Shop.java b/Solutions/whiteWeed/Game Shop/4/Shop.java new file mode 100644 index 0000000..589828d --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/Shop.java @@ -0,0 +1,92 @@ +/** + * + */ +package whiteWeed.gameShop; + +import java.io.*; +import java.util.*; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Shop
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 5.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Shop { //ㅁㄴㅇㄹ + String name; + Item[] itemsArray; + List strList = new ArrayList(); + List itemList = new ArrayList(); + List itemsList = new ArrayList(); + + public Shop(String name, Item[] items){ + this.name = name; + this.itemsArray = items; + } + + public Shop(String name, String fileName){ + this.name = name; + String path = Shop.class.getResource("").getPath(); + try{ + BufferedReader br = new BufferedReader(new FileReader(path + fileName)); + while(true){ + String line = br.readLine(); + if(line != null){ + strList.add(line); + }else{ + break; + } + } + br.close(); + } catch(IOException e){ + System.out.println("can't find file"); + } + } + + public void splitData(){ + for(String str : strList){ + str = str.replaceAll("\"", ""); + itemList.add(str.split(", ")); + + } + for(String[] str : itemList){ + if(str[0].equals("Potion") == true){ + itemsList.add(new Potion(str[1], str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), str[5], Integer.parseInt(str[6]))); + } + else if(str[0].equals("Weapon") == true){ + itemsList.add(new Weapon(str[1], str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), Integer.parseInt(str[5]))); + } + else if(str[0].equals("Armor") == true){ + itemsList.add(new Armor(str[1], str[2], Integer.parseInt(str[3]), Integer.parseInt(str[4]), Integer.parseInt(str[5]))); + } + else{ + System.out.println("Invalid item type! Try check .txt file again."); + } + } + } + + public void showItemList(){ + System.out.println("Welcome to " + this.name + " Shop!"); + System.out.println("- Item List -"); + for(Item item : itemsArray){ + item.describe(); + System.out.println(); + } + } + + public void showItemArrayList(){ + splitData(); + System.out.println("Welcome to " + this.name + " Shop!"); + System.out.println("- Item List -"); + for(Item item : itemsList){ + item.describe(); + System.out.println(); + } + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/ShopTest2.java b/Solutions/whiteWeed/Game Shop/4/ShopTest2.java new file mode 100644 index 0000000..6322a29 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/ShopTest2.java @@ -0,0 +1,56 @@ +/** + * + */ +package whiteWeed.gameShop; + +import java.util.Scanner; + +/** + *
+ * whiteWeed.gameShop
+ *   |_ShopTest2
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 7. 3.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class ShopTest2 { //ㅁㄴㅇㄹ + private static Shop[] shops = { + new Shop("Weapon/Armor", "equip_item.txt"), + new Shop("Potion", "potion_item.txt") + }; + + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + boolean end = true; + while(end) { + end = select(); + } + sc.close(); + } + + public static boolean select(){ + System.out.println("- Shop Select -"); + System.out.println(" 1. Weapon/Armor Shop"); + System.out.println(" 2. Potion Shop"); + System.out.println(" 3. Exit"); + System.out.println(); + System.out.print("Select : "); + int selection = sc.nextInt(); + sc.reset(); + + if(selection > 3 || selection <= 0){ + System.out.println("Invalid number! Try again."); + return true; + } + else if(selection <= 2){ + shops[selection - 1].showItemArrayList(); + return true; + } + return false; + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/Weapon.java b/Solutions/whiteWeed/Game Shop/4/Weapon.java new file mode 100644 index 0000000..35a8925 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/Weapon.java @@ -0,0 +1,30 @@ +/** + * + */ +package whiteWeed.gameShop; + +/** + *
+ * whiteWeed.gameShop
+ *   |_Weapon
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 5. 29.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Weapon extends Item { + private int damage; //ㅁㄴㅇㄹ + + public Weapon(String name, String description, int weight, int value, int damage){ + super(name, description, weight, value); + this.damage = damage; + } + + public void describe(){ + super.describe(); + System.out.println("Damage = " + this.damage); + } +} diff --git a/Solutions/whiteWeed/Game Shop/4/equip_item.txt b/Solutions/whiteWeed/Game Shop/4/equip_item.txt new file mode 100644 index 0000000..168a930 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/equip_item.txt @@ -0,0 +1,5 @@ +"Weapon", "Sword", "Medium DMG", 3, 10, 10 +"Armor", "Cap", "Light Armor", 1, 5, 5 +"Armor", "Gloves", "Light Armor", 1, 5, 5 +"Weapon", "Axe", "High DMG", 5, 15, 15 +"Armor", "Boots", "Light Armor", 1, 5, 5 \ No newline at end of file diff --git a/Solutions/whiteWeed/Game Shop/4/potion_item.txt b/Solutions/whiteWeed/Game Shop/4/potion_item.txt new file mode 100644 index 0000000..30a9c21 --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/4/potion_item.txt @@ -0,0 +1,5 @@ +"Potion", "Small Health Potion", "Recovery 100 HP", 2, 5, "Health", 100 +"Potion", "Small Mana Potion", "Recovery 50 MP", 1, 30, "Mana", 50 +"Potion", "Medium Health Potion", "Recovery 200 HP", 4, 120, "Health", 200 +"Potion", "Medium Mana Potion", "Recovery 100 MP", 2, 75, "Mana", 100 +"Potion", "Large Health Potion", "Recovery 300 HP", 6, 200, "Health", 300 \ No newline at end of file diff --git a/Solutions/whiteWeed/Grade Management System/2/Grade2.java b/Solutions/whiteWeed/Grade Management System/2/Grade2.java new file mode 100644 index 0000000..3ec92d7 --- /dev/null +++ b/Solutions/whiteWeed/Grade Management System/2/Grade2.java @@ -0,0 +1,51 @@ +/** + * + */ +package whiteWeed.gradeManage; + +/** + *
+ * whiteWeed.gradeManage
+ *   |_Grade2
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 2.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class Grade2 { //ㅁㄴㅇㄹ + private String name; + private short sum = 0, rank; + private float average; + protected byte[] score; + public static byte[] scoreSum = {0, 0, 0, 0}; + public static int studentCnt = 0; + + public Grade2(String name, byte[] score, short sum, float average){ + this.name = name; + this.score = score; + this.sum = sum; + this.average = average; + studentCnt++; + for(int i = 0; i < 3; i++){ + scoreSum[i] += score[i]; + } + scoreSum[3] += sum; + } + + public short getSum(){ + return sum; + } + + public void setRank(short rank){ + this.rank = rank; + } + + public String toString(){ + return String.format("%-10s", this.name) + String.format("%-6d", this.score[0]) + String.format("%-6d", this.score[1]) + + String.format("%-6d", this.score[2]) + String.format("%-6d", this.sum) + String.format("%-6.1f", this.average) + + String.format("%-3d", this.rank); + } +} diff --git a/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java new file mode 100644 index 0000000..657a4e0 --- /dev/null +++ b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java @@ -0,0 +1,133 @@ +/** + * + */ +package whiteWeed.gradeManage; + +import java.util.*; + +/** + *
+ * whiteWeed.gradeManage
+ *   |_GradeTest2
+ * 
+ * 1. 개요 : 
+ * 2. 작성일 : 2017. 6. 2.
+ * 
+ * + * @author : Weed + * @version : 1.0 + */ +public class GradeTest2 { //ㅁㄴㅇㄹ + + private static Scanner sc = new Scanner(System.in); + private static List gradeArray = new ArrayList(); + private static Map gradeSums = new HashMap(); + + public static void main(String[] args) { + boolean end = true; + while(end){ + end = menuSelect(); + } + sc.close(); + } + + private static boolean menuSelect(){ + System.out.println(" - Menu select -"); + System.out.println(" 1. Input Student's grade"); + System.out.println(" 2. Print Student's grade"); + System.out.println(" 3. Exit"); + System.out.println(); + System.out.print("Select : "); + int index = sc.nextInt(); + sc.reset(); + System.out.println(); + + boolean end = true; + + switch(index){ + case 1: + while(end){ + end = input(); + } + return true; + case 2: + print(); + return true; + case 3: + return false; + default: + return true; + } + } + + private static boolean input(){ + byte[] score = {0, 0, 0}; + short sum = 0; + float average; + String[] subs = {"> Name : ", "> Korean : ", "> English : ", "> Math : "}, args = {null, null, null, null}; + + for(int i = 0; i < 4; i++){ + System.out.print(subs[i]); + args[i] = sc.next(); + sc.reset(); + } + + for(int i = 0; i < 3; i++){ + score[i] = Byte.parseByte(args[i + 1]); + sum += score[i]; + } + + average = (float)sum/3; + gradeArray.add(new Grade2(args[0], score, sum, average)); + System.out.println(); + System.out.print("> Do you continue to input (Y/N)? "); + String index = sc.next(); + sc.reset(); + + switch(index){ + case "Y": + return true; + case "N": + return false; + default: + return false; + } + } + + private static void print(){ + for(int i = 0; i < Grade2.studentCnt; i++){ + gradeSums.put(i, gradeArray.get(i).getSum()); + } + + for(int i = 0; i < Grade2.studentCnt; i++){ + for(int j = i + 1; j < Grade2.studentCnt; j++){ + if(gradeSums.get(i) < gradeSums.get(j)){ + short tmp; + tmp = gradeSums.get(i); + gradeSums.replace(i, gradeSums.get(j)); + gradeSums.replace(j, tmp); + } + } + gradeArray.get(i).setRank((short)(i + 1)); + } + + System.out.println(String.format("%-10s", "Name") + String.format("%-6s", "Kor") + String.format("%-6s", "Eng") + + String.format("%-6s", "Math") + String.format("%-6s", "Sum") + String.format("%-6s", "Avg") + + String.format("%-6s", "Rank")); + System.out.println("============================================"); + for(Grade2 grade : gradeArray){ + System.out.println(grade); + } + System.out.println("============================================"); + System.out.print(String.format("%-10s", "Sum")); + for(int i = 0; i < 4; i++){ + System.out.print(String.format("%-6d", Grade2.scoreSum[i])); + } + System.out.println(); + System.out.print(String.format("%-10s", "Avg")); + for(int i = 0; i < 4; i++){ + System.out.print(String.format("%-6.1f", (float)Grade2.scoreSum[i]/Grade2.studentCnt)); + } + System.out.println(); + } +}