AHHHHHHHHHH COMMITED TO GITHUB INSTEAD OF FORGEJO FOR WEEKS
This commit is contained in:
		
							parent
							
								
									d6ef44f3d1
								
							
						
					
					
						commit
						0919005cb2
					
				
					 163 changed files with 3875 additions and 47 deletions
				
			
		
							
								
								
									
										21
									
								
								Code/Steiner/dynamicCasting/src/App.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								Code/Steiner/dynamicCasting/src/App.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| 
 | ||||
| public class App { | ||||
|     public static void main(String[] args) throws Exception { | ||||
|         ArrayList<Article> list = new ArrayList<Article>(); | ||||
|         list.add(new Book("11241", 12, "Tolkien", "The Book to rule all books")); | ||||
|         list.add(new Camera("0101012", 25000, "Fujifilm")); | ||||
|         list.add(new CD("0345678", 56789, "hello", | ||||
|                 new ArrayList<String>(Arrays.asList("Hello", "World", "THIS IS THE END")))); | ||||
|         list.add(new MP3("RASPUTIN", 456789, "Rasputin", "lengh")); | ||||
| 
 | ||||
|         for (Article article : list) { | ||||
|             article.print(); | ||||
|             if (article instanceof CD) { | ||||
|                 ((CD) article).playTrack(); | ||||
|             } | ||||
|             System.out.println(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										16
									
								
								Code/Steiner/dynamicCasting/src/Article.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Code/Steiner/dynamicCasting/src/Article.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| public abstract class Article { | ||||
|     String code; | ||||
|     double price; | ||||
| 
 | ||||
|     public Article(String code, double price) { | ||||
|         this.code = code; | ||||
|         this.price = price; | ||||
|     } | ||||
| 
 | ||||
|     boolean available() { | ||||
|         boolean maybe = true; | ||||
|         return maybe; | ||||
|     } | ||||
| 
 | ||||
|     abstract void print(); | ||||
| } | ||||
							
								
								
									
										11
									
								
								Code/Steiner/dynamicCasting/src/Audio.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Code/Steiner/dynamicCasting/src/Audio.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | |||
| public abstract class Audio extends Article { | ||||
|     String title; | ||||
| 
 | ||||
|     public Audio(String code, double price, String title) { | ||||
|         super(code, price); | ||||
|         this.title = title; | ||||
|     } | ||||
| 
 | ||||
|     abstract void print(); | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										16
									
								
								Code/Steiner/dynamicCasting/src/Book.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Code/Steiner/dynamicCasting/src/Book.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| public class Book extends Article { | ||||
|     String author; | ||||
|     String title; | ||||
| 
 | ||||
|     public Book(String code, double price, String author, String title) { | ||||
|         super(code, price); | ||||
|         this.author = author; | ||||
|         this.title = title; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     void print() { | ||||
|         System.out.println(this.author + " - " + this.title); | ||||
|         System.out.println("Code: " + super.code + "\nPrice: " + super.price); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										27
									
								
								Code/Steiner/dynamicCasting/src/CD.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Code/Steiner/dynamicCasting/src/CD.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| import java.util.ArrayList; | ||||
| 
 | ||||
| public class CD extends Audio { | ||||
|     ArrayList<String> tracks = new ArrayList<>(); | ||||
| 
 | ||||
|     public CD(String code, double price, String title, ArrayList<String> tracks) { | ||||
|         super(code, price, title); | ||||
|         this.tracks = tracks; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     void print() { | ||||
|         System.out.println("Title: " + title); | ||||
|         System.out.println("Code: " + super.code + "\nPrice: " + super.price); | ||||
|         for (String string : tracks) { | ||||
|             System.out.println(string); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void playTrack() { | ||||
|         int i = 1; | ||||
|         for (String string : tracks) { | ||||
|             System.out.println("Play track " + i + " " + string + " der CD " + title); | ||||
|             i++; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										14
									
								
								Code/Steiner/dynamicCasting/src/Camera.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Code/Steiner/dynamicCasting/src/Camera.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| public class Camera extends Article { | ||||
|     String brand; | ||||
| 
 | ||||
|     public Camera(String code, double price, String brand) { | ||||
|         super(code, price); | ||||
|         this.brand = brand; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     void print() { | ||||
|         System.out.println("Brand: " + this.brand); | ||||
|         System.out.println("Code: " + super.code + "\nPrice: " + super.price); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										15
									
								
								Code/Steiner/dynamicCasting/src/MP3.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								Code/Steiner/dynamicCasting/src/MP3.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| public class MP3 extends Audio { | ||||
|     String lengh; | ||||
| 
 | ||||
|     public MP3(String code, double price, String title, String lengh) { | ||||
|         super(code, price, title); | ||||
|         this.lengh = lengh; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     void print() { | ||||
|         System.out.println("Title: " + title); | ||||
|         System.out.println("Code: " + super.code + "\nPrice: " + super.price); | ||||
|         System.out.println("Lengh: " + lengh + " (this was not my typo i was forced to do this)"); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue