Jump to content
  • Advertisement
Sign in to follow this  
rubsnick

How would I organize these Vector or Vectors in Java?

This topic is 2844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Long story short. Need to sort these vectors..... something something collection sorts don't work... and only have 5 hours to hand it in.

import java.util.*;
import java.io.*;

public class Project02
{
Vector<Coordinates2D> TwoDim=new Vector<Coordinates2D>();
Vector<Coordinates3D> ThreeDim=new Vector<Coordinates3D>();



int coord;
float x,y,z;

public static void main(String[] args)
{
Project02 proj2=new Project02();
proj2.Scanner();

}

public Project02()
{
}
public void Scanner()
{try
{
File file = new File("entrada.txt") ;
Scanner s = new Scanner(file) ;
while(s.hasNext())
{


int Dim = s.nextInt() ;

Coordinates2D coor= new Coordinates2D(Dim);
Coordinates3D coor3= new Coordinates3D(Dim);
if (Dim==3)
{

{
x=s.nextFloat();
y=s.nextFloat();
z=s.nextFloat();
float sum=coor3.calcABS(x,y,z);
coor3.addCoordinate(sum);
coor3.addCoordinate(x);
coor3.addCoordinate(y);
coor3.addCoordinate(z);

System.out.println("x ="+coor3.getCoordinate(0)+"y="+coor3.getCoordinate(1)+"z="+coor3.getCoordinate(2)+"Sum= "+sum);



}
ThreeDim.add(coor3);

}

else if (Dim==2)
{
x = s.nextFloat() ;
y = s.nextFloat() ;
float sum=coor.calcABS(x,y);
coor.addCoordinate(sum);
coor.addCoordinate(x);
coor.addCoordinate(y);

System.out.println("x ="+coor.getCoordinate(0)+"y="+coor.getCoordinate(1)+"Sum= "+sum);
TwoDim.add(coor);

}
}



s.close() ;
}
catch(FileNotFoundException e)
{
System.out.println("The file entrada.txt could not be found. The application will now exit.") ;
}
catch(Exception e)
{
e.printStackTrace() ;
}


}


class Coordinates2D

{

private int dimension;
private Vector<Float> points;

public Coordinates2D(int dimension)
{
setDimensions(dimension);
points= new Vector<Float>(3,1);
}


public void setDimensions(int id)
{
dimension=id;
}
public int getDimension()
{
return dimension;
}

public void addCoordinate(float coordinate)
{
points.add(coordinate);
}


public float getCoordinate(int index)
{
return points.get(index);
}

public float calcABS(float x, float y)
{
if (x<0)
x=x*-1;
if (y<0)
y=y*-1;
float sum=x+y;
return sum;
}

}


class Coordinates3D

{

private int dimension;
private Vector<Float> points;

public Coordinates3D(int dimension)
{
setDimensions(dimension);
points= new Vector<Float>(4,1);
}


public void setDimensions(int id)
{
dimension=id;
}
public int getDimension()
{
return dimension;
}

public void addCoordinate(float coordinate)
{
points.add(coordinate);
}


public float getCoordinate(int index)
{
return points.get(index);
}

public float calcABS(float x, float y,float z)
{
if (x<0)
x=x*-1;
if (y<0)
y=y*-1;
if (z<0)
z=z*-1;
float sum=x+y+z;
return sum;
}

}

}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!