We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am working on a project for my ENGG 233 class. i have a working code, but the project requirements state that i need to use class ParkingLot, class ParkingStallSection, class Date, and class ParkingStall. the details are listed here: http://docdro.id/7ZyzCEF . I have code for class Date and class ParkingStallCan from a previous assignment. Can anybody help me break apart this code into the necessary classes?
PShape s;
PShape f;
void draw(){
shape (s,0,0);
shape (f,0,0);
}
void setup(){
size(850, 1000);
background(100);
stroke(255);
strokeWeight(4);
line(0,395,850,395);
s=createShape();
s.beginShape();
s.fill(0,200,0);
s.stroke(255);
s.strokeWeight(3);
s.vertex(2, 450);
s.vertex(370, 450);
s.vertex(370, 480);
s.vertex(100, 480);
s.vertex(100,920);
s.vertex(370,920);
s.vertex(370,920);
s.vertex(370,950);
s.vertex(2,950);
s.endShape(CLOSE);
f=createShape();
f.beginShape();
f.fill(0,200,0);
f.stroke(255);
f.strokeWeight(3);
f.vertex(848, 450);
f.vertex(480, 450);
f.vertex(480, 480);
f.vertex(750, 480);
f.vertex(750,920);
f.vertex(480,920);
f.vertex(480,920);
f.vertex(480,950);
f.vertex(848,950);
f.endShape(CLOSE);
ParkingStall [][] psA = new ParkingStall[2][5];
ParkingStall [][] psB = new ParkingStall[2][5];
ParkingStall [][] psC = new ParkingStall[2][5];
ParkingStall [][] psD = new ParkingStall[2][5];
ParkingStall [][] psE = new ParkingStall[2][5];
ParkingStall [][] psF = new ParkingStall[2][5];
int counter = 0;
int counter1 = 0;
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
psA[i][j] = new ParkingStall(146 + counter, 510 + counter1, 50, 50);
psB[i][j] = new ParkingStall(456 + counter, 510 + counter1, 50, 50);
psC[i][j] = new ParkingStall(146 + counter, 650 + counter1, 50, 50);
psD[i][j] = new ParkingStall(456 + counter, 650 + counter1, 50, 50);
psE[i][j] = new ParkingStall(146 + counter, 790 + counter1, 50, 50);
psF[i][j] = new ParkingStall(456 + counter, 790 + counter1, 50, 50);
counter += 50;
}
counter = 0;
counter1 += 50;
}
// sets parking stalls time of occupation
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psA[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psA[i][j].setStatus(flag2, psA[i][j].timeTaken );
}}
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psB[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psB[i][j].setStatus(flag2, psB[i][j].timeTaken );
}}
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psC[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psC[i][j].setStatus(flag2, psC[i][j].timeTaken );
}}
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psD[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psD[i][j].setStatus(flag2, psD[i][j].timeTaken );
}}
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psE[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psE[i][j].setStatus(flag2, psE[i][j].timeTaken );
}}
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
boolean flag1 = boolean((int)random(0,2));
boolean flag2 = boolean((int)random(0,2));
psF[i][j].timeTaken = new Date ((int)random(0,7),(int)random(1,12),(int)random(1,60), flag1);
psF[i][j].setStatus(flag2, psF[i][j].timeTaken );
}}
// draws parking stalls on the screen
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
psA[i][j].drawStall();
psB[i][j].drawStall();
psC[i][j].drawStall();
psD[i][j].drawStall();
psE[i][j].drawStall();
psF[i][j].drawStall();
}}
// displays the time stall occupied on the console
for(int i = 0; i < 2; i++)
{
for(int j = 0; j < 5; j++)
{
if(psA[i][j].occupied != false)
{
println( "Row " + (i + 1) + " column " + (j + 1) + " was occupied on: " + psA[i][j].timeTaken);
}}
for(int j = 0; j < 5; j++)
{
if(psB[i][j].occupied != false)
{
println( "Row " + (i + 1) + " column " + (j + 6) + " was occupied on: " + psB[i][j].timeTaken);
}}
for(int j = 0; j < 5; j++)
{
if(psC[i][j].occupied != false)
{
println( "Row " + (i + 3) + " column " + (j + 1) + " was occupied on: " + psC[i][j].timeTaken);
}}
for(int j = 0; j < 5; j++)
{
if(psD[i][j].occupied != false)
{
println( "Row " + (i + 3) + " column " + (j + 6) + " was occupied on: " + psD[i][j].timeTaken);
}}
for(int j = 0; j < 5; j++)
{
if(psE[i][j].occupied != false)
{
println( "Row " + (i + 5) + " column " + (j + 1) + " was occupied on: " + psE[i][j].timeTaken);
}}
for(int j = 0; j < 5; j++)
{
if(psF[i][j].occupied != false)
{
println( "Row " + (i + 5) + " column " + (j + 6) + " was occupied on: " + psF[i][j].timeTaken);
}}
}
}
class Date
{
final String [] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int today;
int hour;
int minute;
boolean beforeNoon;
Date(int d, int h, int m, boolean n)
{
today = d%7;
hour = h%13;
minute = m%60;
beforeNoon=n;
}
Date(Date d)
{
today = d.today;
hour = d.hour;
minute = d.minute;
beforeNoon = d.beforeNoon;
}
void addHour()
{
if(hour <= 11)
hour++;
if( hour == 12 )
{
hour = 1;
if(beforeNoon == true)
beforeNoon = false;
else
beforeNoon = true;
}}
void addMinute()
{
if(minute <= 59)
minute++;
if(minute == 60)
{
hour++;
if(hour == 13 && beforeNoon == false)
{hour = 1; }
if(hour == 12 && beforeNoon == false)
{
beforeNoon = true;
today++;
}
minute = 0;
}}
String toString()
{
String date = days[today];
if(hour < 10)
date += " 0" + hour;
else
date += " " + hour;
if(minute < 10)
date += ":0" + minute;
else
date += ":" + minute;
if(beforeNoon)
date += "AM";
else
date += "PM";
return date;
}
boolean equal(Date date)
{
if(date.hour==hour && date.minute == minute && date.today == today)
return true;
else
return false;
}}
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 ParkingStallSection{
}
class ParkingLot{
}
Answers
https://forum.processing.org/two/discussion/25136/parking-lot-simulator
please format your code. edit post, highlight the code, press ctrl-o. remove the backticks from the failed attempt at formatting.
trying to fix it now, thanks
sorry bout that, this should be way easier now
use ctrl-t in the processing editor to indent the code correctly. if it's easier to read it's easier to understand and debug.
I look at this and think "Gee, wouldn't a ParkingLotStallSection be just one of those, and a ParkingLot have and array of six ParkingLotStallSections?".
I'm well aware of what I need to do, the issue I have is formatting them into the separate classes.
Well one class starts like this...
And the other starts like this...
So that's like, a lot of help.
I'm working though the final section of my code, but I'm having issues displaying the changing time on the screen. using the same Date class, how can I do this?