java - Program not outputting data correctly -


i working on class assignment has create system simulate vehicles @ intersection. assume there 1 lane going in each of 4 directions, stoplights facing each direction. have vary arrival average of vehicles in each direction , frequency of light changes view "behavior" of intersection.

i gave best attempt @ assignment, still being new java seem have made mistake taking long time trying figure out. basically, outputs @ bottom of program not output anything.

i stuck assuming outputs output desiring them to, require rest of code sound.

that being said, if can spot error preventing code outputting everything, or in addition catches eye, appreciative.

import java.util.*;  public class intersection { private final static int process = 3; private final static int sim_length = 1000;  @suppresswarnings("resource") public static void main(string[] args)     {           car car = new car();            deque<car> carqueue = new linkedlist<car>();            int delaytotal = 0, cararrival, lightchange = 0, switchcount = 0, changecount = 0;           double carcount;           boolean = false;           string lightcolor, green = null, red = null;                 scanner scan = new scanner(system.in);                system.out.println("enter in car arrival interval between 1 , 5 seconds." + "\n");               cararrival = scan.nextint();                if (!(cararrival < 6 && cararrival > 0))                   system.out.println("enter valid time." + "\n");                scanner sc = new scanner(system.in);                system.out.println("enter in traffic light duration between 5 , 10 seconds." + "\n");               lightchange = sc.nextint();                 if (!(lightchange < 11 && lightchange > 4))                   system.out.println("enter valid time." + "\n");                //add car queue every [cararrival] seconds               (int = 0; < sim_length; i+= cararrival)                   {                     carqueue.add(car);                   }                 //develop way program know sim_length has               //counted 'lightchange' seconds.               //count each time lightchange occurs                (int = 0; < sim_length; i++)               {                   if (i % lightchange == 0)                   {                      changecount++;                   }               }               //assuming light starts red, every time preceding count increases 1,             //switch lightcolor.             //if count % 2 == 0, return green light; else red light                if (changecount % 2 == 0)               {                   = true;               }                 if (even)                   {                   lightcolor = green;                   }               else                   {                   lightcolor = red;                   }                while (lightcolor == green)               {                     //remove car queue every [process] seconds                     //(process time pass intersection)                        (int = 0; < sim_length; i+= process)                       {                           carqueue.remove(car);                       }                        //i increment 'switchcount can use divisor                       //for delaytotal find delayaverage                        switchcount++;               }               //trying increment delay time (cars immobilized red light)               delaytotal += lightchange;             //carcount example:           //lightchange = 6; process = 3; switchcount =166.7 times           //carcount = 333.4 cars; need whole number            carcount = (lightchange / process) * switchcount;             int delayaverage = delaytotal/switchcount;           int stranded = carqueue.size();            system.out.println("cars across: " + carcount);           system.out.println("delay (tot): " + delaytotal);           system.out.println("delay (avg): " + delayaverage);           system.out.println("number stranded: " + stranded);     } 

}


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -