Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class ccc1 {
  5.  
  6. /**
  7. * @param args
  8. */
  9. public static void main(String[] args) {
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. float distance = -1;
  13. float speed = 0.0f;
  14.  
  15. //Speedlimits
  16. float currentlimit = 1000.0f;
  17. float distanceToNextLimit = 1000.0f;
  18. float nextlimit = 1000.0f;
  19.  
  20. float simulationStep = 1/60.0f;
  21. float brake = -21.0f;
  22.  
  23. while(scan.hasNextLine()) {
  24. String s = scan.nextLine();
  25. if(s.contains("distance")) {
  26. distance = Float.parseFloat(s.substring(9));
  27. }
  28. if(s.contains("speed")) {
  29.  
  30. System.out.println(s.substring(6));
  31.  
  32. }
  33. if(s.contains("speedlimit")) {
  34. String split[] = s.split(" ");
  35. currentlimit = Float.parseFloat(split[1]);
  36. distanceToNextLimit = Float.parseFloat(split[2]);
  37. nextlimit = Float.parseFloat(split[3]);
  38. }
  39. if(s.contains("update")) {
  40. if(distance < 1500) {
  41. float deltaSpeed = speed - nextlimit;
  42. double brakeWay = Math.pow(deltaSpeed, 2) / 2 * 5.8f;
  43.  
  44. if(brakeWay >= distanceToNextLimit) {
  45. System.out.println("throttle 0");
  46. System.out.println("brake 100");
  47. } else {
  48. if(speed < currentlimit) {
  49. System.out.println("throttle 100");
  50. System.out.println("brake 0");
  51. } else {
  52. System.out.println("throttle 0");
  53. System.out.println("brake 0");
  54. }
  55. }
  56.  
  57. } else {
  58. System.out.println("throttle 0");
  59. System.out.println("brake 100");
  60. }
  61. }
  62.  
  63. }
  64.  
  65.  
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement