JAVA´úÂ루ÃæÏò¶ÔÏó³ÌÐòÉè¼Æ£© ÏÂÔر¾ÎÄ

}

this.y = y; this.r = r; }

public double GetPerimeter() { double perimeter = 0; perimeter = 2 * r * 3.14; return perimeter; }

public double GetArea() { double area = 0; area = 3.14 * r * r; return area; }

public boolean Inside(double x1, double y1) { boolean b; double d; d = (x1 - this.x) * (x1 - this.x) + (y1 - this.y) * (y1 - this.y); b = (d > r * r) ? false : true; return b; }

Rect£¨¾ØÐΣ©£º

//define a class for Rectangles public class Rect extends Shape{

double x1,y1,x2,y2; // left lower angle and right upper angle point define the location double width,length;

public Rect (double x1, double y1, double x2, double y2) { this.x1=x1; this.y1=y1; this.x2=x2; this.y2=y2; length = this.x2-this.x1; width = this.y2-this.y1; //ûÓзÖÇé¿öÌÖÂÛ£¬Ä¬ÈÏÓÒÉϽǵĵãµÄ×ø±ê´óÓÚ×óϽǵÄ×ø±ê }

public double GetPerimeter() { double perimeter=0; perimeter = (length+width)*2;

return perimeter; }

public double GetArea() { double area=0; area=length*width; return area; }

public Rect MergeRect(Rect r1) { double u1,v1,u2,v2; u1 = (r1.x1this.x2) ? r1.x2 : this.x2; v2 = (r1.y2>this.y2) ? r1.y2 : this.y2; Rect r2=new Rect(u1,v1,u2,v2); return r2; }

public boolean Inside(double x1, double y1) { boolean b=(x1>=this.x1)&&(x1<=this.x2)&&(y1>=this.y1)&&(y1<=this.y2); return b; } }

Test£¨²âÊÔÀࣩ£º

public class RectCircleTest {

public static void main(String[] args) { Rect r1=null, r2=null; Circle o1=null,o2=null; //µ÷Óù¹Ô캯ÊýÏÈ´´½¨Á½¸ö¾ØÐκÍÁ½¸öÔ²ÐζÔÏó r1=new Rect(1,1,10,10); r2=new Rect(5,5,20,20); o1=new Circle(3,3,1); o2=new Circle(5,5,2);

int end=r1.compareArea(r2); end=r1.compareArea(o1); end=o2.comparePeri(r1);

} }

4.¶©µ¥

Goods£¨ÉÌÆ·Àࣩ£º

public class Goods { String num; String name; float price; Goods(String num,String name,float price){ this.num=num; this.name=name; this.price=price; } public String toString(){ String s; s=num+\ µ¥¼Û£º\Ôª \ return s; } }

¶©µ¥ÀࣨOrder£©£º

public class Order { //String no; double TotalPrice; OrderItem item1,item2,item3; Order(OrderItem item1,OrderItem item2,OrderItem item3){ this.item1=item1; this.item2=item2; this.item3=item3; TotalPrice(); } private double TotalPrice(){ TotalPrice=item1.price+item2.price+item3.price; return TotalPrice; } void show(){ String s=\ s=item1.toString()+\×ܼ۸ñΪ£º\Ôª\

System.out.println(s); } }

¶©µ¥ÏîÀࣨOrderItem£©£º

public class OrderItem { Goods g; int num; double price; OrderItem(Goods g, int num){ this.g=g; this.num=num; price(); } private double price(){ price=g.price*num; if(price>=100) price-=20; return price; } public String toString(){ String s; s=g.toString()+\ ¹²\¼þ\×ܼÛΪ£º\Ôª\ return s; } }

Óû§ÀࣨUser£©£º

public class User { String name; Order o;

User(String name, Order o) { this.name=name; this.o=o;

} import java.util.Scanner; ¹ºÂò£¨MakeOrder£©£º

public class MakeOrder { public static void main(String[] args) { // TODO Auto-generated method stub Goods good1=new Goods(\¹û¹ûÀ´À² ÄϳäÌزú ´à´àÏãÌá×Ó\

Goods good2=new Goods(\¹û¹ûÀ´À² ÎÂÜ°Ôç²Í °ü×ÓºÍÌðÖà\

Goods good3=new Goods(\ËÉÊóÖ®¼Ò ÖǻۼÒÍ¥ ºìħ·½±ùÏä