Γ ΕΠΑΛ ΕΙΔΙΚΑ ΘΕΜΑΤΑ ΣΤΟΝ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΚΕΦ1 2

download Γ ΕΠΑΛ ΕΙΔΙΚΑ ΘΕΜΑΤΑ ΣΤΟΝ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΚΕΦ1 2

of 40

description

Python, Επαλ, Β τάξη

Transcript of Γ ΕΠΑΛ ΕΙΔΙΚΑ ΘΕΜΑΤΑ ΣΤΟΝ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΚΕΦ1 2

  • ,

    ., ., ., .

    &

  • 2

    :

    ,

    :

    : . ,

    :

    ,

    ,

    ,

    ,

    :

    ,

    ,

    :

    , ...

    ,

    , MSc,

    : /....

  • 3

    .............................................................................. 6

    ............................................................................................................................. 7

    ................................................................... 8

    1.1. Java ........................................................................................... 10

    1.2. ................................................................................... 11

    1.3. ...................................................................... 12

    1.3.1. Greenfoot ....................................................................................................................... 12

    1.3.2. Eclipse ............................................................................................................................ 13

    1.4. ........................................................................................................... 14

    1.5. ................................................................................................... 15

    1.6. (attributes) ......................................................................................... 20

    1.7. ............................................................................................ 21

    ............................................................................................................................... 23

    1 ...................................................................................................................... 23

    2 ...................................................................................................................... 23

    3 ...................................................................................................................... 23

    ..................................................................................................... 24

    2.1. , , .......................................................................... 26

    2.1.1. ................................................................................................................. 26

    2.1.2. ......................................................................................................................... 26

    2.1.3. ................................................................................. 27

    2.2. if else ........................................................................................................ 28

    2.3. for while ........................................................................................ 29

    2.4. - .............................................................................................. 30

    2.5. .......................................................................................................... 33

    2.5.1. ............................................................................................................................. 35

    2.6. .......................................................................................................... 37

    2.7. ........................................................................................................................ 40

    1 ...................................................................................................................... 40

    2 ...................................................................................................................... 40

  • 4

    ENOTHTA 1

    1.1.1 Java ................................ 10

    1.2.1 Java ............................................................... 11

    1.3.1 Greenfoot .......................................................................... 12

    1.3.2 (workspace) Eclipse .............................................. 13

    1.3.3 To Eclipse .......................................................................... 13

    1.3.4 project .................................................................................... 14

    1.5.1 - ............................................................................................. 16

    1.5.2 Greenfoot ................................................................ 17

    1.5.3 1.5.4 .................................... 18

    1.5.5 ........................................................................................ 18

    1.5.6 Frog Fly ........................................................................................ 19

    1.5.7 .............................................................................. 20

    1.6.1 ......................................................................... 20

    1.7.1 ........................................................................................ 21

    1.7.2 Java .......................................................................................... 22

    2.4.1 Frog ............................................................................. 31

    2.4.2 ........................................................................................................... 32

    2.4.3 ................................................................................................. 33

    2.5.1 Actor .................................................................................... 34

    2.5.2 ....................................................................................................... 35

    2.5.3 greenfoot ................................................................................. 35

    2.5.4 Math ........................................................................................... 36

    2.5.5 ...................................................................................................... 37

    2.5.6 Frog ...................................................................................... 37

    2.6.1 Greenfoot .......................................................................... 38

    2.6.2 JOptionPan ............................................................ 39

  • 5

    1 .......................................................................................... 26

    2 ...................................................................................................... 26

    3 .......................................................................................................... 27

    4 ............................................................................................................. 27

    5 ............................................................................. 27

    6 ..................................... 32

    7 ................................................. 32

  • 6

    1

  • 7

    H Java , Android . , , . , , , . : GreenFoot Eclipse. GreenFoot . , (Pascal/Python). Eclipse Java (Ant, javadoc, JUnit). Eclipse Notepad++ . , , Java () . Java Task Force (JTF) ACM /. . Java . stackoverflow Java .

  • 8

    1

  • 9

    :

    (, , , )

    Java

    Greenfoot

  • 10

    1.1. Java

    H Java 1995 SUN . 13 2006 Java (GPL) (javac) (JDK, Java Development Kit). 2010 Oracle Corporation Sun Microsystems ( / ) .

    Java browser (applets). , Java , , , , , , .

    Java Oak, . C, C++ . . Write Once, Run Anywhere (WORA). Java Windows, Linux, Unix, Macintosh , Playstation, .

    Java , , java bytecode, , Java Virtual Machine. Java (Java Runtime Environment, JRE), . JRE (compiler), (interpreter).

    java , Java, JRE. java (javac) java bytecode, (editor) . Eclipse http://www.eclipse.org .

    1.1.1 Java

  • 11

    , Java (www, 3w), , 1995. , Java applets, (web browser). , , Flash HTML5.

    1.2.

    . . . , . : (compiler) (interpreter). . . , - .

    Java . java bytecode. , Java Virtual Machine (JVM). java bytecode .

    1.2.1 Java

    1.2.1 Java.

    , (compiler) Java. java, .. Hello.java,

  • 12

    .class Hello.class. (acm.program) Java. , Java jar.

    1.3.

    1.3.1. Greenfoot

    Greenfoot (IDE) Java. (actors) , .

    Greenfoot :

    (World), .

    (Class hierarchy), ( World ctor Greenfoot). World Actor .

    , . . . - . .

    1.3.1 Greenfoot

    : , , .

    , Save as .

  • 13

    1.3.2. Eclipse

    Eclipse Java, : Ada, C, C++, Perl, PHP, Python, Ruby .. (applets). Eclipse Android Development Tool (ADT) plug in, Android.

    Eclipse workspace project ( 1.3.2.1). project workspace . To Eclipse (workspace) workspace, Eclipse.

    1.3.2 (workspace) Eclipse

    Eclipse ( 1.3.2.2). :

    Package Explorer .

    Problems (Warnings) (Errors) .

    - .

    1.3.3 To Eclipse

  • 14

    .

    H Project FileNewJava Project. ( 1.3.2.3). . Eclipse src .

    1.3.4 project

    , . FileNewClass, . . , . .

    , RunRun.

    1.4.

    (classes) (objects or instances) .

    , . - (attributes) . , (), . , .

    , . , , ,

  • 15

    .. , , , , .. , , .. . , .. , , .., . , , , . , , . ; (). , . (.. ).

    . , , . .

    :

    (, , , , ..) (, , , , ..), .

    1 , 2 . :

    1.5.

    Java ( ) . (subclass) (superclass).

    , (), , ().

    -

    -

    -

    -

    -()

    - ()

    - ()

    - ()

    -()

    1

    = 1800 20V

    = 4

    = 3

    .

    2

    = 1600 16V

    = 4

    = 5

    .

  • 16

    . . .

    1.5.1 , , .

    -

    -

    -

    - ()

    - ()

    - ()

    - ()

    1.5.1 -

    , , , , , .. , .. , , , , .. , , .

    -

    -

    -

    -

    -

    - ()

    - ()

    - ()

    - ()

    - ()

    -

    -

    -

    -

    -

    - ()

    - ()

    - ()

    - ()

    - ()

    -

    -

    -

    -

    -

    - ()

    - ()

    - ()

    - ()

    - ()

    - ()

    - ()

  • 17

    1 :

    : FrogWorld , .

    Greenfoot . FrogEatFlies ( ) ( 1.5.2).

    1.5.2 Greenfoot

    . Greenfoot, , (Actors).

    , Frog ( ) Fly (). : ( ) , , , : FrogWorld . . , , .

    Greenfoot :

    - World, ,

    - Actor, .

    .

  • 18

    ( ), World. . World. FrogWorld, background: cell.jpg ( 1.5.3 1.5.4).

    1.5.3 1.5.4

    , FrogWorld World, World (.. , ..). - Greenfoot FrogWorld World ( 1.5.5).

    Greenfoot , M .

    1.5.5

    , . Actor, Animal () , Frog Fly. Animal , Frog Fly frog.png fly.png , animals ( 1.5.6).

  • 19

    1.5.6 Frog Fly

    , , .

    , Actor, ( ) , , .

    , Greenfoot. java bytecode, Java (Java Virtual Machine).

    , 1.5.5, FrogWorld , . . new Frog(), new Fly() ( 1.5.7). ( ) . , , .

  • 20

    1.5.7

    1.6. (attributes)

    , , . , (attributes), . .. Greenfoot , , , .

    2 :

    FrogEatFlies . . .

    . , . : x y (int x=37 int y=209) (int rotation=0). (GreenfootImage image) (World world) ( 1.6.1). , . .

    1.6.1

  • 21

    FrogWorld. Frog; , ;

    1.7.

    3 :

    DNA , , . DNA, .

    Frog . java.

    1.7.1

    ( 1.7.1) - () act() (

    Java). Greenfoot () ( ).

    act(), { }, (), , act().

    :

    .

    { } act() Frog:

    move(15); turn(10);

  • 22

    , Frog. .

    . move ( 1.7.2).

    1.7.2 Java

    , , .

    . . Greenfoot, . , .. (;) , .

    :

    { }

    ( ) .

    (;) .

    Java :

    .. Frog, .. FrogWorld.

    .. age.

  • 23

    1 Greenfoot

    : , , , , . 2 .

    2 http://www.greenfoot.org/scenarios

    Greenfoot , , .

    3 ,

    : , , , , , , , , ,

    , , , .

  • 24

    2

  • 25

    2.

    Java,

    (, , ), .

    Java APIs () . . .

    Java : .

    .

    , .

    :

    , ,

    if else

    for while

  • 26

    2.1. , ,

    H Java . Java , .

    2.1.1.

    , , :

    byte Byte 1 byte -128 127

    short

    2 bytes

    -32768 32767

    int 4 bytes -231 231-1

    long 8 bytes -263 263-1

    float

    ( ) 4 bytes

    1.4x10-45 3.4x1038

    double

    8 bytes

    4.9x10-324 1.8x10308

    boolean 1 bytes true / false

    char 2 bytes

    unicode

    1

    byte, short, int, long

    , float, double , . boolean true / false ( / ) char 2 bytes Unicode (UTF-16).

    2.1.2.

    Java : (=), , .. a = 496;

    496 a.

    + 18 + 10 28

    18 10 8

    * 18*10 180

    / 18/10 1

    18.0/10 1.8

    %

    18 % 10 8

    2

  • 27

    Java . (/) . , , .

    == 18 == 10 false

    < 18 < 10 false

    > 18 > 10 true

    = 10 true

    != 18 != 10 true

    3

    ! (not)

    && (and)

    || (or)

    ^ (xor)

    4

    , boolean Java.

    :

    A B !A A & B A | B A ^ B

    true true false true true false

    true false false false true true

    false true true false true true

    false false true false False false

    5

    . false && , false. . short-circuit evaluation.

    2.1.3.

    , . .

    Java C++ Pascal, ( Python , ). , , (, ).

    :

  • 28

    int number; // number . int counter = 6; // boolean areEqual = (number == counter); // (attributes),

    , (instances variables).

    ( ) . private ( ) .

    . .

    , (instance variable) :

    public private . ,

    , . . . greeklish. .

    2.2. if else

    Java . if . :

    if () { } else { }

    if else, ( ), else, ( ).

    if :

    if (number < 0) digits = -1; else if (number < 10) digits = 1;

  • 29

    else if (number < 100) digits = 2; else if (number < 1000) digits = 3; else digits = 4;

    , (

    ). :

    if (a != 0) { if (b > 0) { if (c < 0) { f = 1; } else { f = 2; if (b == 100) g = 9; } } }

    2.3. for while

    Java for while, :

    while ( ) { }

    for ( ; ; ) { }

    . 1 1000. :

    sum = 0; for (i = 1; i

  • 30

    . ( ) , . , ( ) .

    :

    int var=3; // var 3

    System.out.println(++var); // var 1 var

    System.out.println(var); // var

    4 . System.out.println(++var); var 3 4 .

    , :

    int var=3;

    System.out.println(var++); // var 1

    System.out.println(var); // var

    3 4.

    , System.out.println(var++); var, 3 var 3 4. 4.

    2.4. -

    , , , . . Java ( ). . . , . . .. (), (), ().

    Java APIs (Application Programming Interface) , Java. . JDK version 1.8 1.000 60 (packages). , . .

    :

    java.lang .

    java.util .

    java.sql Java Data ase Connectivity (JDBC) .

  • 31

    java.lang (Object, String, System)

    (Integer, Long, Double). , java.lang . import. . *,

    : import acm.program.*; acm.program.

    import . , import, .

    Math, java.lang, .

    Math.

    x = Math.max(a, b) ; // x a, b root = Math.sqrt(x) ; // x

    println, . println out , . out System. : :

    System.out.println(" ");

    java . Java, , , . . , , .

    4 :

    Greenfoot, FrogEatFlies. , , . , 2.4.1 Frog. Actor

    2.4.1 Frog

  • 32

    Actor. Frog Actor , .

    , Frog , , , .

    move(int)

    turn(int)

    act()

    setLocation(int, int)

    setRotation(int)

    6

    int .. move(int). int , . int . ( 2.4.2). (..:

    20) Ok. 20 .

    , Frog , ,

    . :

    getRotation()

    getWorld()

    getX()

    getY() y

    7

    , , . . .. getX() x ( 2.4.3).

    2.4.2

  • 33

    2.4.3

    setLocation(int, int) Frog x y . getX() x setLocation. setLocation . ;

    2.5.

    . (Documentation) . Java . (IDEs).

    5 :

    . Actor Open Documentation , Actor ( 2.5.1).

  • 34

    2.5.1 Actor

    Greenfoot Greenfoot, 2.5.2.

  • 35

    2.5.2

    greenfoot , 2.5.3.

    , , .

    greenfoot () .

    , Java .

    2.5.1.

    .

    :

    : , , (revision history) .

    : , , .

    2.5.3 greenfoot

  • 36

    .

    /* */.

    // . Java

    , javadoc . javadoc HTM. . (Development Kit), .

    2.5.4, Math , http://docs.oracle.com/javase/7/docs/api/

    2.5.4 Math

    6 :

    . Frog , , : (Frog) . @author @version 1.0 ( 2.5.5)

  • 37

    2.5.5

    Frog. ( 2.5.5).

    2.5.6 Frog

    2.6.

    , , (common dialogs) , . Java javax.swing (GUI). JOptionPane , . JOptionPane , documentation java : http://docs.oracle.com/javase/7/docs/api/.

    JOptionPane :

  • 38

    (ConfirmDialog)

    (InputDialog)

    (MessageDialog)

    (OptionDialog)

    7 :

    FrogEatFlies Greenfoot. , Frog.

    Frog .

    JOptionPane showInputDialog , . JOptionPane showMessageDialog .

    : import javax.swing.JOptionPane;

    JOptionPane javax.swing.

    act move turn :

    public void act() { if (Greenfoot.mousePressed(this)) { String inputStr = JOptionPane.showInputDialog(" , ;"); JOptionPane.showMessageDialog(null, " " + inputStr + "\n OK

    Enter ."); }

    . , Frog new Frog (), Frog . . , 2.6.1.

    2.6.1 Greenfoot

  • 39

    act (2) .

    import javax.swing.JOptionPane; public void act ( ) { String x = JOptionPane.showInputDialog(" "); String y = JOptionPane.showInputDialog(" "); int number1 = Integer.parseInt(x); int number2 = Integer.parseInt(y); int sum = number1 + number2; JOptionPane.showMessageDialog(null, " " + sum, " ", JOptionPane.PLAIN_MESSAGE);

    }

    2.6.2.

    2.6.2 JOptionPan

    PLAIN_MESSAGE :

    .

  • 40

    2.7.

    1

    1000 . / JOptionPane

    2

    JOptionPane .