import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; interface Plottable { double function(double x); double getA(); double getB(); } class Plott implements Plottable { private double a; private double b; @Override public double function(double x) { // TODO Auto-generated method stub return (x*x)+5; } //GEt and Set A public void setA(double a){ this.a=a; } @Override public double getA() { return a; } //Get and Set B public void setB(double b){ this.b=b; } @Override public double getB() { // TODO Auto-generated method stub return b; } } class Hauptroutine { public static void main(String[]args) { Plott Gnuplot = new Plott(); System.out.println("Geben sie die Intervallgrenzen a und b ein!"); Gnuplot.setA( Input.in.readDouble()); Gnuplot.setB(Input.in.readDouble()); System.out.println("Geben sie die Zahl der Intervalle n ein (positive ganze Zahl!)"); int n = Input.in.readInteger(); System.out.println("Unter welchem Dateinamen wollen sie die Daten speichern?"); String filename = Input.in.readString(); createData(filename,Gnuplot,n); } public static void createData(String filename,Plottable p,int n) { double aktuell = p.getA(); double schrittweite = (p.getA()+p.getB())/n; try { File f = new File("/home/mosfet/eclipse/workspace/Aufgabe40/src/"+ filename + ".data"); if(!f.canWrite() || !f.createNewFile()) { System.out.println("Kann Datei nicht schreiben!"); System.exit(1); } else { while(aktuell != p.getB()) { DataOutputStream out = new DataOutputStream(new FileOutputStream(f)); PrintStream s = new PrintStream(out); s.println(aktuell+ " " + p.function(aktuell)); s.close(); aktuell = aktuell + schrittweite ; }//Ende while } }//Ende Try catch(IOException e) { System.out.println(e);} }//Ende create Data }//Ende Klasse