Using java, Represent the following using classes and interfaces: Dogs, Fish, and BoxTurtles are all Animals. All swim except BoxTurtles. Next, make a list containing all kinds of animals, fill it and print it; then make a list of only animals that can swim
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the answer.
Thank You !
===========================================================================
public class Animal {
private boolean canSwim;
private String animalType;
public Animal(String animalType) {
canSwim = false;
this.animalType = animalType;
}
public void setAnimalType(String animalType) {
this.animalType = animalType;
}
public String getAnimalType() {
return animalType;
}
public Animal(boolean canSwim) {
this.canSwim = canSwim;
}
public boolean isCanSwim() {
return canSwim;
}
public void setCanSwim(boolean canSwim) {
this.canSwim = canSwim;
}
@Override
public String toString() {
if (canSwim) {
return animalType + " can swim";
} else {
return animalType + " can swim";
}
}
}
=================================================================
public class Dog extends Animal {
private static String animalType = "Dog";
public Dog() {
super(animalType);
setCanSwim(true);
}
}
=================================================================
public class Fish extends Animal {
private static String animalType = "Fish";
public Fish() {
super(animalType);
setCanSwim(true);
}
}
=================================================================
public class BoxTurtles extends Animal {
private static String animalType = "Box Turtles";
public BoxTurtles() {
super(animalType);
setCanSwim(false);
}
}
=================================================================
import java.util.ArrayList;
public class MainAnimal {
public static void main(String[] args) {
// Next, make a list containing all kinds of animals,
ArrayList<Animal> animals = new ArrayList<>();
animals.add(new Dog());
animals.add(new Fish());
animals.add(new BoxTurtles());
// fill it and print it;
for (Animal animal : animals) {
System.out.println(animal);
}
//then make a list of only animals that can swim
ArrayList<Animal> swimmingAnimals = new ArrayList<>();
swimmingAnimals.add(new Dog());
swimmingAnimals.add(new Fish());
System.out.println("Animals that can swim only");
System.out.println("==========================");
// fill it and print it;
for (Animal animal : swimmingAnimals) {
System.out.println(animal);
}
}
}
=================================================================

Using java, Represent the following using classes and interfaces: Dogs, Fish, and BoxTurtles are all Animals....
Abstract Classes and Interfaces.
Write the code for all the necessary classes and/or interfaces for a solution to the problem below. Focus on class structure and interaction. You may implement your solution however you wish, but you will be graded on the appropriateness of your solution to the requirements. Note the use of capit and bold for clarification in the problem. You may use whatever constructors or additional methods you wish. - Define a structure that can represent Animals. -...
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
Abstract Classes and Interfaces Java This particular assignment is doing research and programming. I want you to do a research report of the following: Ways that abstract classes promotes software reusability, decreases time programming, and helps reduce the number of errors in software. Research the using abstract classes and interfaces. I would like for you to be creative and come up with your own example of abstract classes and interfaces in Java by writing your own abstract class and interface,...
Java — write code to represent the following classes in the
order asked.
Use comparable —>compateTo(), toString() and create a
constrcutor.
Follow the question outline please
62. 6S points) Writehfl Jaoe for a clss below that represents an aple where the following things Apples have a weight and a brand and cannot be created without these. are important to represent: Apples havs-natural ordering by weight, brand is not important). When an apple is printed, it should display all the properties...
Answer using Java
Part I: Feeding the Animals (3 points) Filename(s): PetShelter.java Alicia is responsible for buying a week's supply of food and medication for the dogs and cats at a local animal shelter. The food and medication for each dog costs twice as much as those for a cat. Each week the number of cats and dogs changes, as well as how much money she has available to spend on the animals. Write a program that asks the user...
In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...
In Java, write classes the following different types of questions: YesNo: this can be answered in one of two ways: yes or no. answer(String) would accept only "Yes" or "No" as valid answers. Essay: this can be answered in at most 140 characters, including spaces. Likert: this can be answered on a fixed, 5-point Likert scale (Strongly Agree, Agree, Neither Agree nor Disagree, Disagree, Strongly Disagree). answer(String) would accept only these precise words as valid answers. Design the data in...
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...
Using Java coding, complete the following: This program should implement a LinkedList data structure to handle the management of student records. It will need to be able to store any number of students, using a Linked List. LinearNode.java can be used to aid creating this program Student should be a class defined with the following: • String name • int year • A linked list of college classes (college classes are represented using strings) • An...
Please use Java only: Background: Java contains several different types of interfaces used to organize collections of items. You may already be familiar with the List interface, which is implemented by classes such as the ArrayList. A List represents a collection of elements from which elements can be stored or retreived, in which elements are ordered and can be retrieved by index. A List extends from a Collection, which represents a collection of elements but which may or may not...