Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Teaching Object Oriented Java with Students and Ice Cream

"I'm getting tired of students. Can we do something else". So said my delegates at Cardiff University today. So we did Ice Cream and other deserts!

Perhaps I had better explain. I'm running a Java Course there, and looking for examples of classes and objects to write about. At the start of the course, delegates know diddly squat about OO design, and how it works in Java, so the first sample programs they write are tentative steps and using only an edited selection of the facilities available. Then they extend the example and find that "I wish I had known before I started that I would be going this way" but the catch is that they couldn't have known - too much information before the first practical means a poor practical and some points missed. So after the first example has been written, stretched, overstretched and pulled apart nearly to the point of breaking we consolidate the knowledge gained into a fresh example which can be written, from the beginning with the end target in mind.

I'm not doing to show you any of the "student" examples. They look horrid / they show things that are kludged together nastily and I would be ashamed of them. But I will show you the Dairy Queen class!

public class DairyQueen {
 
  public static void main (String [] args) {
 
    Desert [] Ice = new Desert[6];
 
    Ice[0] = new Icecream("Chocolate", 1000, 100,0);
    Ice[1] = new Icecream("Vanilla", 1400, 150,-15);
    Ice[2] = new Icecream("Strawberry", 1200, 100,-15);
    Ice[3] = new Icecream("Nut", 900, 100,-15);
    Ice[4] = new Icecream("Pistaccio", 450, 50,-25);
    Ice[5] = new Colddesert(1500,90,-10,"Strawberry and courgette cheesecake");
 
    for (int k=0; k       String what = Ice[k].getwhat();
      int cals = Ice[k].getcals();
      int wei = Ice[k].getweight();
 
      System.out.print(what);
      System.out.print(" ");
      System.out.print(cals);
      System.out.print(" ");
      System.out.println(wei);
    }
  }
}


And how does that run?

Dorothy:febjava grahamellis$ java DairyQueen
Chocolate flavoured Ice Cream 1000 100
Vanilla flavoured Ice Cream 1400 150
Strawberry flavoured Ice Cream 1200 100
Nut flavoured Ice Cream 900 100
Pistachio flavoured Ice Cream 450 50
Strawberry and courgette cheesecake and custard 90 1500
Dorothy:febjava grahamellis$


Now - do you feel cheated that I've not shown you all the code? I'm glad you've noticed that I've not shown you everything but that's the very joy of Object Oriented programming. YOU write the bits that YOU know about, someone else writes all the detail that they know about, they hide it within a class of objects and you keep calling the class methods as you need too. This hiding stuff within is known as encapsulation!


Full code? Oh - if you MUST ;-)


Desert.java - basic object for a desert
Insurable.java - how to define something that's insurable
Icecream.java - an ice cream desert is a desert with other features
Colddesert.java - a cold desert is another type of desert
DairyQueen.java - the whole application (above) which pulls it together
(written 2008-02-12 23:00:53)

 
Associated topics are indexed under
J710 - Java - Extending Classes and More
Q907 - Object Orientation and General technical topics - Object Orientation: Design Techniques

Back to
To Wales - where theres still a toll on the bridge
Previous and next
or
Horse's mouth home
Forward to
A forum is not always the best vehicle
Some other Articles
Are nasty programs looking for security holes on your server?
Colour, Composition or Content
Chinese New Year
A forum is not always the best vehicle
Teaching Object Oriented Java with Students and Ice Cream
To Wales - where theres still a toll on the bridge
A Weekend in Liverpool
OO PHP demonstration - comparing objects and more
Where in the world / country is my visitor from?
Short and sweet and sticky - PHP form input
2259 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2009: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho