Experiments eight nine experiments

Experiment eight:

Source:

calculating the area of ​​the cone package;

class ABC the extends yuanzhuiti the implements Area, Volume {

Final Double the PI = 3.14;
public Double Volume (Double R & lt, Double H) {
Double V;
V = R & lt * H /. 3;
return V;
}
public Double Area (Double R & lt, Double L ) {
Double A;
A = the PI * R & lt * L + the PI * R & lt * R & lt;
return A;
}
}
public class yuanzhuiti {
public static void main (String [] args) {

ABC A = new new ABC ();
ABC B = ABC new new ();
System.out.println ( "cone area a is:" + a.area (2,. 4));
System.out.println ( "a volume of the cone is:" + a.volume (. 3,. 6));
System.out.println ( "area of the cone B is:" + b.area (. 3,. 6));
System.out.println ( "volume of the cone B is:" + b .volume (. 4,. 8));
System.out.println ( "a larger volume is:" + Math.max (a.area (3 , 6), b.volume (4,8)));
}
}

calculating the area of ​​the cone package;


public interface Area{
public abstract double area(double r,double l);
}

calculating the area of ​​the cone package;

 

public interface Volume {
public abstract double volume(double r,double h);
}

 

result:

Experimental nine:

Source:

package throws an exception;

public class 实验 {
public static void main(String[] args) {
point p=new point(1,3);
point p1=new point(1,2);
point p2=new point(1,1);
rectangle r=new rectangle(p,5,6);
triangle t=new triangle(p,p1,p2);
}

}
class point {
public int x,y;
public point() {}
public point(int x,int y)throws IllegalArgumentException
{
this.x=x;
this.y=y; 

if(x<0||y<0)
throw new IllegalArgumentException("无效参数");
}
}
class rectangle extends point{
public int width,length;
//public point point1(3,6);
public rectangle(point point1,int length,int width)throws IllegalArgumentException
{

this.length=length;
this.width=width;
if(length<0||width<0)
throw new IllegalArgumentException("参数无效");
}

class triangle extends point{
public triangle(point point1,point point2,point point3)throws IllegalArgumentException
{
if(((point1.x-point2.y)-(point2.x-point1.y))+((point2.x-point3.y)-(point3.x-point2.y))+((point3.x-point1.y)-(point3.y-point1.x))==0)
throw new IllegalArgumentException("无效的参数");
}
}

 

The results:

Guess you like

Origin www.cnblogs.com/myb1128/p/10930098.html
Recommended