Untitled
unknown
plain_text
4 years ago
10 kB
2
Indexable
package GivenProblem; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Initializers { public Initializers() { } public static String[] initialObject1() throws IOException { BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\azimismail03\\Desktop\\2DPlane\\src\\GivenProblem\\FileDirectory")); String line = br.readLine(); String[] lines = line.split(","); return lines; } public static String[] initialObject2() throws IOException { BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\azimismail03\\Desktop\\2DPlane\\src\\GivenProblem\\FileDirectory")); br.readLine(); String line = br.readLine(); String lines[] = line.split(","); return lines; } // --------------------------------------- Initializes Object 1 -------------------------------------------------------- //Gets Mass public double getMass1() throws IOException { String [] obj = initialObject1(); String mass = obj[0]; return Double.parseDouble(mass); } //Gets Position public double getPosition1()throws IOException{ String [] obj = initialObject1(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(1)); } String position = p.get(0); return Double.parseDouble(position); } //Get X Direction public String getPXDir1()throws IOException{ String [] obj = initialObject1(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(2)); } return p.get(0); } //Get position Angle public double getPAngle1() throws IOException{ String [] obj = initialObject1(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(3)); } String angle = p.get(0); return Double.parseDouble(angle); } //gets Y Direction public String getPYDir1() throws IOException{ String [] obj = initialObject1(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(4)); } return p.get(0); } // Get Velocity 1 public double getVelocity1() throws IOException{ String [] obj = initialObject1(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(1)); } String velocity = p.get(0); return Double.parseDouble(velocity); } // gets X Direction for Velocity public String getVXDir1() throws IOException{ String [] obj = initialObject1(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(2)); } return p.get(0); } // gets Angle public double getVAngle1() throws IOException{ String [] obj = initialObject1(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(3)); } String angle = p.get(0); return Double.parseDouble(angle); } // Gets Y direction for velocity public String getVYDir1() throws IOException{ String [] obj = initialObject1(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(4)); } return p.get(0); } // Setting each object x and y coordinates public double objPositionX1() throws IOException{ formula formula = new formula(); return formula.xCoord(getPosition1(), getPAngle1(), getPXDir1()); } public double objPositionY1() throws IOException{ formula formula = new formula(); return formula.yCoord(getPosition1(), getPAngle1(), getPYDir1()); } public double objVelocityX1() throws IOException{ formula formula = new formula(); return formula.xCoord(getVelocity1(), getVAngle1(), getVXDir1()); } public double objVelocityY1() throws IOException{ formula formula = new formula(); return formula.yCoord(getVelocity1(), getVAngle1(), getVYDir1()); } //----------------------------------------Initialize Object 2------------------------------------------------------------ //Gets Mass public double getMass2() throws IOException { String [] obj = initialObject2(); String mass = obj[0]; return Double.parseDouble(mass); } //Gets Position public double getPosition2()throws IOException{ String [] obj = initialObject2(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(1)); } String position = p.get(0); return Double.parseDouble(position); } //Get X Direction public String getPXDir2()throws IOException{ String [] obj = initialObject2(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(2)); } return p.get(0); } //Get position Angle public double getPAngle2() throws IOException{ String [] obj = initialObject2(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(3)); } String angle = p.get(0); return Double.parseDouble(angle); } //gets Y Direction public String getPYDir2() throws IOException{ String [] obj = initialObject2(); String line = obj[1]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(4)); } return p.get(0); } // Get Velocity 1 public double getVelocity2() throws IOException{ String [] obj = initialObject2(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(1)); } String velocity = p.get(0); return Double.parseDouble(velocity); } // gets X Direction for Velocity public String getVXDir2() throws IOException{ String [] obj = initialObject2(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(2)); } return p.get(0); } // gets Angle public double getVAngle2() throws IOException{ String [] obj = initialObject2(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(3)); } String angle = p.get(0); return Double.parseDouble(angle); } // Gets Y direction for velocity public String getVYDir2() throws IOException{ String [] obj = initialObject2(); String line = obj[2]; ArrayList<String> p = new ArrayList<>(); Pattern pattern = Pattern.compile("\\s(\\d*.?\\d+)\\[(N|S)(\\d*.?\\d+)(E|W)\\]"); Matcher matcher = pattern.matcher(line); while(matcher.find()){ p.add(matcher.group(4)); } return p.get(0); } public double objPositionX2() throws IOException{ formula formula = new formula(); return formula.xCoord(getPosition2(), getPAngle2(), getPXDir2()); } public double objPositionY2() throws IOException{ formula formula = new formula(); return formula.yCoord(getPosition2(), getPAngle2(), getPYDir2()); } public double objVelocityX2() throws IOException{ formula formula = new formula(); return formula.xCoord(getVelocity2(), getVAngle2(), getVXDir2()); } public double objVelocityY2() throws IOException{ formula formula = new formula(); return formula.yCoord(getVelocity2(), getVAngle2(), getVYDir2()); } }
Editor is loading...