We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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:
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:
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?