Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I keep getting these errors. Can someone please help me? Write javadoc style comments for the program. ----jGRASP exec: javac -g Animal.java Animal.java:116: error: class,

I keep getting these errors. Can someone please help me? Write javadoc style comments for the program.

----jGRASP exec: javac -g Animal.java

Animal.java:116: error: class, interface, or enum expected import java.util.Random; ^ Animal.java:117: error: class, interface, or enum expected import java.util.Scanner; ^ 2 errors

----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.

//Super Class Animal

public class Animal {

@Override public String toString() { return "Animal: "+this.getClass().getName(); } } //==============

//Fish Inherit Animal public class Fish extends Animal { @Override public String toString() { return super.toString(); } } //=====================

//Bear inherit Animal public class Bear extends Animal { @Override public String toString() { return super.toString(); } } //=====================

public class River { public static final int MAX_RIVER_SIZE = 10; //rivers of animal private Animal[] animals; //Constructor

public River() { //Set the river size this.animals = new Animal[MAX_RIVER_SIZE]; animals[0] = new Bear(); animals[5] = new Fish(); animals[2] = new Fish(); animals[7]= new Bear(); }

public void move(int moveIndex) { Random random = new Random(); int index = random.nextInt(MAX_RIVER_SIZE-1); if(animals[index] instanceof Fish && animals[moveIndex]instanceof Fish) {

System.out.println("Fish collides with Fish. Stay at same place.");

} else if(animals[index] instanceof Bear && animals[moveIndex] instanceof Bear) { System.out.println("Bear collides with Bear. Stay at same place.");

} else if(animals[index] instanceof Fish && animals[moveIndex] instanceof Bear) { System.out.println("Bear collides with Fish"); System.out.println(animals[index]+" dies."); //Bear Occupy Fish place animals[index]= animals[moveIndex]; //Bear Older place is null animals[moveIndex]= null; } else { if (animals[moveIndex] instanceof Fish) animals[moveIndex] = new Fish(); else if(animals[moveIndex] instanceof Bear) animals[moveIndex]= new Bear(); else animals[moveIndex]= new Fish(); } display(); } private void display() { for (int i = 0; i { System.out.println("Animal["+(i+1)+"] = "+animals[i]); } } } //===========================

import java.util.Random; import java.util.Scanner; public class Ecosystem { public static void main(String[] args) { Scanner input = new Scanner(System.in); Random random = new Random(); char choice; do { int moveAnimalIndex = random.nextInt(River.MAX_RIVER_SIZE-1); //Create River River river = new River(); river.move(moveAnimalIndex); System.out.print("Wanna Continue: (y/n): "); choice = input.next().toLowerCase().charAt(0); }while (choice =='y'); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions