Newbie code help~ about FILE IO

H

Herrcho

this is about my Homework , and i've wrote the code below and it runs
well

but i'd really appreciate it if anyone could correct it. especially

about Stream IO.

// Add the member method isParallel(Vector2D v) to the Vector2D class
to test whether a vector v is parallel to the host vector. Given any
four points, use Vector2D objects to determine whether they form a
parallelogram //

import java.io.*;

class Vector2D
{
private float x;
private float y;

static private float a;
static private float b;

public Vector2D(float x, float y)
{
this.x = x;
this.y = y;
}
public Vector2D o_vec(Vector2D a) //
{
return new Vector2D(a.x-x, a.y-y);
}

public boolean isParallel(Vector2D v)
{
if (x*v.x == 0){
if (x+ v.x == 0) return true;
else return false;
}

else if (y*v.y == 0){
if (y+v.y == 0) return true;
else return false;
}

else if (v.x%x == 0 && v.y%y == 0) return true;

else return false;

}

public String toString()
{
return ("("+x+","+y+")" );
}

public static Vector2D getPoint()
{
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
try{

a = Float.parseFloat(in.readLine());
b = Float.parseFloat(in.readLine());

return new Vector2D(a,b);

}
catch(IOException ex)
{
ex.printStackTrace();
return new Vector2D(a,b);
}

}
}
class jdriver
{

public static void main(String[] args)
{
Vector2D[] point = new Vector2D[4];
for (int i=0 ; i<4; i++)
{
point = Vector2D.getPoint();
}

System.out.println(point[0]+" "+point[1]+" "+point[2]+"
"+point[3]+" ");


Vector2D k01 = point[0].o_vec(point[1]);
Vector2D k02 = point[0].o_vec(point[2]);
Vector2D k03 = point[0].o_vec(point[3]);
Vector2D k12 = point[1].o_vec(point[2]);
Vector2D k13 = point[1].o_vec(point[3]);
Vector2D k23 = point[2].o_vec(point[3]);

if (k01.isParallel(k23))
{
if (k03.isParallel(k12) || k02.isParallel(k13))
System.out.println("Parallelogram");
}

else if (k03.isParallel(k12))
{
if (k02.isParallel(k13) || k01.isParallel(k23))
System.out.println("Parallelogram");
}

else System.out.println("is not Parallelogram");

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top