-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bd15c0
commit a3badc6
Showing
5 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
public class App { | ||
//Each Exercise can run individualy, but I intend to create a main code where all the exercises with explanations can be outputted. | ||
public static void main(String[] args) { | ||
System.out.println(" Lets run the codes! "); | ||
System.out.println(" I'm still working on the codes. But for now, you can run each one individualy"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package Objects; | ||
|
||
public class Cat extends Animal { | ||
@Override | ||
public void speak(){ | ||
System.out.println("Cat goes MEOW MEOW MEOW MEOOOOOOOOOOOOOW"); | ||
} | ||
@Override | ||
public void animalSpeak(){ | ||
System.out.println("*meow*"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package files; | ||
|
||
import java.util.Scanner; | ||
|
||
import Objects.Animal; | ||
import Objects.Cat; | ||
import Objects.Dog; | ||
|
||
public class DynamicPolymorphism { | ||
public static void main(String[] args) { | ||
run(); | ||
} | ||
public static void run() { | ||
Scanner scanner = new Scanner(System.in); | ||
Animal animal; | ||
|
||
System.out.println("What animal do you want?"); | ||
System.out.print("(1=dog) or (2=cat): "); | ||
int choice = scanner.nextInt(); | ||
|
||
if(choice==1) { | ||
animal = new Dog(); | ||
animal.speak(); | ||
} | ||
else if(choice==2) { | ||
animal = new Cat(); | ||
animal.speak(); | ||
} | ||
else { | ||
animal = new Animal(); | ||
System.out.println("That choice was invalid"); | ||
animal.speak(); | ||
} | ||
scanner.close(); | ||
} | ||
} |