programming with objects object interaction (part 1) week 9
TRANSCRIPT
![Page 1: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/1.jpg)
Programming with Objects
Object Interaction (Part 1)
Week 9
![Page 2: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/2.jpg)
• Abstraction & modularisation
• The modulo operator
Programming with Objects CONCEPTS COVERED THIS WEEK
![Page 3: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/3.jpg)
• 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 ObjectsABSTRACTION & MODULARISATION
![Page 4: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/4.jpg)
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
![Page 5: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/5.jpg)
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:
![Page 6: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/6.jpg)
Programming with Objects ABSTRACTION & MODULARISATION
A digital clock
![Page 7: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/7.jpg)
Programming with Objects ABSTRACTION & MODULARISATION
Modularising the clock display
One four-digit display?
Or two two-digit displays?
![Page 8: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/8.jpg)
BlueJ DemonstrationA look at the NumberDisplay class
![Page 9: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/9.jpg)
Programming with Objects Source Code - NumberDisplay
public class NumberDisplay{ private int limit; private int value;
// Constructor and methods // omitted.}
![Page 10: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/10.jpg)
Programming with Objects Source Code - NumberDisplay
public NumberDisplay(int rollOverLimit){ limit = rollOverLimit; value = 0;}
public int getValue(){ return value;}
![Page 11: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/11.jpg)
Programming with Objects Source Code - NumberDisplay
public String getDisplayValue(){ if(value < 10) { return "0" + value; } else { return "" + value; }}
![Page 12: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/12.jpg)
Programming with Objects Source Code - NumberDisplay
public void setValue(int replacementValue){ if((replacementValue >= 0) && (replacementValue < limit)) { value = replacementValue; }}
![Page 13: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/13.jpg)
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;
![Page 14: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/14.jpg)
Programming with Objects Source Code - NumberDisplay
public void increment(){ value = (value + 1) % limit;}
![Page 15: Programming with Objects Object Interaction (Part 1) Week 9](https://reader035.vdocuments.us/reader035/viewer/2022072010/56649ddb5503460f94ad2424/html5/thumbnails/15.jpg)
Required ReadingObjects First With Java – A Practical Introduction using
BlueJ
Related reading for this lecture• Chapter 3