עבור לתוכן

JAVA תהליכונים

Featured Replies

פורסם

תכנית שמבצעת הדמיה של קו ייצור כסאות הכולל 4 עמדות עבודה המתבצעות במקביל.

העמדה הראשונה בונה את השלד של הכסא משלושה סוגים שונים של עץ .

העמדה השניה מקבלת את השלד מהעמדה הראשונה וצובעת את השלד באחד משלושה צבעים.

העמדה השלישית מקבלת את השלד הצבוע ומרכיבה עליו את המושב (יש רק סוג אחד).

העמדה הרביעית מקבלת את השלד עם המושב ומרפדת את המושב באחד משני סוגי עורות.

כל תהליך המייצג עמדה, מעביר הודעה עם פרטי הכסא המוזמן לתהליך המייצג את העמדה הבאה, לאחר שסיים את הפעולה.

בסיום המשימה האחרונה יש לרשום האם הכסא הושלם או שחסר בו דבר. (בכל מקרה מעבירים הלאה את פרטי ההזמנה)

עבור הקלט יש ליצור 'הזמנות' בעזרת ערכים אקראיים. סיום העבודה ע"י 'דגל' מוסכם.

השאלה שלי:

מה יש בconstructor של הכסא?

וגם איך אני מעבירה את פרטי הכסא בין העמדות?

זה מה שעשיתי עד עכשיו:



public class Cheir
{
int x;
float tree;
float color;
int seat;
float skin;


public Cheir(int k)
{
x=k;
}
}



//import java.io.* ;
import java.lang.Thread;
import java.lang.Math;


class built extends Thread // בניית שלד הכסא
{
Event64 begin, end;
Cheir data;

public built(Event64 BeginA, Event64 BeginB) // constructor
{
begin = BeginA;
end = BeginB;
data = new Cheir(1);


start();
}

public void run()
{
System.out.println("built starts ");
while(data.x!=0)
{
data=(Cheir)(begin.waitEvent());
System.out.println("built Cheir number "+(data.x-1));

float t;
if (t<0.3)
{
System.out.println("Sug tree for build sheled Cheir is 'Erez'.");
}
else
if((t>=0.3)&&(t<0.7))
{
System.out.println("Sug tree for build sheld Cheir is' 'Shita'.");
}
else
{
System.out.println("Sug tree for build sheled Cheir is''Olive'.");
}


end.sendEvent(data);
}
System.out.println("built finish");
}
}

class paint extends Thread // צביעת הכסא
{
Event64 begin,end;
Cheir data = new Cheir(2);

public paint(Event64 BeginB, Event64 BeginC) // constructor
{
begin = BeginB;
end = BeginC;

start();
}

public void run ()
{
System.out.println("paint starts");
while(data.x==2)
{
data=(Cheir)(begin.waitEvent());
System.out.println ("paint chair number "+(data.x-2));

float c;
if (c<0.3)
{
System.out.println("Color for paint the Cheir is 'Tchelet'.");
}
else
if((c>=0.3)&&(c<0.7))
{
System.out.println("Color for paint the Cheir is 'Argaman'.");
}
else
{
System.out.println("Color for paint the Cheir is 'Shani'.");
}

end.sendEvent(data);
}
System.out.println("paint finish");
}
}

class seat extends Thread // הנחת מושב לכסא
{
Event64 begin,end;
Cheir data=new Cheir(3);

public seat(Event64 BeginC, Event64 BeginD) // constructor
{
begin = BeginC;
end = BeginD;

start();
}

public void run ()
{
System.out.println("seat starts");
while(data.x==3)
{
data=(Cheir)(begin.waitEvent());
System.out.println ("put seats for cheir number "+(data.x-3));


end.sendEvent(data);
}
System.out.println("seat finish");
}
}

class ripud extends Thread // ריפוד הכסא
{
Event64 begin,end;
Cheir data=new Cheir(4);

public ripud(Event64 BeginD) // constructor
{
begin = BeginD;

start();
}

public void run ()
{
System.out.println("ripud starts");
while(data.x==4)
{
data=(Cheir)(begin.waitEvent());
System.out.println ("put ripud for cheir number "+(data.x-4));

float sk;
if (sk<0.5)
{
System.out.println("Ripud on the Cheir is 'Or Ayalim'.");
}
else
{
System.out.println("Ripud on the Cheir is 'Or Tahash'.");
}

}

System.out.println("ripud finish");
}
}


public class Table
{

int n=4; // no of pieces.
int k; // nb turn
Cheir data;

void rotable()
{
Event64 beginA = new Event64();
Event64 beginB = new Event64();
Event64 beginC = new Event64();
Event64 beginD = new Event64();

built a = new built (beginA, beginB);
paint b = new paint (beginB, beginC);
seat c = new seat (beginC, beginD);
ripud d = new ripud (beginD);

for(k=1 ; k<=n; k++)
{
data = new Cheir(k);
beginA.sendEvent(data);
System.out.println ("turn the table");


float tree = (float)Math.random();
float color = (float) Math.random();
int seat;
float skin = (float) Math.random();

}

data=new Cheir(0);
beginA.sendEvent(data);
}


public static void main(String[] args)
{
Table t= new Table();
t.rotable();
}
}

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים