using the acm java libraries in cs 1

Upload: artsan3

Post on 05-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    1/26

    Using the ACM Java Libraries in CS 1

    Andrew MertzWilliam Slough

    Nancy Van Cleave

    Mathematics and Computer Science DepartmentEastern Illinois University

    September 26, 2008

    CCSC: MW 2008, Hope College

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    2/26

    Overview

    About us: challenges & resources

    The ACM Java library: contents

    Sampling a few laboratory exercises

    Conclusions

    CCSC: MW 2008, Hope College

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    3/26

    Background

    CS 1 challenges

    Diverse audience: varying majors and interestsLanguage choiceIdentify interesting, authentic and accessible projectsWhat should be taught?

    Our CS 1 courseLab-based: three 50-minute lectures + one 100-minute labIncorporates simple graphicsUses Java and the ACM Java Libraries

    Laboratory environmentLinuxJava JDK + NetBeansACM Java Libraries Java applets student web sites

    CCSC: MW 2008, Hope College

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    4/26

    Course history

    AP CS language: Java

    Desire for graphics early

    Language evolution:

    Pascal C++ Java

    Library evolution:

    home grown textbook-supplied ACM Java libraries

    ACM Java libraries, adopted Fall 2007

    CCSC: MW 2008, Hope College

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    5/26

    ACM Java Task Force: modern programming languages

    How have modern programming languages affected pedagogy?

    Complexity

    The number of details that students must

    master. . .

    has grown much faster than thecorresponding number of high-level concepts.

    Instability

    The languages, APIs, and tools. . . are changing

    more rapidly than . . . in the past.

    http://jtf.acm.org/rationale/introduction.htmlCCSC: MW 2008, Hope College

    http://jtf.acm.org/rationale/introduction.htmlhttp://jtf.acm.org/rationale/introduction.html
  • 8/2/2019 Using the ACM Java Libraries in CS 1

    6/26

    ACM Java libraries

    Released in 2006

    Used extensively in The Art and Science of Java: AnIntroduction to Computer Science, Eric Roberts, 2008

    Libraries include:

    Object-oriented model for programsSimple methods for I/OAccessible graphics capabilities

    Yield stand-alone programs or applets

    CCSC: MW 2008, Hope College

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    7/26

    Student work

    Live demo: http://www.eiu.edu/~mathcs/http/

    CCSC: MW 2008, Hope College

    http://www.eiu.edu/~mathcs/http/http://www.eiu.edu/~mathcs/http/http://www.eiu.edu/~mathcs/http/http://www.eiu.edu/~mathcs/http/
  • 8/2/2019 Using the ACM Java Libraries in CS 1

    8/26

    ACM Java libraries: packages

    acm.program Provides object-oriented program model

    acm.io Assists with input and output operations

    acm.graphics Supports simple, object-oriented graphicsacm.gui Simplifies creation of interactive programs

    acm.util Miscellaneous utility classes

    CCSC: MW 2008, Hope College

    C f

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    9/26

    Class diagram for acm.program

    javax.swing.JMenuBar

    ProgramMenuBar

    javax.swing.JApplet

    Program

    ConsoleProgram DialogProgram GraphicsProgram

    Program Input and output using the system console

    ConsoleProgram Uses a program frame with an interactiveconsole (acm.io.Console)

    DialogProgram Input/output is performed within dialogboxes

    GraphicsProgram Fills the program frame with a GCanvas for

    drawing graphics objectsCCSC: MW 2008, Hope College

    C l dd i

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    10/26

    Console program: add two integers

    /*

    * File: Add2.java

    *

    * This program ...

    *

    */

    import acm.program.*;

    public class Add extends ConsoleProgram {

    public void run() {

    int a = readInt("Enter a: ");int b = readInt("Enter b: ");

    println("a + b = " + (a + b));

    }

    }

    CCSC: MW 2008, Hope College

    C l dd i

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    11/26

    Console program: add two integers

    CCSC: MW 2008, Hope College

    Di l dd t i t

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    12/26

    Dialog program: add two integers

    /*

    * File: Add.java

    *

    * This program ...

    *

    */

    import acm.program.*;

    public class Add extends DialogProgram {

    public void run() {

    int a = readInt("Enter a: ");int b = readInt("Enter b: ");

    println("a + b = " + (a + b));

    }

    }

    CCSC: MW 2008, Hope College

    Di l dd t i t

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    13/26

    Dialog program: add two integers

    CCSC: MW 2008, Hope College

    G hi s g t d fill d i l

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    14/26

    Graphics program: centered filled circle

    import acm.graphics.*;

    import acm.program.*;

    import java.awt.*;

    public class Circle extends GraphicsProgram {

    public void run() {int radius = 50;

    GOval myCircle = new GOval(getWidth()/2 - radius,

    getHeight()/2 - radius,

    2*radius, 2*radius);

    myCircle.setColor(Color.RED);myCircle.setFilled(true);

    add(myCircle);

    }

    }

    CCSC: MW 2008, Hope College

    Graphics program: centered filled circle

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    15/26

    Graphics program: centered filled circle

    CCSC: MW 2008, Hope College

    Advantages

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    16/26

    Advantages

    Many details are hidden

    Unifies applets and applications

    Simple and consistent syntax

    Ability to add new functionality by manipulating or adding tounderlying objects

    Entry point is run rather than main

    CCSC: MW 2008, Hope College

    acm graphics

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    17/26

    acm.graphics

    Uses collage model; objects are added to GCanvas

    Newer objects can obscure earlier ones

    Distances and coordinates are measured in pixels, specified asfloating point values

    Several classes provided

    CCSC: MW 2008, Hope College

    acm graphics: partial class diagram

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    18/26

    acm.graphics: partial class diagram

    java.awt.Container

    GCanvas

    GObject GCompound

    GLabel

    GRectGOval

    GLine

    GPolygon

    GImageGArc

    GTurtle

    CCSC: MW 2008, Hope College

    Introductory lab: orientation

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    19/26

    Introductory lab: orientation

    Learn NetBeans IDE basics

    Download and install ACM Java libraries

    Create and modify simple Java programs

    Create several Java applets

    Use basic HTML to create a web site portfolio

    CCSC: MW 2008, Hope College

    Introductory lab: Hello world! modification

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    20/26

    Introductory lab: Hello, world! modification

    import acm.graphics.*;

    import acm.program.*;

    public class HelloProgram extends GraphicsProgram {

    public void run() {add(new GLabel("Hello, world!", 100, 75));

    add(new GLabel("My Name is Julie.", 100, 95));

    add(new GLabel("Im from Chicago.", 100, 115));

    }

    }

    CCSC: MW 2008, Hope College

    Introductory lab: Hello world! modification

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    21/26

    Introductory lab: Hello, world! modification

    CCSC: MW 2008, Hope College

    Curve stitch/string art

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    22/26

    Curve stitch/string art

    Recreational mathematics

    Vehicle for loops

    Parameterization: square size, number of segments

    Visual clues during debugging

    1 2 3 4

    1

    2

    3

    4

    1 2 3 4

    1

    2

    3

    4

    CCSC: MW 2008, Hope College

    Curve stitch/string art

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    23/26

    Curve stitch/string art

    CCSC: MW 2008, Hope College

    The jailers problem

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    24/26

    j p b

    1 2 3 4initially L L L L

    after pass 1 U U U U

    after pass 2 U L U L

    after pass 3 U L L L

    after pass 4 U L L U

    1 2 3 4

    1 2 3 4

    1 2 3 4

    1 2 3 4

    1 2 3 4

    Given n cells, which will end up unlocked?

    Unfamiliar problem; non-obvious pattern

    Motivates the idea of a GNumberedRect class

    CCSC: MW 2008, Hope College

    Other laboratory assignments

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    25/26

    y g

    Bouncing ball

    A simplified pool table

    Julia setsRandom walk on a lattice

    . . .

    CCSC: MW 2008, Hope College

    Conclusions

  • 8/2/2019 Using the ACM Java Libraries in CS 1

    26/26

    We agree with the motivations of the ACM Java Task Force

    We found simplifications to Java helpful for CS 1

    Learning about the libraries is not a dead-end

    Graphics allows for interesting assignments

    Plentiful documentation and pedagogy available

    CCSC: MW 2008, Hope College