Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author s162556
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- public class TollGates {
- JFrame frame = new JFrame("Graph");
- JPanel panel = new JPanel();
- JPanel titel = new JPanel();
- Color gray = new Color(230, 230, 230); //Black colour for black background. Blackground XD
- Color red = new Color(255, 0, 0); //White colour
- double maintenancePerTollgatePerYear = 1200.0;
- double employerCostsPerYear = 60000.0;
- double placingCostsTollgate = 150000.0;
- double maintenancePerRoadPerYear = 140.0;
- double placingCostsRoad = 50000.0;
- double startSpeed = 100.0;
- double roadTime = 10.0;
- double acceleration = 2.8;
- double pricePerCar = 5.0;
- double pricePerMotor = 2.5;
- double pricePerTruck = 25.0;
- double vehiclesPerHour = 2755.0;
- double waitingTime = 10.0;
- double maxMoney = -1E10;
- double minMoney = 0;
- double maxWaiting = 0;
- double getMoney(int normal, int ttag) {
- double vehiclesPerYear = vehiclesPerHour * 24.0 * 365.0;
- double carsPerYear = vehiclesPerYear * (110.0 / 124.0);
- double motorsPerYear = vehiclesPerYear * (1.0 / 124.0);
- double trucksPerYear = vehiclesPerYear * (13.0 / 124.0);
- double incomeAfter15Years = 15.0 * ((carsPerYear * pricePerCar) + (motorsPerYear * pricePerMotor) + (trucksPerYear * pricePerTruck));
- double roadTimeSquared = Math.pow(roadTime, 2.0);
- double amountOfRoadPerTollgate = 2.0 *(startSpeed * roadTime + 0.5 * acceleration * roadTimeSquared);
- double costsPerRoadAfter15Years = amountOfRoadPerTollgate * (15.0 * maintenancePerRoadPerYear + placingCostsRoad);
- double costsPerTollgateAfter15Years = 15.0 * (maintenancePerTollgatePerYear + employerCostsPerYear) + placingCostsTollgate;
- double costsPerUnitAfter15Years = costsPerTollgateAfter15Years + costsPerRoadAfter15Years;
- double amountOfUnits = normal + ttag;
- double costsAfter15Years = amountOfUnits * costsPerUnitAfter15Years;
- double nettoCostsAfter15Years = (costsAfter15Years - incomeAfter15Years); //incomeAfter15Years);
- return nettoCostsAfter15Years;
- }
- double getWaiting(int normal, int ttag) {
- double THIRD = (1.0/3.0);
- //System.out.println(THIRD);
- double normalUserLeavingPerHour = normal * (3600.0 / waitingTime);
- //System.out.println(normalUserLeavingPerHour);
- double normalUserArrivingPerHour = vehiclesPerHour * THIRD;
- //System.out.println(normalUserArrivingPerHour);
- double tTagUserArrivingPerHour = vehiclesPerHour * 2.0 * THIRD;
- //System.out.println(tTagUserArrivingPerHour);
- double tTagUserLeavingPerHour = ttag * (3600.0 / 2.0);
- //System.out.println(tTagUserLeavingPerHour);
- double tTagUsersWaitingAfter24h = Math.max(24.0 * (tTagUserArrivingPerHour - tTagUserLeavingPerHour), 0);
- //System.out.println(tTagUsersWaitingAfter24h);
- double normalUsersWaitingAfter24h = Math.max(0, 24.0 * (normalUserArrivingPerHour - normalUserLeavingPerHour));
- //System.out.println(normalUsersWaitingAfter24h);
- double amountOfWaitingVehiclesAfter24h = tTagUsersWaitingAfter24h + normalUsersWaitingAfter24h;
- if (amountOfWaitingVehiclesAfter24h < 0) {
- amountOfWaitingVehiclesAfter24h = 0;
- }
- return amountOfWaitingVehiclesAfter24h;
- }
- void run() {
- frame.setSize(1000, 1000);
- frame.setLocationRelativeTo(null);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.add(panel, BorderLayout.CENTER);
- panel.setLayout(null);
- panel.setBackground(gray);
- frame.setVisible(true);
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- double money = getMoney(i, j);
- double waiting = getWaiting(i, j);
- if (money > maxMoney) {
- maxMoney = money;
- }
- if (money < minMoney) {
- minMoney = money;
- }
- if (waiting > maxWaiting) {
- maxWaiting = waiting;
- }
- dot d = new dot(waiting, money); // <------
- frame.add(d);
- }
- }
- System.out.println("The max Money is: € " + maxMoney);
- System.out.println("The min Money is: € " + minMoney);
- System.out.println("The max Waiting is: " + maxWaiting);
- }
- public static void main(String[] args) {
- (new TollGates()).run();
- //(new TollGates()).test();
- }
- }
- class dot extends JPanel{
- double locx = 0;
- double locy = 0;
- int locyInt = 0;
- dot(double x, double y){
- locx = 1;
- locy = ((3.38E-8) * y) + 86.29;
- locyInt = (int) (9.0 * ((4.65 * (Math.pow(10,-8) * y) + 118.8)));
- //System.out.println(valDivMax);
- }
- public void paintComponent (Graphics g){
- super.paintComponent(g);
- g.setColor(Color.RED);
- g.fillOval(1, locyInt, 10, 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement