Docsity

Notes on Object Chart, Data and Methods | IT 108, Study notes of Information Technology

Toggle sidebar
bg1
April 2, 2009
O-O solution
1. What is the problem?
2. What is the Object?
3. Object Chart
a. Data?
i. Will be unique for each object
1. Instance variable
b. Methods
i. Access
ii. Mutator
iii. Constructor
iv. Special purpose
v. Special Purpose
1. Operation instance data
public class Team {
Team
getNames()
getWon()
getLost()
setNames()
setWon()
setLost()
stats()
Info out
return value
access(get)
Information in
parameter
Muatator(set))
Soccer.java
I|P|O
Data in one object classdefination
Procedural
(implementation)
Soccer League
Name
Won
Lost
Team.java
Input info
Soccer
Input info
done
Output name and
stats
Input teamName
Input into Object
Access from
object
Create object
pf3

Partial preview of the text

Download Notes on Object Chart, Data and Methods | IT 108 and more Study notes Information Technology in PDF only on Docsity!

O-O solution

  1. What is the problem?
  2. What is the Object?
  3. Object Chart a. Data? i. Will be unique for each object 1. Instance variable b. Methods i. Access ii. Mutator iii. Constructor iv. Special purpose v. Special Purpose
  4. Operation instance data public class Team { Team getNames() getWon() getLost() setNames() setWon() setLost() stats() Info out return value access(get) Information in parameter Muatator(set)) Soccer.java I|P|O Data in one object  classdefination Procedural (implementation) Soccer League Name Won Lost Team.java Input info Soccer Input info (^) done Output name and stats Input teamName Input into Object Access from object Create object

private String name; private int won; private int lost; public String () { return name; } public int getWon () {return won; } public int getLost () {return lost; } public void setName(String n) { name = n; } public void setWon (int w) {won = w; } public void setLost (int l) {lost = l; } Public int stats() {return 100 * won / (won + lost); } } Public class soccer { Public static void main (String [] args) { Team myTeam = newTeam ( ); Team another = newTeam ( ); teamName = JOptionPane.ShowInputDialog(“Name:”)

myTeam.setName(teamName);

another.setName(JOptionsPane.ShowInputDialog(“Name:”)); . Mistake!: public void setName(String name) {name = name; }

- Problem is one variable is **representing for two things

  • Same name cant do both
  • Local over rides it (you get a** team without a name) Creates: myTeam Name Won Lost getName getWon getLost stats setLost setWon Teamname “Falcons” Creates: myTeam Name Won Lost getName getLost getWon stats setLost setWon