M1G413283 Introduction to Programming 2 - PowerPoint PPT Presentation

About This Presentation
Title:

M1G413283 Introduction to Programming 2

Description:

... A Practical Introduction Using BlueJ by David J ... Studying Programming by Sally Fincher ... Designing a program * Description of the game The game ... – PowerPoint PPT presentation

Number of Views:166
Avg rating:3.0/5.0
Slides: 24
Provided by: JimP74
Category:

less

Transcript and Presenter's Notes

Title: M1G413283 Introduction to Programming 2


1
M1G413283Introduction to Programming 2
  • 1. Designing a program

2
Teaching staff
  • Jim Paterson Room M628James.Paterson_at_gcu.ac.uk
  • Katrin HartmannRoom 611

3
Online resources
  • Blackboard
  • Announcements
  • Assessment information
  • Course website
  • Can be accessed through Blackboard
  • www.paterson.co.uk/gcal/intro2prog2.shtml
  • Lecture notes, lab tutorial sheets, etc
  • Links to other resources

4
Reading
  • No set text notes will be provided
  • The following books are recommended as additional
    reading
  • Objects First with Java A Practical Introduction
    Using BlueJ by David J. Barnes and Michael
    Kolling (ISBN 0137005628)
  • Studying Programming by Sally Fincher (ISBN
    1403946876)

5
Assessment
  • Class test
  • Lab exercises
  • PeerWise

6
Models in software development
  • A software system can be modelled using, for
    example, class diagrams
  • A model of the data in the system can be used to
    help design a database
  • A model can also be used to help design and
    create the software application, or program,
    which actually carries out the functions of the
    system

7
Java programs
  • A Java program can be
  • A few lines of code which perform a single
    function, for example to add two numbers
  • A large enterprise system consisting of many Java
    classes which provide very complex services
  • Anything in between...

8
Java programs
  • User interface can be
  • Windows application
  • Web pages
  • Web page applets
  • Phone applications
  • Games
  • Embedded
  • Command line
  • etc...

9
Object-oriented programs
  • Java is an object-oriented programming language
  • When an object-oriented program is running, it
    creates objects which work together, or
    collaborate, to perform the required actions
  • These objects often represent entities in the
    system
  • GCU Tours system has objects representing
    customers, bookings, and so on

10
Classes and objects
  • An OO program creates objects as it runs
  • Nees to have a template which specifies what type
    of object will be created and what that type of
    object can do
  • This template is called a class
  • In fact, when you write a program, you are
    actually writing the templates
  • An object is a single instance of a class there
    can be many objects of the same type

11
Class contents
  • A class specifies the following for the objects
    it is used to create
  • The name of the type of object (e.g. Customer)
  • The properties which each object will have (e.g.
    name)
  • The actions which each object can perform (e.g.
    change password)
  • The way in which each object is linked with other
    objects (e.g. with Booking objects)

12
Other languages
  • Other popular object-oriented languages include
    C, Visual Basic.NET, C, Python
  • In your university career you will come across a
    number of languages
  • Many of the techniques which you learn with Java
    have equivalents in other languages
  • Once you learn Java it is relatively easy to
    adapt to others.

13
What do classes represent?
  • Information
  • May be information which needs to be stored
    permanently - database

14
What do classes represent
  • Not all classes represent information
  • Other roles for classes
  • Getting input from the user and displaying output
  • Controlling the flow of activity while the
    program runs
  • Other specialised tasks for example formatting
    output, getting information into and out of the
    database, and so on

15
The GCU Adventure Game
  • Simple example of a system which uses objects
    which do a range of jobs and work together as a
    complete program
  • The GCU game is a text adventure game
    (interactive fiction)
  • Inspired by Hitchhikers Guide to the Galaxy game
    (but not as exciting!)
  • Borrowed liberally from example in Barnes and
    Kolling book

16
Description of the game
  • The game centres around characters travelling
    through a world which consists of rooms
  • Each room has a description
  • Rooms have exits which lead to other rooms
  • Each room can contain several items which may be
    used by a character when in that room

17
Description of the game
  • An item will also have a description
  • A player navigates through a world by typing
    commands (go north, go south, quit, and so on)
  • The game can be played by several players

18
Objects in the game
  • game this will be an object which sets up the
    game world and controls the game play
  • There will be only one Game object
  • room this will be an object which represents a
    room in the game world
  • There may be many rooms.
  • item this will be an object which represents an
    item in a room
  • There may be several items in each room.

19
Objects in the game
  • description this simply describes a room or
    item
  • a property rather than an object in its own right
  • exit an exit from a room is really just a way
    into another room
  • exit is actually a way of referring to a room
    object
  • player this will be an object which represents
    a player
  • player will be in one room at any time

20
Objects in the game
  • There may be several players in the game.
  • Each player should have a name, which is a
    property of the object.
  • command this will be an object as the job of
    representing players actions may be quite
    complicated
  • one command object for each input entered by a
    player.
  • Others may be required as program develops

21
Model for the game
  • Class diagram shows classes and properties
    identified, and suggests how they may be linked,
    or associated

22
Importance of the class diagram
  • While it is usually not the only part of a model
    of a system, the class diagram is very important
    when you start to build the system as a Java
    program
  • The classes become the Java classes which you
    need to write
  • Other diagrams are also useful, e.g. Activity,
    use case, sequence

23
Whats next?
  • Build incrementally a working implementation of
    the World of GCU adventure game
  • As we do so you will learn about some new
    programming techniques and tools as they are
    needed
  • You will also learn how the associations between
    classes in the game are implemented in Java
Write a Comment
User Comments (0)
About PowerShow.com