fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.SimpleDateFormat;
  7.  
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main(String[] args) {
  13. String[] ss = { "(0,\"Cell Phone Plan\", new SimpleDateFormat(\"08/15/2015\"), 85.22, true);",
  14. "(0,\"Car Insurance\", new SimpleDateFormat(\"08/05/2015\"), 45.22, true);" };
  15.  
  16. for (String line : ss) {
  17. // needs
  18. //int cN
  19. int cN;
  20. //String desc
  21. String desc;
  22. //SimpleDateFormat dt
  23. //double amt
  24. double amt;
  25. //boolean repeat
  26. boolean repeat;
  27.  
  28. String array[] = line.split(",");
  29. //produces:
  30. //[0] (0
  31. cN = Integer.parseInt(array[0].substring(1));
  32. //[1] "Cell Phone Plan"
  33. desc = array[1].replaceAll("\"", "");
  34. //[2] new SimpleDateFormat("08/15/2015")
  35. dt = new SimpleDateFormat(array[2].substring(array[2].indexOf("(\"") + 2, array[2].indexOf("\")")));
  36. //[3] 85.22
  37. amt = Double.parseDouble(array[3]);
  38. //[4] true);
  39. repeat = Boolean.parseBoolean(array[4].substring(0,array[4].indexOf(");")));
  40.  
  41. //public Expense (int cN, String desc, SimpleDateFormat dt, double amt, boolean repeat)
  42. System.out.println("public Expense (" + cN + ", " + desc + ", " + dt.toLocalizedPattern() + ", " + amt + ", " + repeat + " );");
  43. }
  44. }
  45.  
  46. }
Success #stdin #stdout 0.14s 321344KB
stdin
Standard input is empty
stdout
public Expense (0, Cell Phone Plan, 08/15/2015, 85.22, false  );
public Expense (0, Car Insurance, 08/05/2015, 45.22, false  );