2013年9月12日 星期四

【職訓局-手機程式開發班】2013 9/11 java

CLASS ex1:
class aa{
public int x, y;
public bb b;

aa(int x, int y){
this.x = x;
this.y = y;
b = new bb(this.x, this.y);
}

public String area(){
return  "x:" + this.x + ",y:" + this.y + ",面積為:" + b.area();
}

public String perimeter(){
return "x:" + this.x + ",y:" + this.y + ",邊長為:" + b.perimeter();
}

}

class bb{
public int x, y;
public cc c;

bb(int x, int y){
this.x = x;
this.y = y;
c = new cc(this.x, this.y);
}

public int area(){
return this.x * this.y;
}

public int perimeter(){
return c.perimeter();
}
}

class cc{
public int x, y;

cc(int x, int y){
this.x = x;
this.y = y;
}

public int perimeter(){
return 2 * (this.x + this.y);
}
}


public class test01 {

public static void main(String[] args) {
aa a = new aa(10,20);
a.b.x = 100;
System.out.println(a.area());
a.b.c.x = 1000;
System.out.println(a.perimeter());
}

}
CLASS ex2:
package ch09;

class aa{
public int x, y;
public bb b;

aa(int x, int y){
this.x = x;
this.y = y;
b = new bb(this.x, this.y);
}

public String area(){
return  "x:" + this.x + ",y:" + this.y + ",面積為:" + b.area();
}

public String perimeter(){
return "x:" + this.x + ",y:" + this.y + ",邊長為:" + b.perimeter();
}

}

class bb{
public int x, y;
public cc c;

bb(int x, int y){
this.x = x;
this.y = y;
c = new cc(this.x, this.y);
}

public int area(){
return this.x * this.y;
}

public int perimeter(){
return c.perimeter();
}
}

class cc{
public int x, y;

cc(int x, int y){
this.x = x;
this.y = y;
}

public int perimeter(){
return 2 * (this.x + this.y);
}
}


public class test01 {

public static void main(String[] args) {
aa a = new aa(10,20);
a.b.x = 100;
System.out.println(a.area());
a.b.c.x = 1000;
System.out.println(a.perimeter());
}


}