Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileWriter;
- import java.io.IOException;
- /**
- * @author Manuel Komann & Matthes Elstermann
- * @version 23-Feb-2018
- *
- * Template for exercise trajectory with methods
- *
- */
- public class JavaToMaple{
- //global variables to save the trajectory data
- public static double t [] = new double[150]; //time
- public static double x [] = new double[150]; //x-coordinate
- public static double y [] = new double[150]; //y-coordintate
- //... space for other global variables
- /**
- * Method for printing the global t, x and y- coordinate pairs
- * to the console
- */
- public static void printToConsole(){
- // print t, x and y coordinate pairs
- // from arrays to shell area
- //... to be implemented
- for (int i = 0; i < t.length; i++) {
- System.out.println(t[i] + ", " + x[i] + ", " + y[i]);
- }
- }
- /**
- * Method for calculating the trajectory
- */
- public static void calc(double v0, double t0, double alpha){
- for (int i = 0; i < t.length; i++) {
- t[i] = t0 + i;
- x[i] = v0 * t[i] * Math.cos(alpha);
- y[i] = v0 * t[i] * Math.sin(alpha) - 0.5 * 9.81 * t[i] * t[i];
- }
- }
- public static void main(String[] args){
- if (args.length >= 3) {
- System.out.println(args[0]);
- System.out.println(args[1]);
- System.out.println(args[2]);
- }
- // example for parsing the first input parameter
- // Warning: program will crash if no input parameter is given
- double V0 = Double.parseDouble(args[0]);
- double T0 = Double.parseDouble(args[1]);
- double a = Double.parseDouble(args[2]);
- //...implement further parsing and evaluation of args
- //calling mehtods
- calc(V0, T0, a);
- printToConsole();
- //saving the elements to the maple worksheet
- //uncomment to save to the maple sheet
- //for Praktomat-turn-in this must be commented out
- // (writing files is not allowed in test envoironment)
- // saveMaple("throw");
- }
- /**
- * Method that creates a new Maple-work sheet. (.mw file)
- * This method is complete! The details are not mandatory to be understood.
- *
- * @param title - Name that the new Maple File will get
- */
- public static void saveMaple(String title){
- String plot = "restart; with(plots):A:=<<";
- //try-catch block: not relevant for exam,
- //but the preferred way to handle possible exceptions in JAVA
- //in this case if the computer fails to write a file for some reason
- try{
- //a class of the package IO for writing to text files
- FileWriter w = new FileWriter(title + ".mw");
- int i = 0;
- for(i = 0; i < t.length-1; i++){ plot = plot + x[i] + ",";}
- plot = plot + x[i]+">|<";
- for(i = 0; i < t.length-1; i++){ plot = plot + y[i] + ",";}
- plot = plot + y[i]+">>:";
- plot = plot + "pointplot(A,color=blue,symbol=cross,labels=[distance,hight]);";
- w.append(plot);
- w.flush();
- w.close();
- System.out.println("\nFile saved as " + title);
- }catch(IOException e){e.printStackTrace();}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement