Commit bec6856b authored by a-j.towse's avatar a-j.towse

firstcommit

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).
import java.util.ArrayList;
public abstract class Animal {
public String name;
public String description;
protected String environment;
protected String foodType;
ArrayList<String> detailList= new ArrayList<>();
public Animal() {
this.name = "Name Unknown";
this.description = "Description Unknown";
this.environment = "Environment Unkown";
this.foodType = "Food Unknown";
}
public Animal(String name, String description, String environment, String foodType){
this.name = name;
this.description = description;
this.environment = environment;
this.foodType = foodType;
}
public ArrayList<String> getDetails(){
detailList.add("Name: "+this.name);
detailList.add("Description: "+this.description);
detailList.add("Environment "+this.environment);
detailList.add("Food Type: "+this.foodType);
return detailList;
}
public void addDetail(String detail1){
detailList.add(detail1);
}
public String getFoodType(){
return this.foodType;
}
}
public class App {
public static void main(String[] args) throws Exception {
Zoo myZoo = new Zoo();
DogTest Rex = new DogTest("Rex","red stripes","barn","dog food");
DogTest Pix = new DogTest("Pix","Gold","house","human food and dog food");
myZoo.addanimal(Rex);
myZoo.addanimal(Pix);
myZoo.displayAnimalArrayList();
myZoo.displayDetails(Rex);
myZoo.displayfoodRequirements(Rex);
myZoo.displayfoodRequirements(Pix);
}
}
public class DogTest extends Animal {
public DogTest() {
super();
}
public DogTest(String name, String description, String environment, String foodType) {
super(name, description, environment, foodType);
}
}
import java.util.ArrayList;
public class Zoo {
private ArrayList<Animal> animalArrayList= new ArrayList<>();
public ArrayList<Animal> getanimalArrayList(){
return this.animalArrayList;
}
public void displayAnimalArrayList(){
for (int i = 0; i < animalArrayList.size();i++){
System.out.println(animalArrayList.get(i).name);
}
}
public void addanimal(Animal animal){
animalArrayList.add(animal);
}
public void displayfoodRequirements(Animal animal){
System.out.println(animal.getFoodType());
}
public void displayDetails(Animal animal){
ArrayList<String> detailList=animal.getDetails();
for(int i = 0; i < detailList.size();i++){
System.out.println(detailList.get(i));
}
}
}
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