

































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


































































○ (^) Model Component : One or More Java Classes e.g., Person vs. SMS, Student, CourseRecord ○ (^) Another Java class that “manipulates” the model class (by creating instances and calling methods): ● (^) Controller (e.g., BMIActivity, BankActivity). Effects? Visualized (via a GUI) at connected tablet ● (^) Tester with main (e.g., PersonTester, BankTester). Effects? Seen (as textual outputs) at console
○ We may define more than one classes. ○ Each class may contain more than one methods.
○ (^) Use classes to define templates ○ Use objects to instantiate classes ○ (^) At runtime, create objects and call methods on objects, to simulate interactions between real-life entities.
e.g., People gain/lose weight, marry/divorce, or get older. e.g., Cars move from one point to another. e.g., Clients initiate transactions with banks.
○ (^) Possess attributes; ○ (^) Exhibit bebaviour ; and ○ (^) Interact with each other.
○ (^) Classifying entities of interest Entities in the same class share common attributes and bebaviour. ○ Manipulating data that represent these entities Each entity is represented by specific values.
○ attributes (e.g., age, weight, height) [≈ nouns] ○ (^) behaviour (e.g., get older, gain weight) [≈ verbs]
○ (^) attributes (e.g., x, y) [≈ nouns] ○ (^) behaviour (e.g., move up, get distance from) [≈ verbs]
○ Each point possesses an x-coordinate and a y-coordinate. ○ Each point’s location might be distinct e.g., p1 is located at ( 3 , 4 ) e.g., p2 is located at (− 4 , − 3 )
○ (^) When p1 moves up for 1 unit, it will end up being at ( 3 , 5 ) ○ (^) When p2 moves up for 1 unit, it will end up being at (− 4 , − 2 ) ○ (^) Then, p1’s distance from origin: [
○ (^) Then, p2’s distance from origin: [
public class Person { int age; String nationality; double weight; double height; }
public class Point { double x; double y; }
public class Point {
... /* attributes: x, y */ Point(double newX, double newY) { x = newX; y = newY; } }
public class PointTester { public static void main(String[] args) { Point p1 = new Point (2, 4); println( p1 .x + " " + p1 .y); Point p2 = new Point (-4, -3); 11 of 73^ println( p2 .x^ +^ "^ "^ +^ p2 .y);^ }^ }
public class Person {
... /* attributes: age, nationality, weight, height */ Person(int newAge, String newNationality) { age = newAge; nationality = newNationality; } }
public class PersonTester { public static void main(String[] args) { Person jim = new Person (50, "British"); println( jim .nationlaity + " " + jim .age); Person jonathan = new Person (60, "Canadian"); println( jonathan .nationlaity + " " + jonathan .age); } }
Person jim = new Person(50, "British");
50 “British”
age nationality
Person
weight height
50 “British”
age nationality
Person
jim
weight 14 of 73^ height
Person jim = new Person(50, "British", 80, 1.8);
double bmi = jim.getBMI();
bmi = p.getBMI();
class Point { double x; double y; void moveUp(double units) { y += units; } }
1 Point p1 = new Point(2, 3); 2 Point p2 = new Point(4, 6); 3 p1.moveUp(3.5); 4 p2.moveUp(4.7);
○ p1 and p2 are called the call targets or context objects. ○ (^) Lines 3 and 4 apply the same definition of the moveUp method. ○ (^) But how does Java distinguish the change to p1.y versus the change to p2.y?