In: Computer Science
Instructions:
In this exercise, you’ll design a role playing character class. The Character class attributes should include the characters’s name, gender, class* and race (can be human, elf or dwarf), and additional integer attributes of Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma.
Your class should have a constructor that receives this data. For each attribute, provide setters and getters. The class should include methods that calculate and return the user’s total attributes (sums 6 attributes). Write a Java application that prompts for the character’s information, instantiates an object of class Character for that character and prints the information from that object, then calculates and prints the character’s total stats. It should also display the available classes for our application.
An example output:
Name: Draugr
Gender: Male
Class: Fighter
Race: Human
STR: 18
DEX: 12
CON: 15
INT: 9
WIS: 11
CHA: 10
TOTAL: 75
---------------------
Available Classes
************************
Fighter
Paladin
Ranger
Wizard
Thief
************************
Submission:
To submit, zip the entire project folder created by IntelliJ IDEA and submit on Learn. As we have a late submission policy, please submit your work on time. Otherwise you will receive deductions to your grades.
0-1 day late: -10,
1-2 days late: -20,
2-4 days late: -40,
4 days+ late: No grade!
// Character.java
public class Character
{
// fields
private String name;
private String gender;
private String char_class;
private String race;
private int strength;
private int dexterity;
private int constitution;
private int intelligence;
private int wisdom;
private int charisma;
// constructor to initialize the fields to specified
values
public Character(String name, String gender, String
char_class, String race, int strength, int dexterity, int
constitution, int intelligence, int wisdom, int charisma)
{
this.name = name;
this.gender = gender;
this.char_class = char_class;
this.race = race;
this.strength = strength;
this.dexterity = dexterity;
this.constitution =
constitution;
this.intelligence =
intelligence;
this.wisdom = wisdom;
this.charisma = charisma;
}
// setters
public void setName(String name)
{
this.name = name;
}
public void setGender(String gender)
{
this.gender = gender;
}
public void setChar_Class(String char_class)
{
this.char_class = char_class;
}
public void setRace(String race)
{
this.race = race;
}
public void setStrength(int strength)
{
this.strength = strength;
}
public void setDexterity(int dexterity)
{
this.dexterity = dexterity;
}
public void setConstitution(int constitution)
{
this.constitution =
constitution;
}
public void setIntelligence(int intelligence)
{
this.intelligence =
intelligence;
}
public void setWisdom(int wisdom)
{
this.wisdom = wisdom;
}
public void setCharisma(int charisma)
{
this.charisma = charisma;
}
// getters
public String getName()
{
return name;
}
public String getGender()
{
return gender;
}
public String getChar_Class()
{
return char_class;
}
public String getRace()
{
return race;
}
public int getStrength()
{
return strength;
}
public int getDexterity()
{
return dexterity;
}
public int getConstitution()
{
return constitution;
}
public int getIntelligence()
{
return intelligence;
}
public int getWisdom()
{
return wisdom;
}
public int getCharisma()
{
return charisma;
}
// method to calculate and return the user’s total
attributes
public int getTotal()
{
return (strength + dexterity +
constitution + intelligence + wisdom + charisma);
}
}
//end of Character.java
// CharacterDriver.java
import java.util.Scanner;
public class CharacterDriver {
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
String name, gender, char_class,
race;
int strength, dexterity,
constitution, intelligence, wisdom, charisma;
// input the details of the
Character from user
System.out.println("Enter the
details of the Character: ");
System.out.print("Name: ");
name = scan.nextLine();
System.out.print("Gender: ");
gender = scan.nextLine();
System.out.print("Class: ");
char_class = scan.nextLine();
System.out.print("Race: ");
race = scan.nextLine();
System.out.print("Strength:
");
strength = scan.nextInt();
System.out.print("Dexterity:
");
dexterity = scan.nextInt();
System.out.print("Constitution:
");
constitution =
scan.nextInt();
System.out.print("Intelligence:
");
intelligence =
scan.nextInt();
System.out.print("Wisdom: ");
wisdom = scan.nextInt();
System.out.print("Charisma:
");
charisma = scan.nextInt();
// create a Character object with
the input details
Character ch = new Character(name,
gender, char_class, race, strength, dexterity, constitution,
intelligence, wisdom, charisma);
// display the details of the
Character
System.out.println("\nName:
"+ch.getName());
System.out.println("Gender:
"+ch.getGender());
System.out.println("Class:
"+ch.getChar_Class());
System.out.println("Race:
"+ch.getRace());
System.out.println("\nSTR:
"+ch.getStrength());
System.out.println("DEX:
"+ch.getDexterity());
System.out.println("CON:
"+ch.getConstitution());
System.out.println("INT:
"+ch.getIntelligence());
System.out.println("WIS:
"+ch.getWisdom());
System.out.println("CHA:
"+ch.getCharisma());
System.out.println("\nTOTAL:
"+ch.getTotal()); // display total of all attributes
// display the available
classes
System.out.println("---------------------");
System.out.println("Available
Classes");
System.out.println("**********************");
System.out.println("Fighter\nPaladin\nRanger\nWizard\nThief");
System.out.println("**********************");
}
}
// end of CharacterDriver.java
Output: