Title: java
1???? ?????? ? java
- ????? ????? ????? ????? 3
- ??????, ????, ???? ??????
2????? ????? ????? ??? ???
- ????? ?? ?????? ?????? PointContainer
- ?????? ????? ????, ????, ???? ????
- ???? ????, Object
- ???? ??????
- ???? ????????? ??????.
3????? ????? ????? - ????????
- ?????? ?????, ??????? ?????, ??????.
- ????? ?? ?"??" ??"???".
- ???? ?????? ??????????? ?????? ???? ????.
- ???? ???? (vector)
- ?????????? ?? ???? ?????, ????...
4???? ?? ?????? ?????
- ????? ?? ????? (?????).
- ?????, ?????, ????, ??????.
public class Point private double _x, _y
public Point (double x1, double y1)
_x x1 _y y1 public double
distance(Point p) double dx
x()-p.x(), dy _y-p._y // x() , _x
return Math.sqrt(dxdx dydy)
5????? ????????? ??????? this
- ??? ????? ???? ????? ????????? ????.
- this ????? ?? ??? ???? ?????? ?? ?????.
- Point pnew Point(5,6)
- Circle cnew Circle(p,4)
- Circle c2
6????? ????? ??????
- ???? ?????? ?? ???????
- ????? ?? ???? ?.?., ?? , ???? ?? ??????.
public class Student private String _name
private long _id private int _grades
public Student(long id, String name) _name
new String(name) // copy. _id id
_grades new int5 // .
7????? ????? ??????
- ???? ???? ???????? , ???? ??????
- ???? ???? ????.
- ???? ?????, ????.
public class Student private int
_grades public void updateGrade(int ind, int
grade) ... public int gradeAt(int ind)
public int finalGrade()
8????? ????? ????? - ????
- ????? ??????
- ????, ?????, ?????, ??????.
- ????? ?????? ??????, toString().
- ???? ?? ????????
- ????? ????? ?? ??????.
- ???? ????? ????? ?? ?? ?????? ??? (?????)
- ????? ??????, ???? ????????.
9????? ?????? StudentContainer
class TestStudent public static void
main(String a) Student s1 new
Student(123456789, Dan) /// Student s10
new Student(55555555, Noam) StudentContain
er st new StudentContainer() st.add(s1)
st.add(s10) S.o.p(st.search(555555555))
10???? ???? ???????? 1
- ?????? ????? ??? ????? ?? ?????? ShapeContainer
- ??? ????? ???? ?? ?????????
- ?????, ????, ??????
11???? ???? ???????? 1
public class StudentContainer1 // data
members public static final int
INIT_SIZE10 // the first (init) size. public
static final int RESCALE10 // the re-scale
factor private int _sp0 private Student
_students / Constructors creates a empty
set / public StudentContainer1() _sp0 _
students new StudentINIT_SIZE
12???? ???? ???????? 1
/ this method returns a list of all the
Students / public String toString() String
ans "StudentContainer1 "size()"\n" for(
int i0 iltthis.size()ii1) ans (i1)")
"at(i)"\n" return ans
13???? ???? ???????? 1
14???? ???? ???????? 2
- ???? ????? ??? ???? ?? ???????? ?????? ????
- ????? (??? ?????? ??????) ?????, ?????..
- ???? ???? ??? ???????? ??? (?????)?
15???? ???? ???????? 2
16???? ???? ???????? 2
public class StudentContainer2 // data
members StudentContainer1 _sc /
Constructors creates a empty set / public
StudentContainer2() _sc new
StudentContainer1() / returns the actual
amount of Student in this set / public int
size() return _sc.size() //
17???? ???? ???????? 2
- / search and return the first Student that
equals to s/ - public Student search(Student s)
- Student ans null
- for(int i0s!null ansnull
iltthis.size()ii1) - if(s.equals(at(i))) ans new Student(s)
- return ans
-
- / returns true iff s is already a member of
this set. / - public boolean member(Student s)
- return this.search(s)!null
- ??? ????? ?? add ???
18???? ???? ???????? 3
- ?????? ??? ????? ????
- ????? ?????? ?????.
- ???? ??? ??? ???? ?"? ?????????.
- class Student //
- public boolean equals(Student other)
- return other!null this.getID()
other.getID() - public boolean smaller(Student other)
- return othernull this.getID() lt
other.getID()
19???? ???? ???????? 3
public class StudentContainer3 // data
members StudentContainer1 _sc
public Student search(Student s) return
at(find(s)) public Student search(long
id) return search(new Student(id,"Dammi")
)
20???? ???? ???????? 3
public boolean member(Student s) return
this.search(s)!null / add a Student to
this set! / public void add (Student
p) if(p!null !this.member(p))
_sc.add(p) sort() else
System.out.println(" ERR can not add "p" to
the set! ")
21???? ???? ???????? 3
private void sort() for(int
i0iltsize()-1ii1) for(int
j0jltsize()-1jj1)
if(at(j1).smaller(at(j))) Student
tmp at(j1) _sc.update(at(j),j1) _sc.upda
te(tmp, j)
22???? ???? ???? - Collection
- ??? ?????
- ?????? ?? ???? ????
- ????? ?????.
- ?????, ????? ??????, ????? ????????.
- ???? ??????, ???? ?????.
- ?????? ????.
- ??????.
- ????? ????? ????
23???? ???? ???? - Collection
- ?????? ?????
- ???? ????? ????? ????????? ???????? ?????.
- ???? ???? ?? ????? ????? ????? ????, ??????.
- ???? ?????? Object
- ????? ???? ????? ?? ????? ???? ? java
- ????? ???? ???? ????? ??? ?? ???????.
24Object ??? (????????) ????????
- ?? ???????? ??? ??????? ?????? ? Object
- ???? ????? ???? Object arr new Object5
- ???? ?????? ?? ????? ?? ????? (?????? ??????? ..)
- ? Object ???? ????? ???? toString()
- ????? ?????? ?? ?????? Object (java api)
25???? ???? ???? - Collection
- ????? ?????? Object ??? ?????? ???? ????
(vector) - ?????
- ?????
- ?????
- ????
- ????? ????? ???????, ????????? \ ????
26???? ???? ???? - Collection
public class MyVector // data members
public static final int INIT_SIZE10,
RESCALE10 private int _sp0 private
Object _objs / Constructors creates a
empty set / public MyVector() _sp0 _obj
s new ObjectINIT_SIZE
27???? ???? ???? - Collection
public int size() return _sp public void add
(Object p) if (p ! null) if(_sp_objs.len
gth) rescale(RESCALE) _objs_sp p //
reference copy semantic. _sp1 public
Object at(int p) return _objsp // ?????!!
28????? ??????? ?? ???????
- ??? ?????? ???? ????? ??? ??????? ???? ?????.
- ??? ?????? ??? ??? ?????? ????? ???? ??? ?????
?? ??????.
29?????? ??? ???? ????????
- ???? ????? ?? ??????? ?????? ?????!
- ???? ??????? ???? (?? ???????), ?????? ????????
????? ????? (????? ?????) ??? ????? ????? ???
????? ???? ?? ????????, ????? ?? ???? this. - ??????? ????? ???? ?????? ?? ?? ??????? (???? ???
???? ????? ?? this).
30???? ????????? ??????
- ???? ????? ????? ?????? ?? ??????? (????? ??
this). - ???? ?????? ????? ??????? ???? ?????? ???? ???.
- ???? ??? ??? ???? ??? ???????? ????? ??????
??????? - ???? ???? ???? ????? ?????? ??? ??????? ??? ????
???? ???? ???? ?????? (?? ??????? ???? ????
?????? ????). - ??????? ????? ???? ????? ?? this ???? ?????
????? ?? ?? ???? ???? ?? ??????.
31???? ????????? ?????? - ?????
- public class Shape
- private static int _counter 0
- private int _color
- public Shape(int c)
- this._color c
- _counter
-
- public static int instances() return _counter
32?? ????? ????
- ????? ? Object Oriented ??????
- ??????,
- ???? ???????? ????, ?????, ????.
- ???? ???? Object
- ????? ???? ????? (???)
- ???? ????????? ??????.