Parking Lot Simulator

edited November 2017 in Questions about Code

Okay, this is my course project for my first year at engineering, its to make a parking lot simulator, and im having trouble where to start. Here is a PDF with the details : http://docdro.id/7ZyzCEF

I am trying to work towards Milestone one (page 6). I have some base code from an assignment, but im not sure what to start editing first to get the required output.

This is the code i get to start with (this was a previous assignment)

void setup(){
  size(520, 520);
  // creates parking stall objects
  int x=10;
  int y=10;
  for(int i=0;i<3;i++){
    x=10;
    for(int j=0;j<10;j++){
  ParkingStall ps1 = new ParkingStall(x, y, 50, 70);


  // sets parking stalls time of occupation
  int rand=(int)random(1,3);
  boolean time;
  if(rand==1){
    time=true;
  }else{
    time=false;
  }
  int day=(int)random(0,7);
  int hour=(int)random(0,12);
  int minute=(int)random(0,12);
  Date ps1_date = new Date (day, hour, minute, time);
  ps1.setStatus(time, ps1_date );

  // draws parking stalls on the screen  
  ps1.drawStall();


  // displays the time stall occupied on the console
  if(time){
  println( "row "+(i+1)+" column"+(j+1)+ " was occupied on: " + ps1.timeTaken);
  }
  x+=50;  
  }
  y+=140;

  }

}


class ParkingStall {
  // STALL ATTRIBUTES
  boolean occupied;
  Date timeTaken;

  // DIMENSIONS AND POSITION
  float stallWidth;
  float stallHeight;
  float posX;
  float posY;

  ParkingStall(float x, float y, float w, float h) {
    occupied = false;
    posX = x;
    posY = y;
    stallWidth = w;
    stallHeight = h;
  }

  void drawStall() {
    if (occupied)
      fill(color(255, 90, 71)); // RED STALL
    else
      fill(color(152, 251, 152));  // GREEN STALL
    strokeWeight(4);
    stroke(255);
    rect(posX, posY, stallWidth, stallHeight);
    strokeWeight(1);
  }

  // Sets whether the stall is occupied or not
  void setStatus(boolean status, Date time)
  {
    occupied = status;
    if (occupied) {
      timeTaken = new Date(time);
    }
  }
}

class Date{
  final String[] days={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
  int today;
  int hour;
  int minute;
  boolean before_noon;
  Date(int d,int h,int m,boolean beforenoon){


    today=d%7;
    hour=h%12;
    minute=m%60;
    before_noon=beforenoon;
    if(hour==0&&before_noon==false){
     hour=12; 
    }
}
  Date(Date d) { 

    today=d.today;
    hour=d.hour;
    minute=d.minute;
    if(d.before_noon==false){
    before_noon=true;
    } else{
     before_noon=false; 

    }
}
void addHour(){

  hour+=1;
  if(hour==12&&before_noon==false){
    before_noon=true;
    today+=1;
  }else if(hour==12&&before_noon==true){
    before_noon=false; 
  }


  hour=hour%12;
   if(hour==0&&before_noon==false){
     hour=12; 
    }

}
void addMinute(){

  minute+=1;
  if(minute>59){
  minute=minute%60;
  addHour();
}
}
String date;
String toString(){
  date=days[today]; 
 if(hour<10){
   date+=" 0"+hour;
 }
 else{
   date+=" "+hour;
   }
  if(minute<10){
   date+=":0"+minute;
  }else{
   date+=":"+minute;
   }
  if(before_noon){
   date+="AM";
  }
  else{
   date+="PM";
   }

return date;  
}

 boolean equal(Date date){

   if(date.today==today&&date.hour==hour&&date.minute==minute){
     return true;
   }else{
     return false;  
   } 
 }
}

I dont really know how to start to work towards Milestone 1. Where should i start?

Answers

  • It is hard to start with your previous code as it has some aspects that could be used in your assignment but some other parts must be re-written to fit you (future/current) design based on the given instructions.

    Do you have an idea of your final outcome? Do you have a feeling of what needs to be accomplished?

    Before you start coding, you need to think as a programmer architect and consider what pieces do you need for your program to run and HOW they will come together. For example, consider creating an object that receives both arrival time and departure time and this object outputs the total cost (This is for milestone 2). I can see this object to be a class by itself, and it will need to be instantiated once in the life of your program. It could potentially be owned by another class (potentially the ParkingLot object that you will instantiate during your program)

    Back to your question:

    You were giving a set of instructions. Note that what you implement in your first milestone won't be set on stone. It might change in the next two milestones, so don't be surprised if anything changes.

    You need to create the ParkingLotSimulator first. This is one tab in your Processing IDE. In this tab you have a setup() and draw() methods.

    Create a class called ParkingLot and it should look like this:

    class ParkingLot {
    
      //Constructor next...
    
    }
    

    Do the same for ParkingStallSection (aka. do its class definition). Now based only on those two classes and the descriptions given in your assignment, you should start putting everything together. I give you a idea:

    final int N_SECTIONS=6;
    final int ROW_N_IN_SECTION=5;
    final int COL_N_IN_SECTION=5;
    final int N_STALL_PER_SECTION=ROW_N_IN_SECTION*COL_N_IN_SECTION;
    final int SIZE_W=50;  //Width
    final int SIZE_H=70;
    
    ParkingLot  mainLot;
    
    void setup() {
      size(520, 520);
    
      mainLot = new ParkingLot(N_SECTIONS);
    
    }
    
    void draw(){
      background(0);
      mainLot.draw();
    }
    
    //ooooooooooo----------oooooooooooooo
    
    class ParkingLot {
    
      //Constructor next...
      //    Here you should think what to take as input and what to create next
      //    For instance, a parking lot has many sections. Here you need to 
      //    simplify your design: All parking lots on this planet are made of n given
      //    sections and each section has the same number of stalls organized
      //    in n rows by n columns. It is a very simplified model but that is what
      //    it was given to you. 
      //    QUESTION: How do you keep track of n number of sections? 
    
      //This function draws each section. 
      void draw(){
         //To be implemented
         //Here you iterate through your section objects and call the *draw* function
         //of each section so for them to be drawn. 
      }
    
    }
    
    //ooooooooooo----------oooooooooooooo
    
     class ParkingStallSection{
        //TBI (To be implemented): 
        //Contructor, member variables and associated functions
    
       //For instance: Next draws te section, which is made of row x col number 
       //of stalls
       void draw(){
       }
    
    }    
    
    //ooooooooooo----------oooooooooooooo
    
    class ParkingStall{
    
          //.......
    
     }
    

    Notice your last class is already implemented (or given to you) so you just need to reuse that code.

    For handling multiple objects, you should consider using arrays or arrayList (https://processing.org/reference/ArrayList.html). There are pros and cons of which one to use but not relevant at this point. Either one will work in your case.

    I hope this gives you some direction....

    Kf

  • Neat project. Kf has given you solid advice. Keep us informed of your progress?

Sign In or Register to comment.