Hello everyone :)
My problem is that my input will not be transfered when i build a new Object.
To understand my problem i give you first the output:
Welcome Hero!
Show me your Attributes!
Enter your Name:
KIKI
Enter your Strength:
50
Enter your Health:
60
Enter your Intelligence:
40
Enter your Agility:
30
I am KIKI.
My Strength is 50 my Health is 60
My Intelligence is 40 and my Agility is 30
Please choose your Class you want to be trained in.
Press 1 for WARRIOR!
Press 2 for MAGE!
Press 3 for THIEF!
Press 4 for PRIEST!
1
After years of training im a Warrior now.
My Strength and Health are increased but my Intelligence and Agility are decreased.
I am now null the Destroyer
My Strength is 20 my Health is 50
My Intelligence is -30 and my Agility is -20
I can jump and run.
My Sword Strike penetrates deep into Enemys Flesh!!
The part i i made bolt is where the problem lies.
As you can see my input by strength was 50. In the bolt part its supposed to be 70 (increment of 20) but it only shows me the increment value.
How can i keep the value from the first input so when i choose warrior the input will be increased by 20?
my codes for the superclass are:
import java.util.*;
public class Human {
Scanner CharSet = new Scanner(System.in);
String name;
int strength, health, intelligence, agility;
public void MyChar() {
System.out.println("Enter your Name: ");
name = CharSet.next();
System.out.println("Enter your Strength: ");
strength = CharSet.nextInt();
System.out.println("Enter your Health: ");
health = CharSet.nextInt();
System.out.println("Enter your Intelligence: ");
intelligence = CharSet.nextInt();
System.out.println("Enter your Agility: ");
agility = CharSet.nextInt();
}
public void Reveal() {
System.out.println("I am " + name + ". ");
System.out.println("My Strength is " + strength + " my Health is " + health);
System.out.println("My Intelligence is " + intelligence + " and my Agility is " + agility);
}
public void BasicSkill() {
System.out.println("I can jump and run.");
}
}
My codes for the subclass are:
public class Warrior extends Human {
public void Reveal() {
System.out.println("After years of training im a Warrior now.");
System.out.println("My Strength and Health are increased but my Intelligence and Agility are decreased.");
System.out.println("I am now " + name + " the Destroyer ");
System.out.println("My Strength is " + (strength +20) + " my Health is " + (health +50));
System.out.println("My Intelligence is " + (intelligence - 30) + " and my Agility is " + (agility - 20));
}
public void WarriorSkill() {
System.out.println("My Sword Strike penetrates deep into Enemys Flesh!!");
}
}
And my codes for the Main:
import java.util.*;
public class TestHuman {
public static void main(String[] arguements) {
Scanner NewClass = new Scanner(System.in);
int choose;
System.out.println("Welcome Hero!");
System.out.println("Show me your Attributes!");
Human Hobject = new Human();
Hobject.MyChar();
Hobject.Reveal();
System.out.println("");
System.out.println("Please choose your Class you want to be trained in.");
System.out.println("Press 1 for WARRIOR!");
System.out.println("Press 2 for MAGE!");
System.out.println("Press 3 for THIEF!");
System.out.println("Press 4 for PRIEST!");
choose = NewClass.nextInt();
if (choose == 1) {
Warrior Wobject = new Warrior();
//Wobject.MyChar();
Wobject.Reveal();
Wobject.BasicSkill();
Wobject.WarriorSkill();
}
else {
System.out.println("When you are not even be able to choose from 1 to 4 you cant become a HERO!");
}
}
}
Thanks for helping