Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7.  
  8. /**
  9. *
  10. * @author s162556
  11. */
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import java.util.*;
  15. import javax.swing.*;
  16.  
  17. public class TollGates {
  18.  
  19. JFrame frame = new JFrame("Graph");
  20. JPanel panel = new JPanel();
  21. JPanel titel = new JPanel();
  22.  
  23. Color gray = new Color(230, 230, 230); //Black colour for black background. Blackground XD
  24. Color red = new Color(255, 0, 0); //White colour
  25.  
  26. double maintenancePerTollgatePerYear = 1200.0;
  27. double employerCostsPerYear = 60000.0;
  28. double placingCostsTollgate = 150000.0;
  29. double maintenancePerRoadPerYear = 140.0;
  30. double placingCostsRoad = 50000.0;
  31. double startSpeed = 100.0;
  32. double roadTime = 10.0;
  33. double acceleration = 2.8;
  34. double pricePerCar = 5.0;
  35. double pricePerMotor = 2.5;
  36. double pricePerTruck = 25.0;
  37. double vehiclesPerHour = 2755.0;
  38. double waitingTime = 10.0;
  39.  
  40. double maxMoney = -1E10;
  41. double minMoney = 0;
  42. double maxWaiting = 0;
  43.  
  44.  
  45. double getMoney(int normal, int ttag) {
  46. double vehiclesPerYear = vehiclesPerHour * 24.0 * 365.0;
  47. double carsPerYear = vehiclesPerYear * (110.0 / 124.0);
  48. double motorsPerYear = vehiclesPerYear * (1.0 / 124.0);
  49. double trucksPerYear = vehiclesPerYear * (13.0 / 124.0);
  50.  
  51. double incomeAfter15Years = 15.0 * ((carsPerYear * pricePerCar) + (motorsPerYear * pricePerMotor) + (trucksPerYear * pricePerTruck));
  52. double roadTimeSquared = Math.pow(roadTime, 2.0);
  53. double amountOfRoadPerTollgate = 2.0 *(startSpeed * roadTime + 0.5 * acceleration * roadTimeSquared);
  54.  
  55. double costsPerRoadAfter15Years = amountOfRoadPerTollgate * (15.0 * maintenancePerRoadPerYear + placingCostsRoad);
  56. double costsPerTollgateAfter15Years = 15.0 * (maintenancePerTollgatePerYear + employerCostsPerYear) + placingCostsTollgate;
  57.  
  58. double costsPerUnitAfter15Years = costsPerTollgateAfter15Years + costsPerRoadAfter15Years;
  59. double amountOfUnits = normal + ttag;
  60. double costsAfter15Years = amountOfUnits * costsPerUnitAfter15Years;
  61.  
  62. double nettoCostsAfter15Years = (costsAfter15Years - incomeAfter15Years); //incomeAfter15Years);
  63. return nettoCostsAfter15Years;
  64. }
  65.  
  66. double getWaiting(int normal, int ttag) {
  67. double THIRD = (1.0/3.0);
  68. //System.out.println(THIRD);
  69. double normalUserLeavingPerHour = normal * (3600.0 / waitingTime);
  70. //System.out.println(normalUserLeavingPerHour);
  71. double normalUserArrivingPerHour = vehiclesPerHour * THIRD;
  72. //System.out.println(normalUserArrivingPerHour);
  73. double tTagUserArrivingPerHour = vehiclesPerHour * 2.0 * THIRD;
  74. //System.out.println(tTagUserArrivingPerHour);
  75. double tTagUserLeavingPerHour = ttag * (3600.0 / 2.0);
  76. //System.out.println(tTagUserLeavingPerHour);
  77. double tTagUsersWaitingAfter24h = Math.max(24.0 * (tTagUserArrivingPerHour - tTagUserLeavingPerHour), 0);
  78. //System.out.println(tTagUsersWaitingAfter24h);
  79. double normalUsersWaitingAfter24h = Math.max(0, 24.0 * (normalUserArrivingPerHour - normalUserLeavingPerHour));
  80. //System.out.println(normalUsersWaitingAfter24h);
  81. double amountOfWaitingVehiclesAfter24h = tTagUsersWaitingAfter24h + normalUsersWaitingAfter24h;
  82. if (amountOfWaitingVehiclesAfter24h < 0) {
  83. amountOfWaitingVehiclesAfter24h = 0;
  84. }
  85. return amountOfWaitingVehiclesAfter24h;
  86. }
  87.  
  88. void run() {
  89.  
  90. frame.setSize(1000, 1000);
  91. frame.setLocationRelativeTo(null);
  92. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  93. frame.add(panel, BorderLayout.CENTER);
  94. panel.setLayout(null);
  95. panel.setBackground(gray);
  96. frame.setVisible(true);
  97.  
  98. for (int i = 0; i < 10; i++) {
  99. for (int j = 0; j < 10; j++) {
  100. double money = getMoney(i, j);
  101. double waiting = getWaiting(i, j);
  102. if (money > maxMoney) {
  103. maxMoney = money;
  104. }
  105. if (money < minMoney) {
  106. minMoney = money;
  107. }
  108. if (waiting > maxWaiting) {
  109. maxWaiting = waiting;
  110. }
  111. dot d = new dot(waiting, money); // <------
  112. frame.add(d);
  113. }
  114. }
  115.  
  116. System.out.println("The max Money is: € " + maxMoney);
  117. System.out.println("The min Money is: € " + minMoney);
  118. System.out.println("The max Waiting is: " + maxWaiting);
  119. }
  120.  
  121.  
  122. public static void main(String[] args) {
  123. (new TollGates()).run();
  124. //(new TollGates()).test();
  125. }
  126. }
  127.  
  128. class dot extends JPanel{
  129. double locx = 0;
  130. double locy = 0;
  131. int locyInt = 0;
  132.  
  133. dot(double x, double y){
  134.  
  135. locx = 1;
  136. locy = ((3.38E-8) * y) + 86.29;
  137.  
  138. locyInt = (int) (9.0 * ((4.65 * (Math.pow(10,-8) * y) + 118.8)));
  139.  
  140. //System.out.println(valDivMax);
  141. }
  142.  
  143. public void paintComponent (Graphics g){
  144. super.paintComponent(g);
  145.  
  146. g.setColor(Color.RED);
  147. g.fillOval(1, locyInt, 10, 10);
  148. }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement