Question: String and Regex Lab Part 1 : Strings and String Methods in Java: Take the given example code which is part of a simple conversation

String and Regex Lab
Part 1: Strings and String Methods in Java:
Take the given example code which is part of a simple conversation/messaging system. Review the code to make sure you are familiar with the String methods that it is currently using. We are going to be adding more functionality to it. Currently, we have Topics, that consist of a title, some content, and some options. The user is shown the content and then the options allow the user to respond. Those responses then link to another topic.
:: Yes
Thank you stranger, we are lost in the woods. Can you help us find the way out?
[[Okay I can help]]
[[Find your own way]]
Objective 1: Adding decoration text
So right now what the users response options are exactly what topic it goes to. We need to have some way of saying one thing that goes to another named topic. It would be really annoying to have a player option say 3 or 4 sentences and then have to name a topic those same 3 or 4 sentences. Instead lets do something like:
[[Okay I can do that-> Accept]]
Now what it shows to the user is the text at the beginning but if that option is selected it will go to the Accept topic.
Objective 2: Adding variables
We will be adding a way to set variables based on where the user goes in the conversation. The format for how variables will be set should look something like:
<>
We will be focusing on integer (whole numbers) and string datatypes. Floating or any other datatypes are not required to be implemented. I typically do not consider capitalization for either the command (set) or the variable name but I will leave that option up to you. You can choose however you want to store/save the variables for later, but keep in mind that later we will need to retrieve them.
Bonus 5-10%: include some basic math for the integer type variables (make sure you indicate this on the submission page if you want credit)
Objective 3: Getting Variables
Now we need to add the ability to retrieve variables. So we will add a get command that looks something like:
<>
This doesnt have a lot of utility but will be used in the next objective. It could be used to say count the number of times youve done stuff (if some simple math was added to the variables to allow them to count). This could also be used to store names like storing the player name and getting it whenever another player said hello for instance:
:: Greet
Hello <>. How are you doing
[[Well I could be better -> Okay]]
Objective 4:
The last objective is to add a conditional statement. Im fine with you guys working out the format of this command a bit for yourself but this is how I do it:
<>=1>>Since you are helping us how about I cheer you on!<>
So conditionals do nothing if you arent getting variables (though if you wanted to make the if statement automatically get variables without having to use the get command that would work too). And the goal of the if statement is to check a variable to either open up content text (like in the example above) or open up player options (that would take you to other topics).
<>=1>>[[Your cheers are greatly appreciated -> Yes]]<>
This example shows a player option that is only available if the AcceptMission variable is set to 1. I also typically abbreviate this as:
<>[[Your cheers are greatly appreciated -> Yes]]<>
Since I often want to know just if a variable exists (note this does automatically use the get command). One final note is that I end all of my if statements with an <> this is because text could be multiple lines long. The endif is a clear indication of when Im through with the if statement.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!