Question
This is Java problem this is the questions and i have some of the code already. Your program will implement the following two interfaces: -Interface
This is Java problem this is the questions and i have some of the code already.
Your program will implement the following two interfaces:
-Interface LifeForm: This interface defines the methods necessary for a life-form to participate in the simulation. It defines the following methods: getChar(): Returns a character to display on the screen getX(),
getY(): Returns the x & y position of the life-form setX(int x), setY(int y): Set the x & y position of the life-form o Interface Moveable: This interface defines the move() method necessary for every life-form to make a legal move in different directions.
Your program will implement five classes. The behavior of each class is described below:
-An abstract class AbstractLifeForm that implements the LifeForm interface: Data Fields: x and y position of a life-form. Constructors: - A default constructor to create an instance of the Java Object class. - Another constructor to create an abstract life form with initial x and y positions passed as parameters. Behavior: - Override the get and set methods defined in the LifeForm interface. - Override the toString() method to display the x and y positions.
these are the code
these two are the one i stuggle with.
The following four classes are different types of life-forms. Three of these classes also implement the interface Moveable (except for the Plant which remains stationary). The general properties are defined as follows: 1. Plant class: Denoted by the constant character P. Constructors: 1) A default constructor and 2) a constructor that takes in the initial x and y positions as the parameters. Behavior: Override the getChar()method.
2.Sparrow class: Denoted by the constant character S. A sparrow can move in either of the 4 directions (North, South, East, West). Constructors: 1) A default constructor that sets the default direction (you can choose the initial direction) and the move count to 1. 2) A constructor that takes in the initial x and y positions as the parameters. Behavior: Override the getChar()method. Override the move()method. The sparrow moves in any of the 4 directions random cell steps at a time. (i.e after every random cell steps forward or backward change the direction of sparrow)
how do i make these do i implement moveable and lifeform or just lifeform?
Interface LifeForm (Filenamc LifeForm.javal oublic Interface LifeFom ( public char getChar: public int getxD: uublic int gelYD public void setXint x public vold sety(Int yl; Interface Moveable (Filename Moveable.java) oublic interface Moveable vublic void movell class AbstractLifeForm (Filename- AbstractLifeForm.java) vublic abstract class AbslracLifeFor mplemels LifeFurm, Moveablel private int X; prvate Int Y default constructor oublic AbstractuifeFormo oublic AbstractLifeFormlint x, int y) ovcrriding the methods from interfaces Override public vold setxint x @Override public void set(int y) @Override public String toString return X-XY-"+Y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started