From 66a4ed2735fa7faa9d0fc5e559fc64c15a9da63e Mon Sep 17 00:00:00 2001 From: whiteWeed Date: Mon, 5 Jun 2017 12:24:30 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=EC=84=B1=EC=A0=81=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=8B=9C=EC=8A=A4=ED=85=9C=202=20=EC=A0=9C=EC=B6=9C=ED=95=A9?= =?UTF-8?q?=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Grade Management System/2/Grade2.java | 46 +++++++ .../Grade Management System/2/GradeTest2.java | 129 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 Solutions/whiteWeed/Grade Management System/2/Grade2.java create mode 100644 Solutions/whiteWeed/Grade Management System/2/GradeTest2.java 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..9cbce21 --- /dev/null +++ b/Solutions/whiteWeed/Grade Management System/2/Grade2.java @@ -0,0 +1,46 @@ +/** + * + */ +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 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++; + } + + 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..55c376b --- /dev/null +++ b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java @@ -0,0 +1,129 @@ +/** + * + */ +package whiteWeed.gradeManage; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + *
+ * 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 List gradeSums = new ArrayList(); + + public static void main(String[] args) { + menuSelect(); + sc.close(); + } + + private static void 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(); + switch(index){ + case 1: + input(); + menuSelect(); + break; + case 2: + print(); + menuSelect(); + break; + case 3: + break; + } + } + + private static void input(){ + byte[] score = {0, 0, 0}; + short sum = 0; + float average; + System.out.print("> Name : "); + String name = sc.next(); + sc.reset(); + System.out.print("> Korean : "); + score[0] = sc.nextByte(); + sc.reset(); + sum += score[0]; + System.out.print("> English : "); + score[1] = sc.nextByte(); + sc.reset(); + sum += score[1]; + System.out.print("> Math : "); + score[2] = sc.nextByte(); + sc.reset(); + sum += score[2]; + average = (float)sum/3; + gradeArray.add(new Grade2(name, score, sum, average)); + System.out.println(); + System.out.print("> Do you continue to input (Y/N)? "); + String index = sc.next(); + + switch(index){ + case "Y": + input(); + break; + case "N": + break; + } + } + + private static void print(){ + int[] sums = {0, 0, 0, 0}; + + for(Grade2 grade : gradeArray){ + gradeSums.add(grade.getSum()); + } + gradeSums.toArray(); + + for(int i = gradeArray.size()-1; i >= 0; i--){ + for(int j = 0; j <= gradeArray.size()-1; j++){ + short sum1 = gradeSums.get(i); + Grade2 grade1 = gradeArray.get(j); + if(sum1 == (grade1.getSum())){ + grade1.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("============================================"); + for(Grade2 grade : gradeArray){ + for(int i = 0; i < 3; i++){ + sums[i] += grade.score[i]; + sums[3] += grade.score[i]; + } + } + System.out.println(String.format("%-10s", "Sum") + String.format("%-6d", sums[0]) + String.format("%-6d", sums[1]) + + String.format("%-6d", sums[2]) + String.format("%-6d", sums[3])); + System.out.println(String.format("%-10s", "Avg") + + String.format("%-6.1f", (float)sums[0]/Grade2.studentCnt) + String.format("%-6.1f", (float)sums[1]/Grade2.studentCnt) + + String.format("%-6.1f", (float)sums[2]/Grade2.studentCnt) + String.format("%-6.1f", (float)sums[3]/Grade2.studentCnt)); + } +} From af714b66126d1ecf515d4bf2c21d6ac4ae19227f Mon Sep 17 00:00:00 2001 From: whiteWeed Date: Mon, 5 Jun 2017 12:54:57 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=EA=B2=8C=EC=9E=84=EC=83=81=EC=A0=90=203=20?= =?UTF-8?q?=EC=A0=9C=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solutions/whiteWeed/Game Shop/3/Armor.java | 30 ++++++++ Solutions/whiteWeed/Game Shop/3/Item.java | 35 +++++++++ Solutions/whiteWeed/Game Shop/3/Potion.java | 33 ++++++++ Solutions/whiteWeed/Game Shop/3/Shop.java | 35 +++++++++ Solutions/whiteWeed/Game Shop/3/ShopTest.java | 75 +++++++++++++++++++ Solutions/whiteWeed/Game Shop/3/Weapon.java | 30 ++++++++ 6 files changed, 238 insertions(+) create mode 100644 Solutions/whiteWeed/Game Shop/3/Armor.java create mode 100644 Solutions/whiteWeed/Game Shop/3/Item.java create mode 100644 Solutions/whiteWeed/Game Shop/3/Potion.java create mode 100644 Solutions/whiteWeed/Game Shop/3/Shop.java create mode 100644 Solutions/whiteWeed/Game Shop/3/ShopTest.java create mode 100644 Solutions/whiteWeed/Game Shop/3/Weapon.java 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/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..264bffc --- /dev/null +++ b/Solutions/whiteWeed/Game Shop/3/ShopTest.java @@ -0,0 +1,75 @@ +/** + * + */ +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) { + select(); + sc.close(); + } + + public static void 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(); + + switch(selection){ + case 1: + shops[0].showItemList(); + select(); + break; + case 2: + shops[1].showItemList(); + select(); + break; + case 3: + break; + default: + System.out.println("Invalid number! Try again."); + select(); + break; + } + } +} 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); + } +} From f29ea71e389b1f36316997defda5979e06d4fa07 Mon Sep 17 00:00:00 2001 From: whiteWeed Date: Sat, 1 Jul 2017 17:33:12 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=EA=B3=A0=EC=B3=90=EB=B4=A4=EC=8A=B5?= =?UTF-8?q?=EB=8B=88=EB=8B=A4!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solutions/whiteWeed/Game Shop/3/ItemTest.java | 30 +++++ .../whiteWeed/Game Shop/3/ItemTest2.java | 30 +++++ Solutions/whiteWeed/Game Shop/3/ShopTest.java | 29 +++-- .../Grade Management System/2/Grade2.java | 5 + .../Grade Management System/2/GradeTest2.java | 110 +++++++++--------- 5 files changed, 135 insertions(+), 69 deletions(-) create mode 100644 Solutions/whiteWeed/Game Shop/3/ItemTest.java create mode 100644 Solutions/whiteWeed/Game Shop/3/ItemTest2.java 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/ShopTest.java b/Solutions/whiteWeed/Game Shop/3/ShopTest.java index 264bffc..8897234 100644 --- a/Solutions/whiteWeed/Game Shop/3/ShopTest.java +++ b/Solutions/whiteWeed/Game Shop/3/ShopTest.java @@ -42,11 +42,14 @@ public class ShopTest { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { - select(); + boolean end = true; + while(end) { + end = select(); + } sc.close(); } - public static void select(){ + public static boolean select(){ System.out.println("- Shop Select -"); System.out.println(" 1. Weapon/Armor Shop"); System.out.println(" 2. Potion Shop"); @@ -54,22 +57,16 @@ public static void select(){ System.out.println(); System.out.println("Select : "); int selection = sc.nextInt(); + sc.reset(); - switch(selection){ - case 1: - shops[0].showItemList(); - select(); - break; - case 2: - shops[1].showItemList(); - select(); - break; - case 3: - break; - default: + if(selection > 3 || selection <= 0){ System.out.println("Invalid number! Try again."); - select(); - break; + return true; + } + else if(selection <= 2){ + shops[selection - 1].showItemList(); + return true; } + return false; } } diff --git a/Solutions/whiteWeed/Grade Management System/2/Grade2.java b/Solutions/whiteWeed/Grade Management System/2/Grade2.java index 9cbce21..73ce166 100644 --- a/Solutions/whiteWeed/Grade Management System/2/Grade2.java +++ b/Solutions/whiteWeed/Grade Management System/2/Grade2.java @@ -20,6 +20,7 @@ public class Grade2 { 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){ @@ -28,6 +29,10 @@ public Grade2(String name, byte[] score, short sum, float average){ this.sum = sum; this.average = average; studentCnt++; + for(int i = 0; i < 3; i++){ + scoreSum[i] += score[i]; + } + scoreSum[3] += sum; } public short getSum(){ diff --git a/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java index 55c376b..92f696e 100644 --- a/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java +++ b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java @@ -3,9 +3,7 @@ */ package whiteWeed.gradeManage; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; +import java.util.*; /** *
@@ -23,14 +21,17 @@ public class GradeTest2 {
 	
 	private static Scanner sc = new Scanner(System.in);
 	private static List gradeArray = new ArrayList();
-	private static List gradeSums = new ArrayList();
+	private static Map gradeSums = new HashMap();
 	
 	public static void main(String[] args) {
-		menuSelect();
+		boolean end = true;
+		while(end){
+			end = menuSelect();
+		}
 		sc.close();
 	}
 	
-	private static void menuSelect(){
+	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");
@@ -40,70 +41,74 @@ private static void menuSelect(){
 		int index = sc.nextInt();
 		sc.reset();
 		System.out.println();
+		
+		boolean end = true;
+		
 		switch(index){
 		case 1:
-			input();
-			menuSelect();
-			break;
+			while(end){
+				end = input();
+			}
+			return true;
 		case 2:
 			print();
-			menuSelect();
-			break;
+			return true;
 		case 3:
-			break;
+			return false;
+		default:
+			return true;
 		}
 	}
 	
-	private static void input(){
+	private static boolean input(){
 		byte[] score = {0, 0, 0};
 		short sum = 0;
 		float average;
-		System.out.print("> Name : ");
-		String name = sc.next();
-		sc.reset();
-		System.out.print("> Korean : ");
-		score[0] = sc.nextByte();
-		sc.reset();
-		sum += score[0];
-		System.out.print("> English : ");
-		score[1] = sc.nextByte();
-		sc.reset();
-		sum += score[1];
-		System.out.print("> Math : ");
-		score[2] = sc.nextByte();
-		sc.reset();
-		sum += score[2];
+		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(name, score, sum, average));
+		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":
-			input();
-			break;
+			return true;
 		case "N":
-			break;
+			return false;
+		default:
+			return false;
 		}
 	}
 	
 	private static void print(){
-		int[] sums = {0, 0, 0, 0};
-		
-		for(Grade2 grade : gradeArray){
-			gradeSums.add(grade.getSum());
+		for(int i = 0; i < Grade2.studentCnt; i++){
+			gradeSums.put(i, gradeArray.get(i).getSum());
 		}
-		gradeSums.toArray();
 		
-		for(int i = gradeArray.size()-1; i >= 0; i--){
-			for(int j = 0; j <= gradeArray.size()-1; j++){
-				short sum1 = gradeSums.get(i);
-				Grade2 grade1 = gradeArray.get(j);
-				if(sum1 == (grade1.getSum())){
-					grade1.setRank((short)(i + 1));
+		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")
@@ -114,16 +119,15 @@ private static void print(){
 			System.out.println(grade);
 		}
 		System.out.println("============================================");
-		for(Grade2 grade : gradeArray){
-			for(int i = 0; i < 3; i++){
-				sums[i] += grade.score[i];
-				sums[3] += grade.score[i];
-			}
+		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(String.format("%-10s", "Sum") + String.format("%-6d", sums[0]) + String.format("%-6d", sums[1])
-		+ String.format("%-6d", sums[2]) + String.format("%-6d", sums[3]));
-		System.out.println(String.format("%-10s", "Avg") 
-		+ String.format("%-6.1f", (float)sums[0]/Grade2.studentCnt) + String.format("%-6.1f", (float)sums[1]/Grade2.studentCnt)
-		+ String.format("%-6.1f", (float)sums[2]/Grade2.studentCnt) + String.format("%-6.1f", (float)sums[3]/Grade2.studentCnt));
+		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();
 	}
 }

From 0a7bbb0a59cd1e7680074c0c350e21a246c67508 Mon Sep 17 00:00:00 2001
From: whiteWeed 
Date: Mon, 3 Jul 2017 09:57:22 +0900
Subject: [PATCH 4/6] =?UTF-8?q?=EA=B2=8C=EC=9E=84=EC=83=B5=204=20=EC=A0=9C?=
 =?UTF-8?q?=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4~?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Solutions/whiteWeed/Game Shop/4/Armor.java    | 30 ++++++
 Solutions/whiteWeed/Game Shop/4/Item.java     | 35 +++++++
 Solutions/whiteWeed/Game Shop/4/Potion.java   | 33 +++++++
 Solutions/whiteWeed/Game Shop/4/Shop.java     | 92 +++++++++++++++++++
 .../whiteWeed/Game Shop/4/ShopTest2.java      | 56 +++++++++++
 Solutions/whiteWeed/Game Shop/4/Weapon.java   | 30 ++++++
 .../whiteWeed/Game Shop/4/equip_item.txt      |  5 +
 .../whiteWeed/Game Shop/4/potion_item.txt     |  5 +
 8 files changed, 286 insertions(+)
 create mode 100644 Solutions/whiteWeed/Game Shop/4/Armor.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/Item.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/Potion.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/Shop.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/ShopTest2.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/Weapon.java
 create mode 100644 Solutions/whiteWeed/Game Shop/4/equip_item.txt
 create mode 100644 Solutions/whiteWeed/Game Shop/4/potion_item.txt

diff --git a/Solutions/whiteWeed/Game Shop/4/Armor.java b/Solutions/whiteWeed/Game Shop/4/Armor.java
new file mode 100644
index 0000000..c350fa6
--- /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..85ddf1c --- /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..b1534dd --- /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..e683693 --- /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..f3f8ad4 --- /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..a291c6d --- /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 From 6f74a2691a531f579d042b53596ce8e6db5d0e79 Mon Sep 17 00:00:00 2001 From: whiteWeed Date: Mon, 17 Jul 2017 12:14:44 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=EA=B2=8C=EC=9E=84=20=EC=83=81=EC=A0=90=204?= =?UTF-8?q?=EB=B2=88=20=EB=8B=A4=EC=8B=9C=20=EC=A0=9C=EC=B6=9C=ED=95=B4?= =?UTF-8?q?=EC=9A=94!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solutions/whiteWeed/Game Shop/4/Armor.java | 2 +- Solutions/whiteWeed/Game Shop/4/Item.java | 2 +- Solutions/whiteWeed/Game Shop/4/Potion.java | 2 +- Solutions/whiteWeed/Game Shop/4/Shop.java | 2 +- Solutions/whiteWeed/Game Shop/4/ShopTest2.java | 2 +- Solutions/whiteWeed/Game Shop/4/Weapon.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Solutions/whiteWeed/Game Shop/4/Armor.java b/Solutions/whiteWeed/Game Shop/4/Armor.java index c350fa6..e98baea 100644 --- a/Solutions/whiteWeed/Game Shop/4/Armor.java +++ b/Solutions/whiteWeed/Game Shop/4/Armor.java @@ -15,7 +15,7 @@ * @author : Weed * @version : 1.0 */ -public class Armor extends Item { +public class Armor extends Item { //ㅁㄴㅇㄹ private int defence; public Armor(String name, String description, int weight, int value, int defence){ diff --git a/Solutions/whiteWeed/Game Shop/4/Item.java b/Solutions/whiteWeed/Game Shop/4/Item.java index 85ddf1c..5c3b46a 100644 --- a/Solutions/whiteWeed/Game Shop/4/Item.java +++ b/Solutions/whiteWeed/Game Shop/4/Item.java @@ -15,7 +15,7 @@ * @author : Weed * @version : 1.0 */ -public class Item { +public class Item { //ㅁㄴㅇㄹ protected String name, description; protected int weight, value; diff --git a/Solutions/whiteWeed/Game Shop/4/Potion.java b/Solutions/whiteWeed/Game Shop/4/Potion.java index b1534dd..f3fb3a9 100644 --- a/Solutions/whiteWeed/Game Shop/4/Potion.java +++ b/Solutions/whiteWeed/Game Shop/4/Potion.java @@ -15,7 +15,7 @@ * @author : Weed * @version : 1.0 */ -public class Potion extends Item { +public class Potion extends Item { //ㅁㄴㅇㄹ String type; int capacity; diff --git a/Solutions/whiteWeed/Game Shop/4/Shop.java b/Solutions/whiteWeed/Game Shop/4/Shop.java index e683693..589828d 100644 --- a/Solutions/whiteWeed/Game Shop/4/Shop.java +++ b/Solutions/whiteWeed/Game Shop/4/Shop.java @@ -18,7 +18,7 @@ * @author : Weed * @version : 1.0 */ -public class Shop { +public class Shop { //ㅁㄴㅇㄹ String name; Item[] itemsArray; List strList = new ArrayList(); diff --git a/Solutions/whiteWeed/Game Shop/4/ShopTest2.java b/Solutions/whiteWeed/Game Shop/4/ShopTest2.java index f3f8ad4..6322a29 100644 --- a/Solutions/whiteWeed/Game Shop/4/ShopTest2.java +++ b/Solutions/whiteWeed/Game Shop/4/ShopTest2.java @@ -17,7 +17,7 @@ * @author : Weed * @version : 1.0 */ -public class ShopTest2 { +public class ShopTest2 { //ㅁㄴㅇㄹ private static Shop[] shops = { new Shop("Weapon/Armor", "equip_item.txt"), new Shop("Potion", "potion_item.txt") diff --git a/Solutions/whiteWeed/Game Shop/4/Weapon.java b/Solutions/whiteWeed/Game Shop/4/Weapon.java index a291c6d..35a8925 100644 --- a/Solutions/whiteWeed/Game Shop/4/Weapon.java +++ b/Solutions/whiteWeed/Game Shop/4/Weapon.java @@ -16,7 +16,7 @@ * @version : 1.0 */ public class Weapon extends Item { - private int damage; + private int damage; //ㅁㄴㅇㄹ public Weapon(String name, String description, int weight, int value, int damage){ super(name, description, weight, value); From b9fb41520b1f504e4748e0fefb87258e43bf5e72 Mon Sep 17 00:00:00 2001 From: whiteWeed Date: Mon, 17 Jul 2017 12:17:36 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=EC=84=B1=EC=A0=81=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EC=8B=9C=EC=8A=A4=ED=85=9C=202=EB=B2=88=20=EB=8B=A4=EC=8B=9C?= =?UTF-8?q?=20=EC=A0=9C=EC=B6=9C=ED=95=A9=EB=8B=88=EB=8B=A4~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Solutions/whiteWeed/Grade Management System/2/Grade2.java | 2 +- Solutions/whiteWeed/Grade Management System/2/GradeTest2.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Solutions/whiteWeed/Grade Management System/2/Grade2.java b/Solutions/whiteWeed/Grade Management System/2/Grade2.java index 73ce166..3ec92d7 100644 --- a/Solutions/whiteWeed/Grade Management System/2/Grade2.java +++ b/Solutions/whiteWeed/Grade Management System/2/Grade2.java @@ -15,7 +15,7 @@ * @author : Weed * @version : 1.0 */ -public class Grade2 { +public class Grade2 { //ㅁㄴㅇㄹ private String name; private short sum = 0, rank; private float average; diff --git a/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java index 92f696e..657a4e0 100644 --- a/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java +++ b/Solutions/whiteWeed/Grade Management System/2/GradeTest2.java @@ -17,7 +17,7 @@ * @author : Weed * @version : 1.0 */ -public class GradeTest2 { +public class GradeTest2 { //ㅁㄴㅇㄹ private static Scanner sc = new Scanner(System.in); private static List gradeArray = new ArrayList();