Public Group

# 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.

## 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; } } } 

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×