Hello everyone...

For now i have build a Human class and i want to test it now but on 2 lines there is an error and both errors states "void expected".
I have a main function in my class but later i gonna remove it because i want this Human class later to be a Superclass and a warrior, mage and so on will be a subclass that inherits everything what i got so far in my Human class.

Errors are on line 13 and 32
Here are the codes.

import java.util.*; 

public class Human {
	
	public static void main(String[] arguements) {
	
	Scanner CharSet = new Scanner(System.in);
	
	String name;
	int strength, health, intelligence, agility;
	
	public void MyChar() {  //On this line is a error
	
	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() {     //On this line is a error

		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);
		}
	
	}

}

Hope you can help me with that...

you have name = CharSet.next()
perhaps what you need is CharSet.nextInt()

you have name = CharSet.next()
perhaps what you need is CharSet.nextInt()

No; that would result in an error because name is a String and nextInt() obviously returns an int. He might want to say name = CharSet.nextLine() but that is not the source of his compiler error. His compiler error is a result of trying to define two methods, MyChar() and Reveal(), inside of the main method. You can't define one method inside of another method like that. Moving the two methods outside of main will get rid of one error, but introduce another. In order to use the variables name, strength, health, intelligence, and agility in MyChar() and Reveal(), they should be declared as class variables. The other alternative would be to pass them as parameters into the MyChar and Reveal methods.

Hmmm... But its a String and Int will be for numbers.
Or doesn´t it matter?

Read my previous post. We posted at the same time.

@BestJewSinceJC
I noticed that after I posted.

@HelloMe: it does matter. however, i got the code compiling leaving the main method empty, and rewriting brackets. try that!

No; that would result in an error because name is a String and nextInt() obviously returns an int. He might want to say name = CharSet.nextLine() but that is not the source of his compiler error. His compiler error is a result of trying to define two methods, MyChar() and Reveal(), inside of the main method. You can't define one method inside of another method like that. Moving the two methods outside of main will get rid of one error, but introduce another. In order to use the variables name, strength, health, intelligence, and agility in MyChar() and Reveal(), they should be declared as class variables. The other alternative would be to pass them as parameters into the MyChar and Reveal methods.

Oje, :-)
How about i get rid of main and make another class TestHuman with the main would that help?

@BestJewSinceJC
I noticed that after I posted.

@HelloMe: it does matter. however, i got the code compiling leaving the main method empty, and rewriting brackets. try that!

My main method is empty now but don´t know what you mean with rewriting the brackets :-)

BTW Thanks to both of you for your help i really apprechiate it...

My main method is empty now but don´t know what you mean with rewriting the brackets :-)

BTW Thanks to both of you for your help i really apprechiate it...

He was just repeating what I said. Anyway, it would be helpful to have your main driver in another class... the TestHuman class is a good idea. Just make sure to define your variables as class variables by putting them like this in your Human class:

public class Human{
//Your variable declarations go up here if they're class variables!
}

He was just repeating what I said. Anyway, it would be helpful to have your main driver in another class... the TestHuman class is a good idea. Just make sure to define your variables as class variables by putting them like this in your Human class:

public class Human{
//Your variable declarations go up here if they're class variables!
}

Grrr i had a short Blackout... i will try your suggestion now please don´t run away :-P

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.