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

System.out.println("My Strength is " + (strength +20) + " my Health is " + (health +50));

doesn't change the value of strength. On a separate line, write strength = strength + 20; and it will change the value of strength. Is that what you were asking?

System.out.println("My Strength is " + (strength +20) + " my Health is " + (health +50));

doesn't change the value of strength. On a separate line, write strength = strength + 20; and it will change the value of strength. Is that what you were asking?

Thanks first that you are still awake :)

strength = stregth +20
Gives me still the output 20

it´s supposed to be 70
Because i give my attributes strength 50
and after years of training i become stronger so 50 + 20

The first imput is will be acctualy a Human object...
When i choose warrior it needs to add.

When i use immediatly a warrior object it works output will be 70. But later i want to add other classes like mage. So it should take the input from the human object and adjust it to the class choosen.l

Hope you know what i mean :)

That's because for your WObject you never called MyChar() which is the only place I can see where you could have set the strength to 50.

That's because for your WObject you never called MyChar() which is the only place I can see where you could have set the strength to 50.

Yes, if i would call the Wobject.MyChar(); right from the beginning instead of Hobject.MyChar(); then it works... problem only if i add a Mage class with other increase and decrease attributes.
Thats the reason i try to get the input from the Hobject to adjust to my warrior and mage and so on.

Sadly i can not use + (Hobject.strength +20) in my warrior class

If you want a Warrior to have a starting strength of 50, then in the Warrior class put int strength = 50; and do similarly for the other variables. By default, Warrior will inherit 'strength' and your other variables from Human. But in the Human class, you do not have 'strength' or any other variables set to a default value. I'd also recommend making a setStrength() method and a getStrength() method, and similar get and set methods for the other variables in your Human class. That way when you want to set a Warrior's strength, you can say WObject.setStrength(50);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.