Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

Database style application

Databases

As far as the old programme (up to May 2005) is concerned, this was the only dossier idea in town. Students getting ready for 2006 and later are lucky (really!) because they can either use this very common type of application or branch out into new areas.

For students who are not confident in their programming abilities, this may be a good choice because the design path is well-trodden.

 

I have encouraged my students to choose at least 4 but not more than 6 fields.

More fields simply adds to the workload..

Storing a date might require us to first define a Date Class which is a complication we can well do without at this stage.

I chose them to illustrate the use of different primitives, of course.

If you choose to put it in BlueJ we can use the object in interesting ways on the workbench.

 

 

 

Right-button click the compiled Biscuit Class and select new Biscuit() - or whatever your object is.

You have to give a name which is a valid Java identifier.

The comments also appear in this create Object dialog.

A red object instance appears on the bottom of the screen (the workbench).

We can see (and use) the Public methods of the Class.

 

On this page: [ an object | the BlueJ Workbench | Properties ]

An object

The first task is to develop a class which represents an object or item that you wish to store data about. It could be:

  • coffee drinks
  • songs
  • shops/stores
  • patients
  • video tapes (cheating!)
  • students
  • etc

Once the object is chosen, suitable fields have to be selected (fields, properties, any information you feel it useful to store to describe the object in question).

As an example I have selected biscuits. It is too late now but I do realize this may cause some confusion with our friends in the USA and elsewhere. A biscuit is the British term for what you guys would call a cookie.

Anyway I decided to keep the following information about biscuits:

  • shape
  • taste
  • price
  • unit
  • my favourite

Each field needs a type. This could be quite a complex decision, eg if we decided to store a date, but here we restrict ourselves to Java's primitive types.

I have chosen the following types:

// data members
private char shape;            // the biscuit shape - coded, eg R = round
private String taste;          // well, taste
private double price;          // um, the price
private int unit;              // the number of biscuits the price applies to
private boolean myFavourite;   // true if this is my favourite biscuit

Here is my first attempt at coding the Biscuit Class , you can download it and put it in your favourite editor. Better still, choose your own object and code it.

back to top

The workbench

With the class as it exists now, we could use it in another program and test all the methods. However, BlueJ allows us to create an Object (instance) and to assign properties using the mutator methods.

Try this:

back to top

Properties

Selecting a method from the menu brings up another dialog box, allowing you to use the method to set the property.

Note that if you want to set a String property you have to enclose it in quote marks:

  setTaste("Chocolate")

A char type has to be in single quotes:

    setShape('S')

Selecting the inspect menu option brings up a description of the current state of the object.

You can create as many objects as you like and place them on the workbench.

Each object instance is still a biscuit but each one has its own distinct properties.

back to top

Related: [ Java home | records home | next database page ]

Dedicated to the Class of 2006:

  Angel
  Bich Tram
  Fei Fei
  Jacky
  Jessie
  Lily
  Minh
  Shan
  Yuwei


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: May 31, 2009