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,53 @@
|
||||
import javax.management.RuntimeErrorException;
|
||||
|
||||
public class Animal
|
||||
{
|
||||
//TODO: private member variables
|
||||
private String _soundMade;
|
||||
private boolean _hasLegs;
|
||||
private boolean _hasWings;
|
||||
private boolean _hasGills;
|
||||
|
||||
public Animal( String soundMade, boolean hasLegs, boolean hasWings, boolean hasGills )
|
||||
{
|
||||
_soundMade = soundMade;
|
||||
_hasLegs = hasLegs;
|
||||
_hasWings = hasWings;
|
||||
_hasGills = hasGills;
|
||||
}
|
||||
|
||||
public String getSoundMade()
|
||||
{
|
||||
return _soundMade;
|
||||
}
|
||||
|
||||
public boolean hasLegs()
|
||||
{
|
||||
return _hasLegs;
|
||||
}
|
||||
|
||||
public boolean hasWings()
|
||||
{
|
||||
return _hasWings;
|
||||
}
|
||||
|
||||
public boolean hasGills()
|
||||
{
|
||||
return _hasGills;
|
||||
}
|
||||
|
||||
public int numberOfLegs()
|
||||
{
|
||||
throw new RuntimeException("Unknown # of Legs");
|
||||
}
|
||||
|
||||
public int numberOfWings()
|
||||
{
|
||||
throw new RuntimeException("Unknown # of Wings");
|
||||
}
|
||||
|
||||
public void breatheUnderwater()
|
||||
{
|
||||
throw new RuntimeException("Unknown if animal can breathe underwater.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public class Bird extends Animal {
|
||||
public Bird() {
|
||||
super("tweet", true, true, false);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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,19 @@
|
||||
public class Fish extends Animal{
|
||||
public Fish() {
|
||||
super("blub", false, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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,186 @@
|
||||
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 () ;
|
||||
|
||||
//Dog
|
||||
if( d.hasLegs() )
|
||||
{
|
||||
System.out.println( "Dogs have " + d.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( d.hasWings() )
|
||||
{
|
||||
System.out.println( "Dogs have " + d.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( d.hasGills() )
|
||||
{
|
||||
d.breatheUnderwater() ;
|
||||
System.out.println( "Dogs can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Cat
|
||||
if( c.hasLegs() )
|
||||
{
|
||||
System.out.println( "Cats have " + c.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( d.hasWings() )
|
||||
{
|
||||
System.out.println( "Cats have " + c.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( c.hasGills() )
|
||||
{
|
||||
c.breatheUnderwater() ;
|
||||
System.out.println( "Cats can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Bird
|
||||
if( b.hasLegs() )
|
||||
{
|
||||
System.out.println( "Birds have " + b.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( b.hasWings() )
|
||||
{
|
||||
System.out.println( "Birds have " + b.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( b.hasGills() )
|
||||
{
|
||||
b.breatheUnderwater() ;
|
||||
System.out.println( "Birds can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Fish
|
||||
if( f.hasLegs() )
|
||||
{
|
||||
System.out.println( "Fish have " + f.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( f.hasWings() )
|
||||
{
|
||||
System.out.println( "Fish have " + f.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( f.hasGills() )
|
||||
{
|
||||
f.breatheUnderwater() ;
|
||||
System.out.println( "Fish can breathe under water." ) ;
|
||||
}
|
||||
|
||||
//Fox
|
||||
if( x.hasLegs() )
|
||||
{
|
||||
System.out.println( "Foxes have " + x.numberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
if( x.hasWings() )
|
||||
{
|
||||
System.out.println( "Foxes have " + x.numberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
if( x.hasGills() )
|
||||
{
|
||||
x.breatheUnderwater() ;
|
||||
System.out.println( "Foxes can breathe under water." ) ;
|
||||
}
|
||||
|
||||
System.out.println() ;
|
||||
System.out.println( "Attempting things we shouldn't..." ) ;
|
||||
try
|
||||
{
|
||||
d.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
d.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
c.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
c.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
b.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
f.numberOfLegs() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
f.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.numberOfWings() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
x.breatheUnderwater() ;
|
||||
}
|
||||
catch( RuntimeException e )
|
||||
{
|
||||
System.out.println( e.getMessage() ) ;
|
||||
}
|
||||
|
||||
System.out.println() ;
|
||||
System.out.println( "Dog goes " + d.getSoundMade() ) ;
|
||||
System.out.println( "Cat goes " + c.getSoundMade() ) ;
|
||||
System.out.println( "Bird goes " + b.getSoundMade() ) ;
|
||||
System.out.println( "Fish goes " + f.getSoundMade() ) ;
|
||||
System.out.println( "What does the fox say? " + x.getSoundMade() ) ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user