Commit 3f0d8f21 authored by tahsif.ahmed's avatar tahsif.ahmed

Upload New File

parent 300579f8
import java.util.Scanner;
import java.util.ArrayList;
public class main {
public static void main(String[] args) throws Exception {
animal animal1 = new animal("Kong", "Gorilla", "Jungle", 120, 200, "Omivore");
animal animal3 = new animal("George", "Monkey", "Jungle", 50, 100, "Omivore");
animal animal4 = new animal("Leo", "Lion", "Savana", 200, 200, "Carnivore");
animal animal5 = new animal("Zebby", "Zebra", "Savana", 90, 140, "Herbivore");
reptile animal6 = new reptile("Liz", "Lizard", "Jungle", 1, 20, "Carnivore");
aquatic animal7 = new aquatic("Bob", "Dolphin", "Ocean", 80, 120, "Carnivore", true, "Salt Water");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter name of animal");
String userName = scanner.nextLine();
System.out.println("Enter species of animal");
String userSpecies = scanner.nextLine();
System.out.println("Enter which biome the animal lives in");
String userBiome = scanner.nextLine();
System.out.println("Enter weight of animal");
double userWeight = scanner.nextDouble();
System.out.println("Enter height of animal");
double userHeight = scanner.nextDouble();
System.out.println("What does the animal eat");
String userFood = scanner.nextLine();
animal animal2 = new animal(userName, userSpecies, userBiome, userWeight, userHeight, userFood);
ArrayList<animal> storeAnimal = new ArrayList<animal>();
storeAnimal.add(animal1);
storeAnimal.add(animal2);
storeAnimal.add(animal3);
storeAnimal.add(animal4);
storeAnimal.add(animal5);
storeAnimal.add(animal6);
storeAnimal.add(animal7);
for(int x=0; x<storeAnimal.size(); x++){
System.out.println(storeAnimal.get(x).name + " "+ storeAnimal.get(x).species + " " + storeAnimal.get(x).biome + " " + storeAnimal.get(x).weight + "KG " + storeAnimal.get(x).height + "CM " + storeAnimal.get(x).foodType + " ");
}
System.out.println("Enter speicies name of the animal(s): ");
String searchSpecies = scanner.nextLine();
for(int x=0; x<storeAnimal.size(); x++){
if(storeAnimal.get(x).species.equals(searchSpecies)){
System.out.println(storeAnimal.get(x).name);
}
else;
}
System.out.println("Enter the food type: ");
String searchFood = scanner.nextLine();
for(int x=0; x<storeAnimal.size(); x++){
if(storeAnimal.get(x).foodType.equals(searchFood)){
System.out.println(storeAnimal.get(x).name);
}
else;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment