Answer to Question #213639 in Java | JSP | JSF for Karon Aldrich

Question #213639

Question )  Implement an object oriented ’Character’ class to capture the common attributes and actions of all characters in your game.

Code) Read input from the keyboard to let the user provide values for your character’s attributes of a specific character object (not a superclass object) your code will create.

Code)  Since the user could mistype or introduce problems with their typed input, handle all exceptions with exception handling as part of your character data gathering code.

Code) Create a superclass character object, and call its attack method to demonstrate its use 



1
Expert's answer
2021-07-05T01:07:24-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Character c=new Character();
		c.getData();
		c.print();
	}
}


class Character{
    private String text;
    private int num;
    Character(){
        text="";
        num=0;
    }
    void getData(){
        Scanner s=new Scanner(System.in);
        text=s.next();
        num=s.nextInt();
    }
    void print(){
        System.out.println("Text is:"+text);
        System.out.println("Num is:"+num);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS