Commit b6c5baf5 authored by antony.adewunmi-jones's avatar antony.adewunmi-jones

Done

parents
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
File added
File added
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
import java.lang.ProcessBuilder.Redirect.Type;
import java.util.Scanner;
public class Zoo {
String[][] animals = {{"Camel","Mammal", "Desert", "Grass"},{"Walrus","Mammal", "Arctic", "Crab"},{"Chimp","Mammal", "Jungle", "Fruit"},{"Deer","Mammal", "Forest", "Grass"},{"Road Runner","Bird", "Desert", "Insects"},{"Puffin","Bird", "Arctic", "Fish"},{"Tucan","Bird", "Jungle", "Fruit"},{"Wood Pecker","Bird", "Forest", "Insects"},{"Arctic Cod","Fish", "Arctic", "Plankton"},{"Angle Fish","Fish", "Jungle", "Algae"},{"Cobra","Reptile", "Desert", "Lizards"},{"Chameleon","Reptile", "Jungle", "Insects"},{"Viper","Reptile", "Forest", "Birds and Eggs"}};
private static void outAll(String[][] animals){
int arrayLength = animals.length;
System.out.println(arrayLength);
for (int i=0; i<arrayLength; i++){
System.out.println("A "+ animals[i][0]+ " is a "+animals[i][1]+" and lives in "+animals[i][2]+" and eats "+ animals[i][3]);
}
}
private static void outAnimal(String[][] animals){
Scanner read = new Scanner(System.in);
System.out.println("Input animal name ");
String choice = read.nextLine();
int arrayLength = animals.length;
System.out.println();
for (int i=0; i<arrayLength; i++){
if (choice.equals(animals[i][0])){
System.out.println("A "+ animals[i][0]+ " is a "+animals[i][1]+" and lives in "+animals[i][2]+" and eats "+ animals[i][3]);
break;
}
}
}
private static void outFood(String[][] animals){
int arrayLength = animals.length;
int arrayPlace = 0;
int a, b = 0;
String [][] Food = {{"",""},{"",""},{"",""},{"",""}};
System.out.println("Please input: ");
System.out.println("1: Display Food of all animals ");
System.out.println("2: Display for specific animals");
Scanner read = new Scanner(System.in);
String choice = read.nextLine();
switch (choice){
case "1":
//Display food of all animals
for (int i=0; i<arrayLength; i++){
System.out.println(animals[i][0]+" eats "+ animals[i][3]);
}
break;
case "2":
while (true){
System.out.println("Input animal name to add to list or press enter to output");
//loop here
choice = read.nextLine();
if (choice.isEmpty()){
System.out.println("array list created");
break;
}
else{
b = b+1;
for (int i=0; i<arrayLength; i++){
if (choice.equals(animals[i][0])){
Food[arrayPlace][0] = animals[i][0];
Food[arrayPlace][1] = animals[i][3];
break;
}
}
}
}
System.out.println("Animals in new Array: ");
}
}
private static void outHabitat(String[][] animals){
Scanner read = new Scanner(System.in);
System.out.println("Input habitat name ");
String choice = read.nextLine();
int arrayLength = animals.length;
System.out.println();
for (int i=0; i<arrayLength; i++){
if (choice.equals(animals[i][2])){
System.out.println("A "+ animals[i][0]+ " is a "+animals[i][1]+" and lives in "+animals[i][2]+" and eats "+ animals[i][3]);
}
}
}
private static void outType(String[][] animals){
String [][] Type = {{"","", "",""},{"","", "",""},{"","", "",""},{"","", "",""}};
Scanner read = new Scanner(System.in);
System.out.println("Input animal type");
String choice = read.nextLine();
int arrayLength = animals.length;
System.out.println();
int arrayPlace = 0;
for (int i=0; i<arrayLength; i++){
if (choice.equals(animals[i][1])){
Type[arrayPlace][0] = animals[i][0];
Type[arrayPlace][1] = animals[i][1];
Type[arrayPlace][2] = animals[i][2];
Type[arrayPlace][3] = animals[i][3];
System.out.println(animals[i][0]+" added to arrayList");
arrayPlace = arrayPlace+1;
}
}
System.out.println("Animals in new Array: ");
System.out.println(Type[0][0]);
System.out.println(Type[1][0]);
System.out.println(Type[2][0]);
System.out.println(Type[3][0]);
}
public static void main(String[] args) throws Exception {
//String species, type, habitat, diet, description;
//while loop for menu
//Display Individual Animal
//Display All Animals
//Display Food of animals
//Display animals from habitat
//Make Arraylist of all animals of a type
// Animals stored indiviually
// Stored as 'Species - Type - Habitat - Diet'
Scanner read = new Scanner(System.in);
String[][] animals = {{"Camel","Mammal", "Desert", "Grass"},{"Walrus","Mammal", "Arctic", "Crab"},{"Chimp","Mammal", "Jungle", "Fruit"},{"Deer","Mammal", "Forest", "Grass"},{"Road Runner","Bird", "Desert", "Insects"},{"Puffin","Bird", "Arctic", "Fish"},{"Tucan","Bird", "Jungle", "Fruit"},{"Wood Pecker","Bird", "Forest", "Insects"},{"Arctic Cod","Fish", "Arctic", "Plankton"},{"Angle Fish","Fish", "Jungle", "Algae"},{"Cobra","Reptile", "Desert", "Lizards"},{"Chameleon","Reptile", "Jungle", "Insects"},{"Viper","Reptile", "Forest", "Birds and Eggs"}};
//System.out.println(test[5][2]);
System.out.println("Please input: ");
System.out.println("1: Display details of Individual animal ");
System.out.println("2: Display all Animal's details");
System.out.println("3: List of animals of specified type ");
System.out.println("4: List of animals 'Food Required' ");
System.out.println("5: List of animals from specified environment ");
String choice = read.nextLine();
switch (choice){
case "1":
//Display details of Individual animal
outAll(animals);
break;
case "2":
//Display all Animal's details
outAnimal(animals);
break;
case "3":
outType(animals);
//List of animals of specified type
break;
case "4":
//List of animals 'Food Required'
outFood(animals);
break;
case "5":
//List of animals from specified environment
outHabitat(animals);
break;
}
}
}
animals
\ No newline at end of file
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