Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming with Objects Object Interaction (Part 1) Week 9.

Similar presentations


Presentation on theme: "Programming with Objects Object Interaction (Part 1) Week 9."— Presentation transcript:

1 Programming with Objects Object Interaction (Part 1) Week 9

2 Abstraction & modularisation The modulo operator Programming with Objects CONCEPTS COVERED THIS WEEK

3 Abstraction is the ability to ignore details of parts to focus attention on a higher level of a problem. Modularisation is the process of dividing a whole into a set of well-defined parts, where each part can be built and tested separately, and where each part only interacts with other parts in well-defined ways. Programming with Objects ABSTRACTION & MODULARISATION

4 It is an object that is made up of other objects! Wheels, Seats, Chassis, Exhaust, Steering Wheel, etc. This car is a Complex Object And… a wheel itself is also a complex object! Tyre, Trim, Hub Cap, etc. ABSTRACTION Object Model

5 MODULARISATION Object Model Team 1 works on producing the Engine Design: Team 2 works on producing the Seat Design: Team 3 works on producing the Wheel Design: Team 3a works on producing the Tyre Design:

6 Programming with Objects ABSTRACTION & MODULARISATION A digital clock

7 Programming with Objects ABSTRACTION & MODULARISATION Modularising the clock display One four-digit display? Or two two-digit displays?

8 BlueJ Demonstration A look at the NumberDisplay class

9 Programming with Objects Source Code - NumberDisplay public class NumberDisplay { private int limit; private int value; // Constructor and methods // omitted. }

10 Programming with Objects Source Code - NumberDisplay public NumberDisplay(int rollOverLimit) { limit = rollOverLimit; value = 0; } public int getValue() { return value; }

11 Programming with Objects Source Code - NumberDisplay public String getDisplayValue() { if(value < 10) { return "0" + value; } else { return "" + value; }

12 Programming with Objects Source Code - NumberDisplay public void setValue(int replacementValue) { if((replacementValue >= 0) && (replacementValue < limit)) { value = replacementValue; }

13 Modulo (or modulus or mod) operator The % operator gives the remainder of a division result = 10 % 3; assigns a value of 1 to result result = 15 % 6; result = 19 % 11;

14 Programming with Objects Source Code - NumberDisplay public void increment() { value = (value + 1) % limit; }

15 Required Reading Objects First With Java – A Practical Introduction using BlueJ Related reading for this lecture Chapter 3


Download ppt "Programming with Objects Object Interaction (Part 1) Week 9."

Similar presentations


Ads by Google