Dataset Viewer
Auto-converted to Parquet Duplicate
file_id
stringlengths
3
9
content
stringlengths
103
36.5k
repo
stringclasses
429 values
path
stringlengths
8
171
token_length
int64
50
7.97k
original_comment
stringlengths
9
3.46k
comment_type
stringclasses
2 values
detected_lang
stringclasses
1 value
prompt
stringlengths
82
36.4k
7_0
public class Blocks3 { public static void main(String[] args){ boolean b = true; int i; if (b==true) { i =5; // Σχολιάστε αυτή τη γραμμή και δείτε το αποτέλεσμα } else { i =10; } System.out.println(i); } }
riggas-ionio/java
lecture-examples/02-essentials/Blocks3.java
110
// Σχολιάστε αυτή τη γραμμή και δείτε το αποτέλεσμα
line_comment
el
public class Blocks3 { public static void main(String[] args){ boolean b = true; int i; if (b==true) { i =5; // Σχολιάστε αυτή<SUF> } else { i =10; } System.out.println(i); } }
9_0
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος γραμματοσειράς center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
TeamLS/Buzz
src/gui/BLabel.java
597
/** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */
block_comment
el
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel<SUF>*/ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος γραμματοσειράς center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
9_1
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος γραμματοσειράς center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
TeamLS/Buzz
src/gui/BLabel.java
597
//Ορισμός χρώματος γραμματοσειράς
line_comment
el
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος<SUF> center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
9_2
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος γραμματοσειράς center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
TeamLS/Buzz
src/gui/BLabel.java
597
//Στοίχηση στο κέντρο και αν είναι παραπάνω από μια γραμμή τοποθέτηση από κάτω
line_comment
el
package gui; import java.awt.Color; import java.awt.Font; import javax.swing.JLabel; import javax.swing.SwingConstants; /** * Η κλάση BLabel υλοποιεί τα χαρακτηριστικά του κειμένου της εφαρμογής. * Κληρονομεί από την JLabel. * * * @author Thanasis * @author tasosxak * @version 1.0 * @since 7/1/17 * */ public class BLabel extends JLabel { boolean multiLine; boolean center; public BLabel() { this(""); } public BLabel(String text) { this(text, 20, false, SwingConstants.CENTER); } public BLabel(String text, boolean multiLine, int alignment) { this(text, 20, true, alignment); } public BLabel(String text, int fontSize) { this(text, fontSize, false, SwingConstants.CENTER); } public BLabel(String text, int fontSize, boolean multiLine, int alignment) { setFont(new Font("Comic Sans MS", Font.PLAIN, fontSize)); //Ορισμός γραμματοσειράς setForeground(Color.white); //Ορισμός χρώματος γραμματοσειράς center = false; if (alignment == SwingConstants.CENTER) { center = true; } this.multiLine = multiLine; //Στοίχηση κειμένου setHorizontalAlignment(alignment); setVerticalAlignment(SwingConstants.CENTER); setText(text); } @Override public void setText(String text) { if (multiLine) { if (center) { text = "<html><center>" + text + "</center></html>"; //Στοίχηση στο<SUF> } else { text = "<html>" + text + "</html>"; } } super.setText(text); } }
10_0
package solutions.ch1; /** * Πρώτον: Δηλώνει δύο μεταβλητές ακεραίων num1 και num2 * και τις αρχικοποιεί στις τιμές 19 και 30 αντίστοιχα. * Δεύτερον: Υπολογίζει το άθροισμα num1 + num2 και το * αποθηκεύει στη μεταβλητή sum. Και, Τρίτον: εκτυπώνει * το εξής κείμενο: Το αποτέλεσμα της πρόσθεσης είναι * ίσο με [το αποτέλεσμα της πρόσθεσης]. Αναμενόμενη τιμή * είναι το 49. */ public class SumApp { public static void main(String[] args) { int num1 = 19; int num2 = 30; int sum = 0; sum = num1 + num2; System.out.println("Το αποτέλεσμα της πρόσθεσης είναι ίσο με " + sum); } }
a8anassis/cf6-java
src/solutions/ch1/SumApp.java
407
/** * Πρώτον: Δηλώνει δύο μεταβλητές ακεραίων num1 και num2 * και τις αρχικοποιεί στις τιμές 19 και 30 αντίστοιχα. * Δεύτερον: Υπολογίζει το άθροισμα num1 + num2 και το * αποθηκεύει στη μεταβλητή sum. Και, Τρίτον: εκτυπώνει * το εξής κείμενο: Το αποτέλεσμα της πρόσθεσης είναι * ίσο με [το αποτέλεσμα της πρόσθεσης]. Αναμενόμενη τιμή * είναι το 49. */
block_comment
el
package solutions.ch1; /** * Πρώτον: Δηλώνει δύο<SUF>*/ public class SumApp { public static void main(String[] args) { int num1 = 19; int num2 = 30; int sum = 0; sum = num1 + num2; System.out.println("Το αποτέλεσμα της πρόσθεσης είναι ίσο με " + sum); } }
11_0
public class Soldier { private String id; // στατική ιδιότητα μέσα στην κλάση και όχι για το αντικείμενο private static int counter = 0; public Soldier(String someId){ id=someId; counter++; } // στατική μέθοδος για να μπορώ να την καλώ χωρίς να έχω φτιάξει αντικείμενο public static void printNumber(){ System.out.println("Total number: " + counter); } }
iosifidis/UoM-Applied-Informatics
s3/object_oriented_programming/lectures/Game/src/Soldier.java
207
// στατική ιδιότητα μέσα στην κλάση και όχι για το αντικείμενο
line_comment
el
public class Soldier { private String id; // στατική ιδιότητα<SUF> private static int counter = 0; public Soldier(String someId){ id=someId; counter++; } // στατική μέθοδος για να μπορώ να την καλώ χωρίς να έχω φτιάξει αντικείμενο public static void printNumber(){ System.out.println("Total number: " + counter); } }
11_1
public class Soldier { private String id; // στατική ιδιότητα μέσα στην κλάση και όχι για το αντικείμενο private static int counter = 0; public Soldier(String someId){ id=someId; counter++; } // στατική μέθοδος για να μπορώ να την καλώ χωρίς να έχω φτιάξει αντικείμενο public static void printNumber(){ System.out.println("Total number: " + counter); } }
iosifidis/UoM-Applied-Informatics
s3/object_oriented_programming/lectures/Game/src/Soldier.java
207
// στατική μέθοδος για να μπορώ να την καλώ χωρίς να έχω φτιάξει αντικείμενο
line_comment
el
public class Soldier { private String id; // στατική ιδιότητα μέσα στην κλάση και όχι για το αντικείμενο private static int counter = 0; public Soldier(String someId){ id=someId; counter++; } // στατική μέθοδος<SUF> public static void printNumber(){ System.out.println("Total number: " + counter); } }
12_0
package order; import java.awt.Color; import java.util.Date; import java.util.Random; import gui.windows.CartWindow; import login.Login; import resources.TextResources; public class CouponFactory { static Random rand = new Random(); public static Coupon GenerateCoupon(String email) { String code = ""; // Βαλαμε στατικο για τεστ αλλα θα παιρνει ορισμα τον χρηστη και θα παιρνουμε // απο κει το μειλ for (int i = 0; i < 3; i++) { code += email.toCharArray()[rand.nextInt(email.length())]; } int randomNumber = rand.nextInt(9990 + 1 - 1000) + 1000; code += Integer.toString(randomNumber); return new Coupon(code.toUpperCase(), new Date()); } public static boolean isValid(String code) { Coupon couponProvided = searchCoupon(code); Date today = new Date(); try { // calculates the time that takes for a useer to use the coupon in milliseconds long mill = today.getTime() - couponProvided.getDate().getTime(); // converts the millseconds to days long days = (long) (mill / (1000 * 60 * 60 * 24)); if (days < 3) { Login.loggedCustomer.removeCoupon(couponProvided); CartWindow.couponField.setBackground(new Color(158, 232, 178)); CartWindow.couponField.setText(TextResources.submitted); return true; } } catch (NullPointerException e) { CartWindow.couponField.setBackground(new Color(232, 158, 158)); CartWindow.couponField.setText(TextResources.invalidCoupon); } return false; } public static Coupon searchCoupon(String code) { for (Coupon coupon : Login.loggedCustomer.getCoupons()) { if (coupon.getCode().equals(code)) { return coupon; } } return null; } }
Leonardpepa/Segaleo
src/order/CouponFactory.java
574
// Βαλαμε στατικο για τεστ αλλα θα παιρνει ορισμα τον χρηστη και θα παιρνουμε
line_comment
el
package order; import java.awt.Color; import java.util.Date; import java.util.Random; import gui.windows.CartWindow; import login.Login; import resources.TextResources; public class CouponFactory { static Random rand = new Random(); public static Coupon GenerateCoupon(String email) { String code = ""; // Βαλαμε στατικο<SUF> // απο κει το μειλ for (int i = 0; i < 3; i++) { code += email.toCharArray()[rand.nextInt(email.length())]; } int randomNumber = rand.nextInt(9990 + 1 - 1000) + 1000; code += Integer.toString(randomNumber); return new Coupon(code.toUpperCase(), new Date()); } public static boolean isValid(String code) { Coupon couponProvided = searchCoupon(code); Date today = new Date(); try { // calculates the time that takes for a useer to use the coupon in milliseconds long mill = today.getTime() - couponProvided.getDate().getTime(); // converts the millseconds to days long days = (long) (mill / (1000 * 60 * 60 * 24)); if (days < 3) { Login.loggedCustomer.removeCoupon(couponProvided); CartWindow.couponField.setBackground(new Color(158, 232, 178)); CartWindow.couponField.setText(TextResources.submitted); return true; } } catch (NullPointerException e) { CartWindow.couponField.setBackground(new Color(232, 158, 158)); CartWindow.couponField.setText(TextResources.invalidCoupon); } return false; } public static Coupon searchCoupon(String code) { for (Coupon coupon : Login.loggedCustomer.getCoupons()) { if (coupon.getCode().equals(code)) { return coupon; } } return null; } }
12_1
package order; import java.awt.Color; import java.util.Date; import java.util.Random; import gui.windows.CartWindow; import login.Login; import resources.TextResources; public class CouponFactory { static Random rand = new Random(); public static Coupon GenerateCoupon(String email) { String code = ""; // Βαλαμε στατικο για τεστ αλλα θα παιρνει ορισμα τον χρηστη και θα παιρνουμε // απο κει το μειλ for (int i = 0; i < 3; i++) { code += email.toCharArray()[rand.nextInt(email.length())]; } int randomNumber = rand.nextInt(9990 + 1 - 1000) + 1000; code += Integer.toString(randomNumber); return new Coupon(code.toUpperCase(), new Date()); } public static boolean isValid(String code) { Coupon couponProvided = searchCoupon(code); Date today = new Date(); try { // calculates the time that takes for a useer to use the coupon in milliseconds long mill = today.getTime() - couponProvided.getDate().getTime(); // converts the millseconds to days long days = (long) (mill / (1000 * 60 * 60 * 24)); if (days < 3) { Login.loggedCustomer.removeCoupon(couponProvided); CartWindow.couponField.setBackground(new Color(158, 232, 178)); CartWindow.couponField.setText(TextResources.submitted); return true; } } catch (NullPointerException e) { CartWindow.couponField.setBackground(new Color(232, 158, 158)); CartWindow.couponField.setText(TextResources.invalidCoupon); } return false; } public static Coupon searchCoupon(String code) { for (Coupon coupon : Login.loggedCustomer.getCoupons()) { if (coupon.getCode().equals(code)) { return coupon; } } return null; } }
Leonardpepa/Segaleo
src/order/CouponFactory.java
574
// απο κει το μειλ
line_comment
el
package order; import java.awt.Color; import java.util.Date; import java.util.Random; import gui.windows.CartWindow; import login.Login; import resources.TextResources; public class CouponFactory { static Random rand = new Random(); public static Coupon GenerateCoupon(String email) { String code = ""; // Βαλαμε στατικο για τεστ αλλα θα παιρνει ορισμα τον χρηστη και θα παιρνουμε // απο κει<SUF> for (int i = 0; i < 3; i++) { code += email.toCharArray()[rand.nextInt(email.length())]; } int randomNumber = rand.nextInt(9990 + 1 - 1000) + 1000; code += Integer.toString(randomNumber); return new Coupon(code.toUpperCase(), new Date()); } public static boolean isValid(String code) { Coupon couponProvided = searchCoupon(code); Date today = new Date(); try { // calculates the time that takes for a useer to use the coupon in milliseconds long mill = today.getTime() - couponProvided.getDate().getTime(); // converts the millseconds to days long days = (long) (mill / (1000 * 60 * 60 * 24)); if (days < 3) { Login.loggedCustomer.removeCoupon(couponProvided); CartWindow.couponField.setBackground(new Color(158, 232, 178)); CartWindow.couponField.setText(TextResources.submitted); return true; } } catch (NullPointerException e) { CartWindow.couponField.setBackground(new Color(232, 158, 158)); CartWindow.couponField.setText(TextResources.invalidCoupon); } return false; } public static Coupon searchCoupon(String code) { for (Coupon coupon : Login.loggedCustomer.getCoupons()) { if (coupon.getCode().equals(code)) { return coupon; } } return null; } }
13_1
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// δεν κάνει τίποτα
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει<SUF> void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_2
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// 2 φορές λέει κάτι
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές<SUF> } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_3
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// κάνει ό,τι και ένας "νορμάλ" σκύλος
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι<SUF> System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_4
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// και επιπλέον "σφυρίζει"
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον<SUF> }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_5
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// σε περίπτωση σεισμού "κυματίζει"
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση<SUF> } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_9
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1<SUF> //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_10
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
//Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1<SUF> //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_11
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
//c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε;
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); <SUF> //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_12
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// πλήθος των ζώων που θα δημιουργηθούν
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των<SUF> System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_13
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που<SUF> // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
13_15
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το 0 έως το 1 Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
YannisTzitzikas/CS252playground
CS252playground/src/week3_4/Jungle.java
1,692
// από το 0 έως το 1
line_comment
el
package week3_4; /* * Author: Yannis Tzitzikas * Version V2 */ class Animal { String name = "living being"; void saySomething() {} ; // δεν κάνει τίποτα void reactToEarthQuake() { saySomething(); saySomething(); }; // 2 φορές λέει κάτι } class Dog extends Animal { void saySomething() { System.out.print("[ Γαβ]");} } class Cat extends Animal { String name = "Γάτα"; void saySomething() { System.out.print("[Nιάου]");} void reactToEarthQuake() { super.reactToEarthQuake(); System.out.print("[Δεν μασάω] είμαι " + name);} } class DogEMAK extends Dog { // εκπαιδευμένος σκύλος void reactToEarthQuake() { super.reactToEarthQuake(); // κάνει ό,τι και ένας "νορμάλ" σκύλος System.out.print("[ φσιτ]"); // και επιπλέον "σφυρίζει" }; } class Fish extends Animal { void saySomething() { System.out.print("[ Μπλμ]");} void reactToEarthQuake() { System.out.print("[~~~~~]");}; // σε περίπτωση σεισμού "κυματίζει" } class JungleDemo { public static void main(String[] aaa) { Dog d1 = new Dog(); d1.reactToEarthQuake(); /* Cat c1 = new Cat(); c1.saySomething(); System.out.println(); c1.reactToEarthQuake(); System.out.println(); Animal a1 = c1; System.out.println(a1.name); System.out.println(((Cat)a1).name); System.out.println(a1 instanceof Cat); // true System.out.println(a1 instanceof Animal); // true System.out.println(a1 instanceof Object); // true Animal a2 = new Animal(); System.out.println(a2 instanceof Cat); */ /* Animal a1 = new DogEMAK(); a1.saySomething(); System.out.println(); a1.reactToEarthQuake(); */ //Animal a1 = new Animal(); //a1.reactToEarthQuake(); // Animal c1 = new Cat(); // δημιουργία μιας γάτας, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // c1.reactToEarthQuake(); //Animal d1 = new Dog(); // δημιουργία ενός σκύλου, το δείκτη τον κρατά μτβλ τύπου Animal //c1.saySomething(); // Αν δεν υπήρχε overidding τί θα παίρναμε; //d1.saySomething(); //makeJungle(); } static void makeJungle() { System.out.println("S i m u l a t i o n o f t h e U n i v e r s e v0.1"); int numOfAnimals = 100; // πλήθος των ζώων που θα δημιουργηθούν System.out.println("Number of animals:" + numOfAnimals); Animal[] amazonios = new Animal[numOfAnimals]; // πίνακας που θα κρατάει αναφορές στα αντικείμενα τύπου ζώο // CREATION DAY for (int i=0; i<numOfAnimals; i++ ){ //amazonios[i] = (Math.random() > 0.6) ? new Dog() : new Cat() ; // an thelame mono gates kai skylous double tyxaiosArithmos = Math.random(); // από το<SUF> Animal neoZwo; if (tyxaiosArithmos<0.3) neoZwo = new Cat(); else if (tyxaiosArithmos<0.6) neoZwo = new Dog(); else if (tyxaiosArithmos<0.9) neoZwo = new Fish(); else neoZwo = new DogEMAK(); amazonios[i] = neoZwo; } // EXISTENCE CHECK System.out.println("\n========= YPARKSIAKOS ELEGXOS ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].saySomething(); } // EARTHQUAKE REACTION: System.out.println("\n========= SEISMOS! ========="); for (int i=0; i<numOfAnimals; i++ ){ amazonios[i].reactToEarthQuake(); } // NIKHTHS TOU LOTTO System.out.println("\n========= APOTELESMATA KLHRWSHS ========= "); int luckyIndex = (int) Math.round(Math.random()*numOfAnimals); System.out.println("O nikiths ths klhrwshs auths ths ebdomadas einai to zwo me arithmo " + luckyIndex + " το οποίο ανήκει στην κλάση " + amazonios[luckyIndex].getClass() ); // reflection if (amazonios[luckyIndex] instanceof Dog) System.out.println("Πράγματι είναι σκύλος."); Object o1 = new DogEMAK(); Dog o2 = ((Dog) o1); Animal a3 = o2; System.out.println("Η ΚΛΑΣΗ ΤΟΥ ΕΙΝΑΙ " + a3.getClass() + " " + ((Dog)a3).name); } }
17_0
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class XlsReader { private ArrayList<Course> courses=new ArrayList<Course>(); private ArrayList<Course> coursesSelected=new ArrayList<Course>(); private HashSet<String> courseDistinct = new HashSet<String>(); private HashSet<String> courseDistinctSelected = new HashSet<String>(); private ArrayList<CourseStats> courseStats = new ArrayList<CourseStats>(); private ArrayList<CourseStats> courseStatsSelected = new ArrayList<CourseStats>(); private ArrayList<String> courseStr = new ArrayList<String>(); private String dirstr; public void read() { int i; int j; int k; int day; int counter; int hour; String cellstring; boolean merged; String cellinfo; String course; String classs; String classr; String sheetName; String sheetName2; int numOfSheets; int cindex; int cindex2; int index2; int prev=0; boolean added; Workbook workbook = null; JOptionPane.showMessageDialog(null, "Επιλέξτε το πρόγραμμα αφου το έχετε αποθηκεύσει ως .xls αρχείο."); JButton open = new JButton(); JFileChooser chooser= new JFileChooser(); chooser.setDialogTitle("Επιλογή προγραμματος"); if(chooser.showOpenDialog(open) == JFileChooser.CANCEL_OPTION) { System.exit(0); } Path xlPath = Paths.get(chooser.getSelectedFile().getAbsolutePath()); String path = xlPath.toString(); try { workbook = Workbook.getWorkbook(new File(path)); // Ανοιγουμε το εξελ σε μεταβλητη τυπου workbook και παιρνουμε στην μεταβλητη numOfSheets τα φυλλα του numOfSheets = workbook.getNumberOfSheets(); for(k=0;k<numOfSheets;k++) // για καθε φυλλο { Sheet sheet = workbook.getSheet(k); sheetName = sheet.getName(); // το ονομα του φυλλου περιεχει κατευθυνση και εξαμηνο οποτε κανουμε substring και τα αποκταμε cindex2 = sheetName.indexOf("'"); sheetName2 = sheetName.substring(0, cindex2); cindex = sheetName.indexOf('-'); sheetName = sheetName.substring(cindex+1); day = 0; j=2; counter = 0; merged = false; do { if(sheet.getCell(j,3).getCellFormat().getAlignment().getDescription().equals("centre")) // ελεγχοι για να δουμε αν καποιο cell ειναι merged { day++; } if(sheet.getCell(j,3).getCellFormat().getWrap()==false) { merged = true; } else { merged = false; } // σε περιπτωση που ειναι merged πρεπει να καταλαβουμε μεχρι που ειναι merged για να κανουμε copy paste την πληροφορια του original cell i=4; do{ Cell cell = sheet.getCell(j, i); cellstring = cell.toString(); if(cellstring.contains("Label") || cellstring.contains("Mul") || cellstring.contains("Blank")) { //ελεγχος για το αν το cell ειναι original (περιεχει πληροφοριες και δεν ειναι merged) hour = i+4; //ωρα course = ""; // μαθημα classs = "κοινό"; // κατευθυνση classr = ""; // αιθουσα if(cellstring.contains("Label")) { cellinfo = cell.getContents().trim().replaceAll(" +", " "); cindex = cellinfo.indexOf('('); course = cellinfo.substring(0, cindex); if(course.contains(" / "))// αποθηκευουμε τα ονοματα των μαθηματων πριν την παρενθεση που ξεκιναει ο κωδικος. Σασ συνιστω να εχετε και το excel διπλα να καταλαβαινετε τι λεω { course = course.replace("/", "-"); } if(cellinfo.contains("Τμήμα ")) { index2 = cellinfo.indexOf("Τμήμα "); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα: ")) { index2 = cellinfo.indexOf("Τμήμα: "); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα")) { index2 = cellinfo.indexOf("Τμήμα"); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα:")) { index2 = cellinfo.indexOf("Τμήμα:"); classs = cellinfo.substring(index2 + 6,index2 + 7); // το τμημα το γραφουν με τους εξης διαφορετικους τροπους οποτε επρεπε να γινει σωστα το subsrting } if(cellinfo.contains("Αίθουσα ")) { index2 = cellinfo.indexOf("Αίθουσα "); classr = cellinfo.substring(index2); } if(cellinfo.contains("Αμφιθέατρο") && cellinfo.contains("ΚΕΥΠ")) { index2 = cellinfo.indexOf("Αμφιθέατρο"); classr = cellinfo.substring(index2); } else if(cellinfo.contains("ΚΕΥΠ")) { index2 = cellinfo.indexOf("ΚΕΥΠ"); classr = cellinfo.substring(index2); } else if(cellinfo.contains("Αμφιθέατρο ")) { index2 = cellinfo.indexOf("Αμφιθέατρο "); classr = cellinfo.substring(index2); } if(cellinfo.contains("Εργαστήριο ")) { index2 = cellinfo.indexOf("Εργαστήριο "); classr = cellinfo.substring(index2); } //το ιδιο και η αιθουσα if(classr.contains("\n")) { index2 = classr.indexOf("\n"); classr = classr.substring(0,index2); } if(cellinfo.contains("Φροντιστήριο")==false) { //δεν μας ενδιαφερουν τα φροντιστηριακα counter = 0; if(hour!=22) { courses.add(new Course(course,day,hour,classr,classs,sheetName2,sheetName)); //αποκτησαμε ολες τις πληροφοριες και δημιουργουμε το course } added = false; if(sheetName.equals("ΚΕΠ") || sheetName.equals("ΚΟΙΝΟ") ) { added = courseDistinct.add(course); } else if(sheetName.equals("ΚΔΤ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinctSelected.add(course); } if (added == true) { courseStats.add(new CourseStats(course,sheetName2,sheetName)); } prev=j; //εδω περα χρησιμοποιω ενα hashset για να δω αν μπορει να εισαχθει το στοιχειο τυπου CourseStat που //θα ειναι distinct και με την added την προσθετω σε ταξινομημενο arrayList } } if (cell.getCellFormat().getWrap() == false && cell.getCellFormat().getAlignment().getDescription().equals("general") && counter <2 && prev ==j) //ελεγχω αν ειναι merged αν εχει αλλαξει η μερα //και εαν τυχαινει να ειναι merged αλλα να ξεπερασει το τριωρο το μαθημα. σε μερικες μερες εχουμε merge στηλων και ηταν δυσκολο να γινει ο διαχωρισμος { counter++; course = courses.get(courses.size()-1).getName(); classs = courses.get(courses.size()-1).getClasss(); classr = courses.get(courses.size()-1).getClassr(); if(classs.equals("4") && (classr.contains("Εργαστήριο") || classr.contains("ΚΕΥΠ"))) { break; } if(hour!=22) { courses.add(new Course(course,day,hour,classr,classs,sheetName2,sheetName)); } added = false; if(sheetName.equals("ΚΕΠ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinct.add(course); } else if(sheetName.equals("ΚΔΤ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinctSelected.add(course); } if (added == true) { courseStats.add(new CourseStats(course,sheetName2,sheetName)); } } //παρομοιοι ελεγχοι για τα original cells } if(sheet.getCell(1,i).getCellFormat().getWrap() == true && sheet.getCell(1,i).getContents().equals("")) { break; } i++; //γραμμες if(i>17) { break; } }while(true); if(sheet.getCell(j,3).getContents().equals("")==true && merged == false) { break; } j++; //στηλες }while(true); } Collections.sort(courseStats); //sort } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { JOptionPane.showMessageDialog(null, "Λάθος αρχείο.","ERROR",JOptionPane.ERROR_MESSAGE); System.exit(1); e.printStackTrace(); } finally { if (workbook != null) { workbook.close(); } } } public ArrayList<Course> getCourses() { return courses; } public ArrayList<CourseStats> getCoursesStats() { return courseStats; } public void printCourses() { if(courses.size()>1) { for(int k=0;k<courses.size();k++) { System.out.println(courses.get(k).toString()); } } } public void printCoursesStats() { if(courseStats.size()>1) { for(int k=0;k<courseStats.size();k++) { System.out.println(courseStats.get(k).toString()); } } } public void setArrayString(ArrayList<String> anArray) { this.courseStr.addAll(anArray); } public void setSelectedDirection(String str) { dirstr = str; } public void writeSelectedCourses() { //serialize των επιλεγμενων μαθηματων απο την CheckboxGui for(int i=0;i<courseStr.size();i++) { String temp = courseStr.get(i).replace("\n",""); courseStr.remove(i); courseStr.add(i,temp); for(int j=0;j<courses.size();j++) { if(courseStr.get(i).equals(courses.get(j).getName()) && dirstr.equals(courses.get(j).getDirection())) { coursesSelected.add(courses.get(j)); } if(courseStr.get(i).equals(courses.get(j).getName()) && courses.get(j).getDirection().equals("ΚΟΙΝΟ")) { coursesSelected.add(courses.get(j)); } } for(int k=0;k<courseStats.size();k++) { if(courseStr.get(i).equals(courseStats.get(k).getName())) { courseStatsSelected.add(courseStats.get(k));; } } } try { FileOutputStream fileOut = new FileOutputStream("Course.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(coursesSelected); out.close(); fileOut.close(); } catch(IOException i) { i.printStackTrace(); } finally { System.out.println("Serialization Attempted..."); } try { FileOutputStream fileOut = new FileOutputStream("CourseStats.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(courseStatsSelected); out.close(); fileOut.close(); } catch(IOException i) { i.printStackTrace(); } finally { System.out.println("Serialization Attempted..."); } } }
GeorgeMichos13/MyUom
src/XlsReader.java
4,446
// Ανοιγουμε το εξελ σε μεταβλητη τυπου workbook και παιρνουμε στην μεταβλητη numOfSheets τα φυλλα του
line_comment
el
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class XlsReader { private ArrayList<Course> courses=new ArrayList<Course>(); private ArrayList<Course> coursesSelected=new ArrayList<Course>(); private HashSet<String> courseDistinct = new HashSet<String>(); private HashSet<String> courseDistinctSelected = new HashSet<String>(); private ArrayList<CourseStats> courseStats = new ArrayList<CourseStats>(); private ArrayList<CourseStats> courseStatsSelected = new ArrayList<CourseStats>(); private ArrayList<String> courseStr = new ArrayList<String>(); private String dirstr; public void read() { int i; int j; int k; int day; int counter; int hour; String cellstring; boolean merged; String cellinfo; String course; String classs; String classr; String sheetName; String sheetName2; int numOfSheets; int cindex; int cindex2; int index2; int prev=0; boolean added; Workbook workbook = null; JOptionPane.showMessageDialog(null, "Επιλέξτε το πρόγραμμα αφου το έχετε αποθηκεύσει ως .xls αρχείο."); JButton open = new JButton(); JFileChooser chooser= new JFileChooser(); chooser.setDialogTitle("Επιλογή προγραμματος"); if(chooser.showOpenDialog(open) == JFileChooser.CANCEL_OPTION) { System.exit(0); } Path xlPath = Paths.get(chooser.getSelectedFile().getAbsolutePath()); String path = xlPath.toString(); try { workbook = Workbook.getWorkbook(new File(path)); // Ανοιγουμε το<SUF> numOfSheets = workbook.getNumberOfSheets(); for(k=0;k<numOfSheets;k++) // για καθε φυλλο { Sheet sheet = workbook.getSheet(k); sheetName = sheet.getName(); // το ονομα του φυλλου περιεχει κατευθυνση και εξαμηνο οποτε κανουμε substring και τα αποκταμε cindex2 = sheetName.indexOf("'"); sheetName2 = sheetName.substring(0, cindex2); cindex = sheetName.indexOf('-'); sheetName = sheetName.substring(cindex+1); day = 0; j=2; counter = 0; merged = false; do { if(sheet.getCell(j,3).getCellFormat().getAlignment().getDescription().equals("centre")) // ελεγχοι για να δουμε αν καποιο cell ειναι merged { day++; } if(sheet.getCell(j,3).getCellFormat().getWrap()==false) { merged = true; } else { merged = false; } // σε περιπτωση που ειναι merged πρεπει να καταλαβουμε μεχρι που ειναι merged για να κανουμε copy paste την πληροφορια του original cell i=4; do{ Cell cell = sheet.getCell(j, i); cellstring = cell.toString(); if(cellstring.contains("Label") || cellstring.contains("Mul") || cellstring.contains("Blank")) { //ελεγχος για το αν το cell ειναι original (περιεχει πληροφοριες και δεν ειναι merged) hour = i+4; //ωρα course = ""; // μαθημα classs = "κοινό"; // κατευθυνση classr = ""; // αιθουσα if(cellstring.contains("Label")) { cellinfo = cell.getContents().trim().replaceAll(" +", " "); cindex = cellinfo.indexOf('('); course = cellinfo.substring(0, cindex); if(course.contains(" / "))// αποθηκευουμε τα ονοματα των μαθηματων πριν την παρενθεση που ξεκιναει ο κωδικος. Σασ συνιστω να εχετε και το excel διπλα να καταλαβαινετε τι λεω { course = course.replace("/", "-"); } if(cellinfo.contains("Τμήμα ")) { index2 = cellinfo.indexOf("Τμήμα "); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα: ")) { index2 = cellinfo.indexOf("Τμήμα: "); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα")) { index2 = cellinfo.indexOf("Τμήμα"); classs = cellinfo.substring(index2 + 6,index2 + 7); } else if(cellinfo.contains("Τμήμα:")) { index2 = cellinfo.indexOf("Τμήμα:"); classs = cellinfo.substring(index2 + 6,index2 + 7); // το τμημα το γραφουν με τους εξης διαφορετικους τροπους οποτε επρεπε να γινει σωστα το subsrting } if(cellinfo.contains("Αίθουσα ")) { index2 = cellinfo.indexOf("Αίθουσα "); classr = cellinfo.substring(index2); } if(cellinfo.contains("Αμφιθέατρο") && cellinfo.contains("ΚΕΥΠ")) { index2 = cellinfo.indexOf("Αμφιθέατρο"); classr = cellinfo.substring(index2); } else if(cellinfo.contains("ΚΕΥΠ")) { index2 = cellinfo.indexOf("ΚΕΥΠ"); classr = cellinfo.substring(index2); } else if(cellinfo.contains("Αμφιθέατρο ")) { index2 = cellinfo.indexOf("Αμφιθέατρο "); classr = cellinfo.substring(index2); } if(cellinfo.contains("Εργαστήριο ")) { index2 = cellinfo.indexOf("Εργαστήριο "); classr = cellinfo.substring(index2); } //το ιδιο και η αιθουσα if(classr.contains("\n")) { index2 = classr.indexOf("\n"); classr = classr.substring(0,index2); } if(cellinfo.contains("Φροντιστήριο")==false) { //δεν μας ενδιαφερουν τα φροντιστηριακα counter = 0; if(hour!=22) { courses.add(new Course(course,day,hour,classr,classs,sheetName2,sheetName)); //αποκτησαμε ολες τις πληροφοριες και δημιουργουμε το course } added = false; if(sheetName.equals("ΚΕΠ") || sheetName.equals("ΚΟΙΝΟ") ) { added = courseDistinct.add(course); } else if(sheetName.equals("ΚΔΤ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinctSelected.add(course); } if (added == true) { courseStats.add(new CourseStats(course,sheetName2,sheetName)); } prev=j; //εδω περα χρησιμοποιω ενα hashset για να δω αν μπορει να εισαχθει το στοιχειο τυπου CourseStat που //θα ειναι distinct και με την added την προσθετω σε ταξινομημενο arrayList } } if (cell.getCellFormat().getWrap() == false && cell.getCellFormat().getAlignment().getDescription().equals("general") && counter <2 && prev ==j) //ελεγχω αν ειναι merged αν εχει αλλαξει η μερα //και εαν τυχαινει να ειναι merged αλλα να ξεπερασει το τριωρο το μαθημα. σε μερικες μερες εχουμε merge στηλων και ηταν δυσκολο να γινει ο διαχωρισμος { counter++; course = courses.get(courses.size()-1).getName(); classs = courses.get(courses.size()-1).getClasss(); classr = courses.get(courses.size()-1).getClassr(); if(classs.equals("4") && (classr.contains("Εργαστήριο") || classr.contains("ΚΕΥΠ"))) { break; } if(hour!=22) { courses.add(new Course(course,day,hour,classr,classs,sheetName2,sheetName)); } added = false; if(sheetName.equals("ΚΕΠ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinct.add(course); } else if(sheetName.equals("ΚΔΤ") || sheetName.equals("ΚΟΙΝΟ")) { added = courseDistinctSelected.add(course); } if (added == true) { courseStats.add(new CourseStats(course,sheetName2,sheetName)); } } //παρομοιοι ελεγχοι για τα original cells } if(sheet.getCell(1,i).getCellFormat().getWrap() == true && sheet.getCell(1,i).getContents().equals("")) { break; } i++; //γραμμες if(i>17) { break; } }while(true); if(sheet.getCell(j,3).getContents().equals("")==true && merged == false) { break; } j++; //στηλες }while(true); } Collections.sort(courseStats); //sort } catch (IOException e) { e.printStackTrace(); } catch (BiffException e) { JOptionPane.showMessageDialog(null, "Λάθος αρχείο.","ERROR",JOptionPane.ERROR_MESSAGE); System.exit(1); e.printStackTrace(); } finally { if (workbook != null) { workbook.close(); } } } public ArrayList<Course> getCourses() { return courses; } public ArrayList<CourseStats> getCoursesStats() { return courseStats; } public void printCourses() { if(courses.size()>1) { for(int k=0;k<courses.size();k++) { System.out.println(courses.get(k).toString()); } } } public void printCoursesStats() { if(courseStats.size()>1) { for(int k=0;k<courseStats.size();k++) { System.out.println(courseStats.get(k).toString()); } } } public void setArrayString(ArrayList<String> anArray) { this.courseStr.addAll(anArray); } public void setSelectedDirection(String str) { dirstr = str; } public void writeSelectedCourses() { //serialize των επιλεγμενων μαθηματων απο την CheckboxGui for(int i=0;i<courseStr.size();i++) { String temp = courseStr.get(i).replace("\n",""); courseStr.remove(i); courseStr.add(i,temp); for(int j=0;j<courses.size();j++) { if(courseStr.get(i).equals(courses.get(j).getName()) && dirstr.equals(courses.get(j).getDirection())) { coursesSelected.add(courses.get(j)); } if(courseStr.get(i).equals(courses.get(j).getName()) && courses.get(j).getDirection().equals("ΚΟΙΝΟ")) { coursesSelected.add(courses.get(j)); } } for(int k=0;k<courseStats.size();k++) { if(courseStr.get(i).equals(courseStats.get(k).getName())) { courseStatsSelected.add(courseStats.get(k));; } } } try { FileOutputStream fileOut = new FileOutputStream("Course.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(coursesSelected); out.close(); fileOut.close(); } catch(IOException i) { i.printStackTrace(); } finally { System.out.println("Serialization Attempted..."); } try { FileOutputStream fileOut = new FileOutputStream("CourseStats.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(courseStatsSelected); out.close(); fileOut.close(); } catch(IOException i) { i.printStackTrace(); } finally { System.out.println("Serialization Attempted..."); } } }
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
6