Question

In: Computer Science

Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should...

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!

Solutions

Expert Solution

// 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:


Related Solutions

Windows Forms application using Visual Basic: Create a class called Character that a role-playing game might...
Windows Forms application using Visual Basic: Create a class called Character that a role-playing game might use to represent a character within the game. A character should include six stats as instance variables – strength, dexterity, constitution, intelligence, wisdom and charisma (all types are int). Your class should have a constructor that initializes these six instance variables. Provide Properties with an appropriate set and get block for each instance variable. In addition, provide a method named getStatsTotal that calculates the...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of Bernard Ferrion (played by Leslie Jordan). Catherine ended being found not guilty, but it led Betty to wonder: are men and women treated differently when convicted of murder? As a result, Betty took two random samples of convicted murderers, given below, and determined how long the sentences were. Men: 25, 30, 50, 25, 20, 30, 40, 25, 30, 25, 75, 25, 15 Women: 25,...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of Bernard Ferrion (played by Leslie Jordan). Catherine ended being found not guilty, but it led Betty to wonder: are men and women treated differently when convicted of murder? As a result, Betty took two random samples of convicted murderers, given below, and determined how long the sentences were. Men: 25, 30, 50, 25, 20, 30, 40, 25, 30, 25, 75, 25, 15 Women: 25,...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of...
While playing the role of Catherine Piper on Boston Legal, Betty White “killed” the character of Bernard Ferrion (played by Leslie Jordan). Catherine ended being found not guilty, but it led Betty to wonder: are men and women treated differently when convicted of murder? As a result, Betty took two random samples of convicted murderers, given below, and determined how long the sentences were. Men: 25, 30, 50, 25, 20, 30, 40, 25, 30, 25, 75, 25, 15 Women: 25,...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE-...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE- class-level attribute initialized to 1000 -acctID: int -bank: String -acctType: String (ex: checking, savings) -balance: Float METHODS: <<Constructor>>Account(id:int, bank: String, type:String, bal:float) +getAcctID(void): int                        NOTE: retrieving a CLASS-LEVEL attribute! -setAcctID(newID: int): void           NOTE: PRIVATE method +getBank(void): String +setBank(newBank: String): void +getBalance(void): float +setBalance(newBal: float): void +str(void): String NOTE: Description: prints the information for the account one item per line. For example: Account #:        ...
Class Instructions You will create a password verification program using C-strings and character testing. The user...
Class Instructions You will create a password verification program using C-strings and character testing. The user will enter a password as a C-string. (Character array). You must test that the password contains at least: One lowercase letter One uppercase letter One number (0-9) The password can contain no spaces You are to add one more requirement to the password. I need help in setting this program up. #include <iostream> #include <cctype> using namespace std; int main() { char input; cout...
(a) Create a Card class that represents a playing card. It should have an int instance...
(a) Create a Card class that represents a playing card. It should have an int instance variable named rank and a char variable named suit. Include the following methods: A constructor with two arguments for initializing the two instance variables. A copy constructor. A method equals — with one argument — which compares the calling object with another Card and returns true if and only if the corresponding ranks and suits are equal. Make sure your method will not generate...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # #...
#Write a class called "Burrito". A Burrito should have the #following attributes (instance variables): # # - meat # - to_go # - rice # - beans # - extra_meat (default: False) # - guacamole (default: False) # - cheese (default: False) # - pico (default: False) # - corn (default: False) # #The constructor should let any of these attributes be #changed when the object is instantiated. The attributes #with a default value should be optional. Both positional #and...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:   ...
Programming Exercise Implement the following class design: class Tune { private:    string title; public:    Tune();    Tune( const string &n );      const string & get_title() const; }; class Music_collection { private: int number; // the number of tunes actually in the collection int max; // the number of tunes the collection will ever be able to hold Tune *collection; // a dynamic array of Tunes: "Music_collection has-many Tunes" public: // default value of max is a conservative...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT