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
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);
}
}
Comments
Leave a comment