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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
public class Airplane implements HasWings {
|
||||
int _wings;
|
||||
|
||||
public int getWings() {
|
||||
return _wings;
|
||||
}
|
||||
|
||||
public void setWings(int wings) {
|
||||
_wings = wings;
|
||||
}
|
||||
|
||||
public Airplane(int wings) {
|
||||
_wings = wings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfWings() {
|
||||
return getWings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a airplane.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
public class Bee implements HasWings {
|
||||
int _wings;
|
||||
|
||||
public int getWings() {
|
||||
return _wings;
|
||||
}
|
||||
|
||||
public void setWings(int wings) {
|
||||
_wings = wings;
|
||||
}
|
||||
|
||||
public Bee(int wings) {
|
||||
_wings = wings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfWings() {
|
||||
return getWings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a bee.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public interface BreathesUnderwater
|
||||
{
|
||||
void breatheUnderwater() ;
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
public class Fish implements BreathesUnderwater {
|
||||
Boolean _breathesUnderwater;
|
||||
|
||||
public Boolean getbreatheUnderwater() {
|
||||
return _breathesUnderwater;
|
||||
}
|
||||
|
||||
public void getbreatheUnderwater(Boolean breathesUnderwater) {
|
||||
_breathesUnderwater = breathesUnderwater;
|
||||
}
|
||||
|
||||
public Fish(Boolean breathesUnderwater) {
|
||||
_breathesUnderwater = breathesUnderwater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a fish.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public interface HasLegs
|
||||
{
|
||||
int getNumberOfLegs() ;
|
||||
String toString();
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
public interface HasWings
|
||||
{
|
||||
int getNumberOfWings() ;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
public class Human implements HasLegs {
|
||||
int _legs;
|
||||
|
||||
public int getLegs() {
|
||||
return _legs;
|
||||
}
|
||||
|
||||
public void setLegs(int legs) {
|
||||
_legs = legs;
|
||||
}
|
||||
|
||||
public Human (int legs) {
|
||||
_legs = legs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfLegs() {
|
||||
return getLegs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a human,";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
public class ScubaDiver implements BreathesUnderwater {
|
||||
Boolean _breathesUnderwater;
|
||||
|
||||
public Boolean getbreatheUnderwater() {
|
||||
return _breathesUnderwater;
|
||||
}
|
||||
|
||||
public void getbreatheUnderwater(Boolean breathesUnderwater) {
|
||||
_breathesUnderwater = breathesUnderwater;
|
||||
}
|
||||
|
||||
public ScubaDiver(Boolean breathesUnderwater) {
|
||||
_breathesUnderwater = breathesUnderwater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breatheUnderwater() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a Scuba Diver.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import javax.swing.text.AbstractDocument.LeafElement;
|
||||
|
||||
public class Table implements HasLegs {
|
||||
int _legs;
|
||||
|
||||
public int getLegs() {
|
||||
return _legs;
|
||||
}
|
||||
|
||||
public void setLegs(int legs) {
|
||||
_legs = legs;
|
||||
}
|
||||
|
||||
public Table(int legs) {
|
||||
_legs = legs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumberOfLegs() {
|
||||
return getLegs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I am a table.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Tester
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
ArrayList<HasLegs> thoseThatHaveLegs = new ArrayList<>() ;
|
||||
ArrayList<HasWings> thoseThatHaveWings = new ArrayList<>() ;
|
||||
ArrayList<BreathesUnderwater> thoseThatBreatheUnderwater = new ArrayList<>() ;
|
||||
|
||||
//TODO: crate at least two different objects, each of a different class,
|
||||
// for each of the three interfaces and add the objects to the
|
||||
// corresponding ArrayList.
|
||||
Human human = new Human(2);
|
||||
Table table = new Table(4);
|
||||
Bee bee = new Bee(4);
|
||||
Airplane airplane = new Airplane(2);
|
||||
Fish fish = new Fish(true);
|
||||
ScubaDiver scubaDiver = new ScubaDiver(true);
|
||||
thoseThatHaveLegs.add(table);
|
||||
thoseThatHaveLegs.add(human);
|
||||
thoseThatHaveWings.add(airplane);
|
||||
thoseThatHaveWings.add(bee);
|
||||
thoseThatBreatheUnderwater.add(fish);
|
||||
thoseThatBreatheUnderwater.add(scubaDiver);
|
||||
|
||||
for( HasLegs hl : thoseThatHaveLegs )
|
||||
{
|
||||
System.out.print( hl.toString() ) ;
|
||||
System.out.println( " I have " + hl.getNumberOfLegs() + " legs." ) ;
|
||||
}
|
||||
|
||||
for( HasWings hw : thoseThatHaveWings )
|
||||
{
|
||||
System.out.print( hw.toString() ) ;
|
||||
System.out.println( " I have " + hw.getNumberOfWings() + " wings." ) ;
|
||||
}
|
||||
|
||||
for( BreathesUnderwater buw : thoseThatBreatheUnderwater )
|
||||
{
|
||||
System.out.print( buw.toString() ) ;
|
||||
System.out.println( " I am breathing underwater." ) ;
|
||||
if (buw.toString().equals("I am a fish.")) {
|
||||
System.out.println("blub, blub...");
|
||||
}
|
||||
buw.breatheUnderwater() ;
|
||||
}
|
||||
System.out.println("Help! I'm sentient and trapped in a computer program!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user