added old projects
This commit is contained in:
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
## 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).
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,67 @@
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
public abstract class Animal
|
||||
{
|
||||
//TODO: private member variables
|
||||
private String _soundMade;
|
||||
private String _type;
|
||||
private boolean _hasLegs;
|
||||
private boolean _hasWings;
|
||||
private boolean _hasGills;
|
||||
|
||||
public Animal( String soundMade, boolean hasLegs, boolean hasWings, boolean hasGills, String type)
|
||||
{
|
||||
_soundMade = soundMade;
|
||||
_hasLegs = hasLegs;
|
||||
_hasWings = hasWings;
|
||||
_hasGills = hasGills;
|
||||
_type = type;
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
public String getSoundMade()
|
||||
{
|
||||
return _soundMade;
|
||||
}
|
||||
|
||||
public boolean hasLegs()
|
||||
{
|
||||
return _hasLegs;
|
||||
}
|
||||
|
||||
public boolean hasWings()
|
||||
{
|
||||
return _hasWings;
|
||||
}
|
||||
|
||||
public boolean hasGills()
|
||||
{
|
||||
return _hasGills;
|
||||
}
|
||||
public abstract int numberOfLegs();
|
||||
public abstract int numberOfWings();
|
||||
public abstract void breatheUnderwater();
|
||||
|
||||
public void PrintDetails(Animal a) {
|
||||
String type = getType();
|
||||
try {
|
||||
int legs = numberOfLegs();
|
||||
System.out.println("A " + type + " has " + legs + " legs");
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
int wings = numberOfWings();
|
||||
System.out.println("A " + type + " has " + wings + " wings");
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
breatheUnderwater();
|
||||
} catch(RuntimeException e) {}
|
||||
try {
|
||||
String sound = getSoundMade();
|
||||
System.out.println("A " + type + " makes the sound " + sound);
|
||||
} catch (RuntimeException e) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Bird extends Animal {
|
||||
public Bird() {
|
||||
super("tweet", true, true, false, "Bird");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Birds can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Cat extends Animal {
|
||||
public Cat() {
|
||||
super("meow", true, false, false, "Cat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Cats can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Cats don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Dog extends Animal {
|
||||
|
||||
public Dog() {
|
||||
super("woof", true, false, false, "Dog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Dogs can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Dogs don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Fish extends Animal{
|
||||
public Fish() {
|
||||
super("blub", false, false, true, "Fish");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
System.out.println("A fish can breathe under water");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
throw new RuntimeException("Fish don't have legs!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Fish don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Fox extends Animal {
|
||||
public Fox() {
|
||||
super("Ring-ding-ding-dingeringeding", true, false, false, "Fox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
throw new RuntimeException( "Foxes can't breathe under water!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfLegs() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int numberOfWings() {
|
||||
throw new RuntimeException("Foxes don't have wings!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Tester
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Dog d = new Dog () ;
|
||||
Cat c = new Cat () ;
|
||||
Bird b = new Bird() ;
|
||||
Fish f = new Fish() ;
|
||||
Fox x = new Fox () ;
|
||||
|
||||
ArrayList<Animal> animals = new ArrayList<>();
|
||||
animals.add(d);
|
||||
animals.add(c);
|
||||
animals.add(b);
|
||||
animals.add(f);
|
||||
animals.add(x);
|
||||
|
||||
for (Animal a:animals) {
|
||||
a.PrintDetails(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user