Answered Essay: God be together with us

Part 1:

Your supervisor, Lester Zamboni, has been approached by a member of the team responsible for building separate types of characters in Legendary Epics. Knowing that you are his ace programmer on the team, he volunteered you to help build new features in the character creation routine:

Background: Most combat-based games have different types of character classes that fulfill different types of roles. In Legendary Epics, there are four roles: Barbarian, Magician, Cleric, and Rogue. Each has their own strengths and weaknesses, but after entering a character name, the user must choose one of the four roles. Present the user with an input box that takes their choice. Note: The input box needs to expect a 1, 2, 3, or 4. If anything different is entered, you should automatically default the role to Barbarian.

You will need to add this code to Character.java:

A new class instance variable that is a string, called charRole.

A new setter and getter (setCharRole() and getCharRole()). Notice that setCharRole() accepts a string argument.

You will need to add this code to Charactergen.java:

Create a method called roleSelect() that accepts a single string as input parameter. roleSelect() should do these things:

Convert the string input variable to integer through Integer.ParseInt, because data entered in an input box is stored as a string, so you have to convert the data type to integer for processing your switch statement.

Declare a string that will be the string variable that will be returned from this method.

Create a switch statement with 4 cases, each one corresponding with the 4 possible roles in the game. If the user enters anything else, the default case should be Barbarian.

Return the resulting role from the method.

In the main method, make a call to human.setCharRole, using a call to roleSelect() as a parameter.

In the main method, when you call displayOutput(), add getCharRole() as a fourth variable to pass.

In the displayOutput() method, make sure that you add the fourth parameter that represents the user’s role.

Modify the output text, so that it passes the string value of the player’s Role.

Part 2:

At lunch on Friday, a fellow coder who is working on the vendor modules in Legendary Epics needs you to help with a few lines of the code. The vendor code is a bit dynamic, as an item has an advertised price, as well as an acceptable minimum price, which the player cannot see. Write a brief program based on this scenario:

Create an integer CONSTANT that represents named ADVERTISEDPRICE equal to 15.

Create an integer CONSTANT that represents named MINIMUMPRICE equal to 12.

Prompt the user with this input box: “The vendor is offering this item at 15, but you might be able to bargain with him. How much do you wish to offer?”

Evaluate the offer in this manner, using if…else:

If the user offers 11 or less or 16 or more, show the text box below:

If the user offers 12 to 15, show the text box below:

and this is the codes

character.java

// This is a class definition for the Character class.

public class Character

{

// Declare instance variables

private String charName;

private int startHealth;

private double startCurrency;

// **** Add a string variable named charRole

// Declare object methods, getters and setters for character name, health, and currency

// ****** Add a setter named setCharRole

// ****** Add a getter named getCharRole

public void setCharName(String cName)

{

charName = cName;

}

public String getCharName()

{

return charName;

}

public void setHealth(int health)

{

startHealth = health;

}

public int getHealth()

{

return startHealth;

}

public void setCurrency(double currency)

{

startCurrency = currency;

}

public double getCurrency()

{

return startCurrency;

}

}

2) Charctergen.java

import javax.swing.JOptionPane;

import java.text.*;

public class Charactergen {

// This is the main method

public static void main(String[] args)

{

// Declare variables

final double BASE_CURRENCY = 10.55;

final int BASE_HEALTH = 50;

int minHealthBonus = 1;

int maxHealthBonus = 5;

String cName;

 

// Create a new character object named human

Character human = new Character();

// Use the Character class method to SET the character’s name by prompting the user to enter a character name

human.setCharName(JOptionPane.showInputDialog(null,”Enter your character’s name: “, “Welcome to Legendary Epics!”, JOptionPane.QUESTION_MESSAGE));

// ***** Use the Character class method to SET the character’s role by calling the roleSelect method, passing an integer that returns a string)

// Use the Character class method to SET the character’s health by calling the calculateHealth method, passing BASE_HEALTH, minHealthBonus, and maxHealthBonus as parameters

human.setHealth(calculateHealth(BASE_HEALTH, minHealthBonus, maxHealthBonus));

// Use the Character class method to SET the character’s currency by calling the setCurrency method, passing BASE_CURRENCY as a parameter

human.setCurrency(calculateCurrency(BASE_CURRENCY));

// Call the displayOutput Method by passing the values of character name, role, starting health, and starting currency through the Character class GETTER methods

// ***** Modify the line below to add the role.

displayOutput(human.getCharName(), human.getHealth(), human.getCurrency());

}

// ***** Create a Method called roleSelect() here that sets the character’s role, using a switch statement.

// This method calculates the starting health of the character by accepting 3 parameters

public static int calculateHealth(int bh, int minhb, int maxhb)

{

int health = bh + minhb + (int)(Math.random() * maxhb);

return health;

}

// This method calculates the starting credits of the character by accepting one parameter

public static double calculateCurrency(double cash)

{

//Compute Currency

double startCurrency = cash – Math.random();

return startCurrency;

}

// This method displays the output to the user

// ****** Modify the method header below so that it also accepts the Character’s role as an input parameter.

public static void displayOutput(String charName, int startHealth, double startCurrency)

{

// Create a new decimal format to truncate double output

DecimalFormat df = new DecimalFormat(“#.##”);

// Display output to the user

// ***** Modify the code below so that it also display’s the character’s class.

JOptionPane.showMessageDialog(null,”Your name is ” + charName + “, your starting health is ” + startHealth+ “, and your starting credits are ” + Double.valueOf(df.format(startCurrency))+ “.”, “Your Character Stats”, JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

Show transcribed image textWelcome to Legendary Epics! Enter a number that represents your desired character class. 1-Barbarian, 2-Magician, 3-Cleric, 4-Rogue: OK Cancel

Expert Answer

 

Hi,

I have ipdated the code and highlghted the changes below.

Charactergen.java

import javax.swing.JOptionPane;

import java.text.*;

public class Charactergen {

// This is the main method

public static void main(String[] args)

{

// Declare variables

final double BASE_CURRENCY = 10.55;

final int ADVERTISEDPRICE = 15;

final int MINIMUMPRICE = 12;

final int BASE_HEALTH = 50;

int minHealthBonus = 1;

int maxHealthBonus = 5;

String cName;

 

// Create a new character object named human

Character human = new Character();

// Use the Character class method to SET the character’s name by prompting the user to enter a character name

human.setCharName(JOptionPane.showInputDialog(null,”Enter your character’s name: “, “Welcome to Legendary Epics!”, JOptionPane.QUESTION_MESSAGE));

// ***** Use the Character class method to SET the character’s role by calling the roleSelect method, passing an integer that returns a string)

// Use the Character class method to SET the character’s health by calling the calculateHealth method, passing BASE_HEALTH, minHealthBonus, and maxHealthBonus as parameters

human.setHealth(calculateHealth(BASE_HEALTH, minHealthBonus, maxHealthBonus));

// Use the Character class method to SET the character’s currency by calling the setCurrency method, passing BASE_CURRENCY as a parameter

human.setCurrency(calculateCurrency(BASE_CURRENCY));

// Call the displayOutput Method by passing the values of character name, role, starting health, and starting currency through the Character class GETTER methods

human.setCharRole(roleSelect(“Enter a number that represents your desired character class. 1. Barbariann 2. Magician 3. Cheric 4. Rogue:”));

// ***** Modify the line below to add the role.

displayOutput(human.getCharName(), human.getHealth(), human.getCurrency(), human.getCharRole());

int offer = Integer.parseInt(JOptionPane.showInputDialog(“The vendor is offering this item at 15, but you might be able to bargain with him. How much do you wish to offer?”));

if(offer >=MINIMUMPRICE && offer <=ADVERTISEDPRICE) {

JOptionPane.showMessageDialog(null, “With a smirk, the vendor accepts your offer of 14 credirs.”);

} else {

JOptionPane.showMessageDialog(null, “The Vendor rejects your offer of 10, because your are clearly not thinking properly.”);

}

}

// ***** Create a Method called roleSelect() here that sets the character’s role, using a switch statement.

public static String roleSelect(String input) {

int choice = Integer.parseInt(JOptionPane.showInputDialog(input));

String role;

switch(choice) {

case 1: role = “Barbarian”;break;

case 2: role = “Magician”;break;

case 3: role = “Cleric”;break;

case 4: role = “Rogue”;break;

default: role = “Barbarian”;

}

return role;

}

// This method calculates the starting health of the character by accepting 3 parameters

public static int calculateHealth(int bh, int minhb, int maxhb)

{

int health = bh + minhb + (int)(Math.random() * maxhb);

return health;

}

// This method calculates the starting credits of the character by accepting one parameter

public static double calculateCurrency(double cash)

{

//Compute Currency

double startCurrency = cash – Math.random();

return startCurrency;

}

// This method displays the output to the user

// ****** Modify the method header below so that it also accepts the Character’s role as an input parameter.

public static void displayOutput(String charName, int startHealth, double startCurrency, String charRole)

{

// Create a new decimal format to truncate double output

DecimalFormat df = new DecimalFormat(“#.##”);

// Display output to the user

// ***** Modify the code below so that it also display’s the character’s class.

JOptionPane.showMessageDialog(null,”Your name is ” + charName + ” the “+charRole+”, your starting health is ” + startHealth+ “, and your starting credits are ” + Double.valueOf(df.format(startCurrency))+ “.”, “Your Character Stats”, JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}

Character.java

public class Character

{

// Declare instance variables

private String charName;

private int startHealth;

private double startCurrency;

private String charRole;

// **** Add a string variable named charRole

// Declare object methods, getters and setters for character name, health, and currency

// ****** Add a setter named setCharRole

// ****** Add a getter named getCharRole

public String getCharRole() {

return charRole;

}

public void setCharRole(String charRole) {

this.charRole = charRole;

}

public void setCharName(String cName)

{

charName = cName;

}

public String getCharName()

{

return charName;

}

public void setHealth(int health)

{

startHealth = health;

}

public int getHealth()

{

return startHealth;

}

public void setCurrency(double currency)

{

startCurrency = currency;

}

public double getCurrency()

{

return startCurrency;

}

}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.