java - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

java

Description:

class Point. intiaf41 - class9. 7. 11/1/09. ?????? ??????? ??? Point ... class Circle { ... public double area() { return Math.PI*_radiud*_radius; ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 23
Provided by: csBg
Category:
Tags: class | java

less

Transcript and Presenter's Notes

Title: java


1
???? ????? ????? ? java
  • ????? ????? ????? ??? ?'

2
????? ????? ????? ??? ???
  • ?????? ????, ??????, ????? 3.
  • ????? ???? ????? ?? ????? ????? ,????? - ?????
    ???, ????????.
  • ????? ?????? ????, ?????, ?????, ????? ??????
    ?????? Point, ??????? ??.
  • ???? ????? ??? ????? ???????? ?????? ??????
    ?????.
  • ????? ????, ???? PointContainer

3
????? ????? ????? - ????????
  • ??? ??????? ?? ??? ????, ?? ???? ????.
  • ?????? ?????, ??????? ?????, ??????.
  • ????? ?? ?"??" ??"???".
  • ???? ?????? ??????????? ?????? ???? ????.
  • ????? ?????? ?????, ?????? ?????, ??????, ????..
  • ??????? ?????? ????? ??? ????? ????????.

4
?????? ??????? ??? Point
  • ??? ??? ????? (?????) ????.
  • ???? ?????? ???? ??????, ???? ?????
  • ???? ??????

class Point int _x, _y // data member!!
boolean same(Point p) return (p._x _x
p._y_y) void print() S.O.P.(_x,
_y) // class Point
5
?????? ??????? ??? Point
  • ????? ????? ?????? ?????.
  • ????? ????? , ???? ?? ?????..

class TextPoint public static void
main(String a) Point p1 new Point() //
constructor! Point p2 new Point(p1._x,
p1._y) p1._x 3 p1._y2 p1.print() //
3,2 boolean b p1.same(p2) // true
6
?????? ??????? ??? Point
  • ???? ???? ??????, ?????? ????????.
  • Copy constructor ????? "????"

class Point int _x, _y // data member!!
Point (int x, int y) _xx _yy
Point(Point p) _xp._x _yp._y // class
Point
7
?????? ??????? ??? Point
  • ???? ???? ?? ????? public \ private
  • ?????? ???? ????? ????? ????.

public class Point private int _x, _y //
data member!! public Point (int x, int y)
_xx _yy public int x() return _x
public int y() return _y // class Point
8
?????? ??????? ??? Point
  • ????? ?????? - ???? ??????.

class TextPoint public static void
main(String a) Point p1 new Point(2,3)
//constructor! Point p2 new Point(p1)
p1._x 5 // ERROR (its private).
s.o.p(p1.x()) // o.k. public boolean b
p1.same(p2) // true
9
?????? ??????? ??? Point
  • ????? ?????? ?? ????? ????, ????.
  • ????? ?? ?????? (?????) ?? ?????.
  • ????? ?? ?????.
  • ????? ?????? ?? ????

class Point double distance(Point p)
double dx x()-p.x(), dy _y-p._y //
x() , _x return Math.sqrt(dxdx dydy) //
class Point
10
?????? ????? ??? Circle
  • ?????? ?????? ???? ??????
  • ???? ??
  • ?????? ???, ????, ???? ?????.
  • ???? ?????? String toString()
  • ?????? ?????? ??????? ?? ????????, ????? ????
    ????? ?? ???????? System.out.print ?? ???????.

11
?????? ????? ??? Circle
  • ?????? ?????? ???? ??????
  • ???? ????? ??????.
  • ????, copy constructor.

class Circle private Point _center
private double _radius public Circle(Point
cen, double rad) _center new
Point(cen) _radius rad // copy
constructor
12
?????? ????? ??? Circle
  • ????? ?????
  • ???, ????.
  • toString
  • ??? ????? ?????

class Circle public double area()
return Math.PI_radiud_radius public
String toString() return Circle
cen_center rad _darius public
boolean contains(Point p) // // class
Circle
13
????? ??????? Point, Circle
class TestCP public static void
main(String a) Point p1new
Point(5,6), p2new Point(1,3) double d
p1.distance(p2) // 5.0 Circle c1
new Circle (p1,4) boolean in
c1.contains(p2) // false
14
????? ????? ????? - ????
  • ??? ?????? ??????? ?????.
  • ????? ????, ?????, ?????, ??????.
  • ????? toString(), ????? ?? ?????????.
  • ???? ?? ?????? Point ps new Point4
  • ????? ??? ?????? ??????? ?????? ???
  • (data members)
  • ??? ?? ????? ? java ????? ?? ????? ??? ?????
    (???? ?????? ????? ???? ?????? Jcreator).

15
?????? ??? ???? ????????
  • this ???? ?????, ?????? ????? ???? ?????.
  • ???? ??????? ???? (?? ???????), ?????? ????????
    ????? ????? (????? ?????) ??? ????? ????? ???
    ????? ???? ?? ????????, ????? ?? ???? this.
  • ???? ????? ?? this ?? ??????? ???? ?? ??????.
  • ?????? this ???? ???? ??? ???? ????? ?? ??????
    ???.

16
????? ????????? ??????? this
  • ??? ????? ???? ????? ????????? ????.
  • this ????? ?? ??? ???? ?????? ?? ?????.
  • Point pnew Point(5,6)
  • Circle cnew Circle(p,4)
  • Circle c2

17
???? ?????? ???? ?? ??????
  • ??? ????? ?? ?? ????? ?? ???????
  • ?????? ?? ???? (Container)
  • ????? ?????.
  • ?????, ????? ??????, ????? ????????.
  • ???? ??????, ???? ?????.
  • ?????? ????.
  • ??????.
  • ????.

18
???? ?????? ???? ?? ??????
  • public class PointContainer
  • // data members
  • public static final int INIT_SIZE10 // init
    size.
  • private int _sp0 // stack pointer
  • private Point _points // the point array
  • / Constructors creates a empty set /
  • public PointContainer()
  • _sp0
  • _points new PointINIT_SIZE

19
???? ?????? ???? ?? ??????
  • public int size() return _sp
  • public void add (Point p)
  • if (p ! null)
  • if(_sp_points.length) rescale(10) // RESCALE
  • _points_sp new Point(p) // deep copy
    semantic.
  • _sp
  • public Point at(int p)
  • if (pgt0 pltsize()) return _pointsp
  • return null // no need for else!

20
???? ?????? ???? ?? ??????
  • / private methodes /
  • private void rescale(int t)
  • Point tmp new Point_spt
  • for(int i0ilt_spi) tmpi _pointsi
  • _points tmp

21
???? ?????? ???? ?? ??????
  • ????? ??????
  • ?????? ????.
  • ????? (copy constructor)
  • ????? ?? ???? ?????.
  • ?????? ?????? ?????
  • ?????, (???? ???? ??? ????)
  • ???? ????, (????? ?? ??? ?????? ???????).

22
?? ????? ????
  • ????? ? Object Oriented
  • ??????? (?????? ?????)
  • ?????, ????.
  • ???? ?? ??????
  • ???? ?????? ??????? ???? ?? ????? ?????.
  • ?? ???? ????
  • ??? ??????, ???? ?? ????? ??????.
  • ????? ?? ???????? ???? ?? ??????.
Write a Comment
User Comments (0)
About PowerShow.com