Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

okay, this is a method that reads data from a file (point x, point y, speed, nam

ID: 3696821 • Letter: O

Question

okay, this is a method that reads data from a file (point x, point y, speed, name of point) however I have to extend Point2D.Double as requisite. The problem its that when I read from the file it returns String values and the class only takes double type in the first 3 variables. So I can't use Double.parseDouble() becasue I'm extending Point2D.Double (it does not let me). is there any way that tose values that I'm getting from the file can be received as double?

public static void readFile(){
       try {                      
           while((line = bufferedReader.readLine()) != null){
               StringTokenizer tk = new StringTokenizer(line);              
               f = new RouteApp((double) tk.nextElement().toString(),(double) tk.nextElement(),(double) tk.nextElement(),tk.nextToken());//can't transform String object to double
               waypointArray.add(f);
           }
       } catch (IOException e) {
           System.out.println("Error reading the file");
       }
   }

Explanation / Answer

Answer:

Hi, You can try like ths.

public static void readFile(){
       try {                      
           while((line = bufferedReader.readLine()) != null){
               StringTokenizer tk = new StringTokenizer(line);              
   f = new RouteApp(Double.parseDouble(tk.nextElement().toString()),Double.parseDouble(tk.nextElement().toString()),Double.parseDouble(tk.nextElement().toString()),tk.nextToken());//can't transform String object to double

                 waypointArray.add(f);
           }
       } catch (IOException e) {
           System.out.println("Error reading the file");
       }
   }