A Fighter/Mage is one of the stronger multi-classes at the end of Baldur’s Gate 2, the seminal role-playing video game (cRPG) developed by BioWare. For character creation of a Fighter/Mage, the highest dice rolls should be allocated to strength (STR), intelligence (INT), dexterity (DEX), and constitution (CON) – in that order – and the lower statistics should go into wisdom (WIS) and charisma (CHA). Fill in code at the three (3) places marked YOUR CODE HERE. Upload your program.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Main {
public static class dndCharacter {
private String name;
private int STR;
private int INT;
private int DEX;
private int CON;
private int WIS;
private int CHA;
public dndCharacter(String myName) {
name = myName;
List statList = new ArrayList();
// get 6 random stats
for (int i = 0; i < 6; i++) {
statList.add(characterStat());
}
// order statList low to high
Collections.sort(statList);
// access elements with statList.get(index) for index f
rom 0 to 5
// assign the character statistics high to low STR INT
DEX CON WIS CHA
// with values from the ordered statList
// YOUR CODE HERE
}
public String about() {
String aboutMe = “”;
aboutMe += “Hi! My name is ” + name+”\n”;
aboutMe += “I am a Fighter/Mage”+”\n”;
if (STR + INT + DEX + CON + WIS + CHA > 6 * 9) {
aboutMe += “I am rather good at questing\n”;
aboutMe += “Strength: ” + STR+”\n”;
aboutMe += “Intelligence: ” + INT+”\n”;
aboutMe += “Dexterity: ” + DEX+”\n”;
aboutMe += “Constitution: ” + CON+”\n”;
aboutMe += “Wisdom: ” + WIS+”\n”;
aboutMe += “Charisma: ” + CHA+”\n”;
} else {
aboutMe += “But enough about me…”;
}
// create the correct return statement
// YOUR CODE HERE
}
static int characterStat() {
Random random = new Random();
int d1 = random.nextInt(5) + 1;
int d2 = random.nextInt(5) + 1;
int d3 = random.nextInt(5) + 1;
int d4 = random.nextInt(5) + 1;
int diceSum = d1 + d2 + d3 + d4;
int min = Math.min(d1, d2);
min = Math.min(min, d3);
min = Math.min(min, d4);
diceSum -= min;
return diceSum;
}
}
public static void main(String[] args) {
// YOUR CODE HERE
// modify myName to initialize dndCharacter
Main.dndCharacter FighterMage = new dndCharacter(“”);
System.out.println(FighterMage.about());
}
}