-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 22a4c58
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.decisionmaker; | ||
|
||
public class Decision { | ||
|
||
private String item; | ||
private int weight; | ||
private String type; | ||
|
||
public String getItem() { | ||
return item; | ||
} | ||
public void setItem(String item) { | ||
this.item = item; | ||
} | ||
public int getWeight() { | ||
return weight; | ||
} | ||
public void setWeight(int weight) { | ||
this.weight = weight; | ||
} | ||
public String getType() { | ||
return type; | ||
} | ||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.decisionmaker; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DecisionCalculator { | ||
|
||
private static int pro_count; | ||
private static int con_count; | ||
private static String winner; | ||
|
||
public static int getPro_count() { | ||
return pro_count; | ||
} | ||
|
||
public static int getCon_count() { | ||
return con_count; | ||
} | ||
|
||
public static String getWinner(){ | ||
return winner; | ||
} | ||
|
||
public static void calculate(ArrayList<Decision> myList){ | ||
for (int i = 0; i <= (myList.size()-1); i++){ | ||
if (myList.get(i).getType().equals("PRO")){ | ||
pro_count += myList.get(i).getWeight(); | ||
} else if (myList.get(i).getType().equals("CON")){ | ||
con_count += myList.get(i).getWeight(); | ||
} | ||
} | ||
|
||
if (pro_count < con_count){ | ||
winner = "CON wins!"; | ||
} else if (pro_count > con_count){ | ||
winner = "PRO wins!"; | ||
} else if (pro_count == con_count){ | ||
winner = "Tie! Filp a coin!"; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.decisionmaker; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DecisionController { | ||
//store the decision item in an array list | ||
public static ArrayList<Decision> myList = new ArrayList<Decision>(); | ||
|
||
public static void storeDecisionInMemory(Decision decision){ | ||
myList.add(decision); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.decisionmaker; | ||
|
||
import java.util.Scanner; | ||
|
||
public class DecisionDemo { | ||
|
||
public static void main(String[] args) { | ||
|
||
String item; | ||
int weight; | ||
String type; | ||
|
||
Scanner in = new Scanner(System.in); | ||
// need this so scanner works properly | ||
in.useDelimiter("\\n"); | ||
|
||
//lets the user input three items in their decision table | ||
for (int i = 0; i <= 1; i++){ | ||
|
||
System.out.println("Enter the item you want to add to your list:"); | ||
item = in.next(); | ||
System.out.println("Enter its relative weight (1-10):"); | ||
weight = in.nextInt(); | ||
System.out.println("Is it a PRO or a CON?:"); | ||
type = in.next(); | ||
|
||
Decision obj = new Decision(); | ||
obj.setItem(item); | ||
obj.setWeight(weight); | ||
obj.setType(type); | ||
|
||
DecisionController.storeDecisionInMemory(obj); | ||
|
||
} | ||
|
||
DecisionView.display(DecisionController.myList); | ||
in.close(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.decisionmaker; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class DecisionView { | ||
public static void display(ArrayList<Decision> myList){ | ||
|
||
//print all the items, their type, and their weight | ||
for (int i = 0; i <= (myList.size()-1); i++){ | ||
System.out.println("Item: "+myList.get(i).getItem()+" --- Type: "+myList.get(i).getType()+" --- Weight: "+myList.get(i).getWeight()); | ||
} | ||
|
||
|
||
//print the totals for pros and cons | ||
DecisionCalculator.calculate(DecisionController.myList); | ||
System.out.println(); | ||
System.out.println("PRO: "+DecisionCalculator.getPro_count()+" CON: "+DecisionCalculator.getCon_count()); | ||
System.out.println(); | ||
|
||
//print the winner | ||
System.out.println("Decision: "+DecisionCalculator.getWinner()); | ||
} | ||
} |