(Solved Homework): 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:

Don't use plagiarized sources. Get Your Custom Essay on
(Solved Homework): God be together with us…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

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;

}

}

Homework Ocean
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

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.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents