Algs4-1.2(非习题)几何对象中的一个2D用例
1.2节(非习题)几何对象中的一个2D用例
public class Test
{
public static void main(String[] args)
{
double xlo=Double.parseDouble(args[0]);
double xhi=Double.parseDouble(args[1]);
double ylo=Double.parseDouble(args[2]);
double yhi=Double.parseDouble(args[3]);
int T=Integer.parseInt(args[4]);
Interval1D xinterval=new Interval1D(xlo,xhi);
Interval1D yinterval=new Interval1D(ylo,yhi);
Interval2D box=new Interval2D(xinterval,yinterval);
box.draw();
Counter c=new Counter("hits");
for(int t=0;t<T;t++)
{
double x=Math.random();
double y=Math.random();
Point2D p=new Point2D(x,y);
if (box.contains(p)) c.increment();
else p.draw();
}
StdOut.println(c);
StdOut.println(box.area());
}
}
public class Test
{
public static void main(String[] args)
{
double xlo=Double.parseDouble(args[0]);
double xhi=Double.parseDouble(args[1]);
double ylo=Double.parseDouble(args[2]);
double yhi=Double.parseDouble(args[3]);
int T=Integer.parseInt(args[4]);
Interval1D xinterval=new Interval1D(xlo,xhi);
Interval1D yinterval=new Interval1D(ylo,yhi);
Interval2D box=new Interval2D(xinterval,yinterval);
box.draw();
Counter c=new Counter("hits");
for(int t=0;t<T;t++)
{
double x=Math.random();
double y=Math.random();
Point2D p=new Point2D(x,y);
if (box.contains(p)) c.increment();
else p.draw();
}
StdOut.println(c);
StdOut.println(box.area());
}
}