Advertisement
Guest User

Untitled

a guest
Dec 10th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1.  
  2. public class SensorInfo
  3. {
  4. private String type;
  5. private String date;
  6. private String time;
  7. private String reading;
  8.  
  9. public SensorInfo(String sensor, String date, String time, String reading)
  10. {
  11. this.type = sensor;
  12. this.date = date;
  13. this.time = time;
  14. this.reading = reading;
  15. }
  16.  
  17. public String getType()
  18. {
  19. return type;
  20. }
  21.  
  22. public SensorInfo(String... parms)
  23. {
  24. this(parms[0], parms[1], parms[2], parms[3]);
  25. }
  26.  
  27. public SensorInfo(String data)
  28. {
  29. this(data.replace("\n", "").replace(" ", "").split(","));
  30. }
  31.  
  32. public String asData()
  33. {
  34. return type + "," + date + "," + time + "," + reading + "\n";
  35. }
  36.  
  37. public String display()
  38. {
  39. return width(type, 14) + width(date, 14) + width(time, 10) + width(reading, 7) + "\n";
  40. }
  41.  
  42. public static String header()
  43. {
  44. return ("-------------------------------------------\n Sensor Date Time Reading \n-------------------------------------------");
  45. }
  46.  
  47. /**
  48. * Pads out or chops the value to a given size for keeping columns neat
  49. * @param value
  50. * @param n
  51. * @return
  52. */
  53. private static String width(String value, int n)
  54. {
  55. return (value + " ").substring(0, n);
  56. }
  57.  
  58. public String getDateAndTime()
  59. {
  60. return date + " " + time;
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement