Question:
Java Programming Help?
2011-12-17 17:12:13 UTC
THe code below has issues where the if else statement for arfter the armor segment of code, if i enter 1, iut stops, but if i enter 2, it will continue. Please help

System.out.print("Welcome to the Colliseum. Today, after being taken prisoner by the wizard Ultimor; You must fight\n" +
"a series of monsters and villians, to earn your freedom, and finally confront the dark wizard, Ultimor.");
System.out.print("\n*********************************************************************************************************");
System.out.println("\nIt is dark. You are tired. You remember nothing. You find you are mixed with feelings of concern and fright. ");
System.out.print("\"PRISONER! Get up!\"");



//Dialogue Section A

Scanner ChatA = new Scanner(System.in);
Scanner ChatA2 = new Scanner(System.in);
int ChatA1;

System.out.print("\n1.Reply back \"I'm Up!\"" + "\n2.Yell Back \"Screw off!\"" + "\n3.Ask Him \"Where am I?\"\n");
ChatA1 = ChatA.nextInt();


if (ChatA1 ==1){
System.out.print("\n\"Alright, you better be ready to fight the mighty Thalmor! He is an elven menace, and I doubt I'll be seeing you anytime soon.\n Be prepared for a battle, your fighting for your freedom now.\"");
}else if (ChatA1 == 2){
System.out.print("\n\"Shut up you blasted prisoner, get ready to die at the hands of the mighty elven Thalmor. I hope he rips your guts out in this gladiator battle.\"");
}else if (ChatA1 == 3){
System.out.print("\n\"Where are yeh? Your the prisoner of Ultimor, and your in his keep. \nOh, and the good news is, you have to fight your way to freedom in a series of gladiator battles. Prepare yourself, your fighting Thalmor. He is a menacing elf. Best of luck.\"");
}

String CharName; //CHARACTERS PERMANENT NAME
System.out.print("\n\n\"Also Prisoner, tell me your name.\": ");
CharName = ChatA2.next();


//Dialogue Section B
Scanner Armorchoice = new Scanner(System.in);
int ArmorChoice; //IMPORTANT VARIABLE - PERMANENT CHOICE
System.out.print("*********************************************************************************************************************");
System.out.print("\n\nThe guard roughly grabs you by the arm, and pulls you toward a large keep door, covered in bloodstains and filth.\nYou get a feeling in your gut that tells you that these could be your last moments.");
System.out.print("\nThe Guard says: \"Good Luck " + CharName + ", Up this hallway, is the armory. Prepare yourself for battle.\"");
System.out.print("\nThe guard opens the large door for you, and as you walk up the flight of stairs, he closes it, and you hear it latch shut. You now know, there is only one way out.");
System.out.print("\n\n*****************************************************************************************************************");
//Armory Dialogue

System.out.print("\nYou finish your walk up the rugged stairs, and see a tall gentleman pleasently waiting for you.");
System.out.print("\n\"Good day Sir, welcome to the armory. It may not look like much, but this is my pride and joy.\nI have, been instructed to provide with your choice of weaponry and armor.");
System.out.print("\nYou have 2 Choices for battle. You may take a light armor set, with robes and leather padding, along with better spell usage.\nOr perhaps you may take a heavy armor set, with steel plates and a powerful sword.\nYour Choice\"(1 for Heavy, 2 for Light): ");

int temporary; //Used to determine threshold
int DT; // DAMAGE THRESHOLD
int ST; // Spell Power
int WT; // Weapon Power
temporary = Armorchoice.nextInt();
if(temporary == 1){
DT = 20;
WT = 20;
ST = 10;
ArmorChoice=1;
System.out.print("\n" + CharName + ", you are a Warrior. Your Steel Armor makes you more resistant to punishment.\nYour Strong Sword makes you attack with great force,\nhowever, your choice makes your spell attacks pitiful, and this could possibly become a disadvantage later.");
}else if(temporary == 2){
DT = 10;
WT = 15;
ST = 20;
ArmorChoice=2;
System.out.print("\n" + CharName + ", you are a Sorcerer. Your Robes make you somewhat vulnerable to punishment.\nYour Normal Sword does not give you a great advantage,\nbut your choice makes your spells powerful, and can lay waste to almost any enemy.");

//Dia
Three answers:
McFate
2011-12-17 17:25:13 UTC
I would not recommend creating several different scanners on System.in. I would recommend you create just ONE scanner, and use it throughout your code.



It's possible that your scanner is getting tripped up by characters that other scanners have already read.



@M
b4iquit
2011-12-18 00:20:26 UTC
I have successfully run your code on all options. All i did was add a '}' at the very end. I have to agree with the other person that having that many System.in Scanners may be the cause of your problem, the code may behave differently on different hardware, which would explain while all three options take me through all of your code. Email me if I can help further.



be safe, be sage
mattia
2016-11-13 15:08:47 UTC
Why roll your man or woman whilst there is in all probability a calendar widget you could reuse? via how, the Java API itself supplies many functional instructions and interfaces: Date, Calendar, GregorianCalendar, DateFormat, and SimpleDateFormat.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...