Commits

Petar Stanev  committed 3b03c52

doma6no

  • Participants
  • Parent commits 5cfabff

Comments (0)

Files changed (9)

File plane2/.classpath

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

File plane2/.project

+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>plane2</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

File plane2/.settings/org.eclipse.jdt.core.prefs

+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7

File plane2/bin/plane/Human.class

Binary file added.

File plane2/bin/plane/Main.class

Binary file added.

File plane2/bin/plane/Plane.class

Binary file added.

File plane2/src/plane/Human.java

+package plane;
+
+public class Human 
+{
+	public String convertSimple(long i)
+	{
+	return "" + i;
+	}
+	
+	
+	private int name;
+	private int gender;
+Human()
+{
+	
+	{
+		
+		this.gender = 1 + (int)(Math.random()*2);
+		if(gender==1)
+		{
+			this.name = 1 + (int)(Math.random()*100);
+		}
+		
+		if(gender==1)
+		{
+			this.name = 101 + (int)(Math.random()*100);
+		}
+	}
+
+}
+
+public int getgender()
+	{
+	return this.gender;
+	}
+
+public int getname()
+	{
+	return this.name;
+	}
+
+}

File plane2/src/plane/Plane.java

+package plane;
+
+public class Plane 
+{
+	int row=0;
+	int i=0;
+    int sum=0;
+    int column=0;
+    int males=0;
+    int females=0;
+    int[][] seats = new int [27][6];
+    
+	
+	
+	public void print(){
+		for (int row=0;row<=26;row++)
+		{
+			for(int column=0;column<=5;column++)
+			{
+				System.out.print(seats[row][column]+" ");
+				if (column==2)
+				System.out.print("	");
+			}
+			System.out.println();
+		}	
+}
+		
+	
+	
+	public void Add(Human H)
+    {
+			
+            for(i=0;sum!=162;i++)
+            {
+                    int rvalue= 1 + (int)(Math.random()*3);
+                    
+                    {
+                            if(rvalue==1)
+                            {
+                                    if (row<=26)
+                                    {
+                                            if(column<=5)
+                                            {
+                                            	if (H.getgender()==1)
+                                            	{
+                                            		seats[row][column]=1;
+                                            		sum=sum+1;
+                                            	}
+                                            	else
+                                            	{
+                                            	seats[row][column]=2;
+                                            	sum=sum+1; 
+                                            	}
+                                        		return;
+                                        		
+                                            }
+                                            else
+                                            {
+                                            	row=row+1;	
+                                            }
+                                    }
+                            }
+                    }
+                    
+                    {
+                            if(rvalue==2)
+                            {
+                            	if (row<=26)
+                                    {
+                            			if(column<=5)
+                                            {
+                                                    if ((column!=2)&&(column!=5))
+                                                    {
+                                                            if((seats[row][column]==0) || (seats[row][column+1]==0))
+                                                            {
+                                                            	if (H.getgender()==1)
+                                                            	{
+                                                            		seats[row][column]=1;
+                                                            		seats[row][column+1]=1;
+                                                            	}
+                                                            	else
+                                                            	{
+                                                            	seats[row][column]=2;
+                                                            	seats[row][column+1]=2;
+                                                            	}
+                                                        		
+                                                        		sum=sum+2;
+                                                                column=column+2;
+                                                                return;
+                                                               
+                                                            }
+                                                    }
+                                            }
+                            				else
+                            				{
+                            					row=row+1;
+                            				}
+                                    }
+                            }
+                    }
+                    
+                    {
+                            if(rvalue==3)
+                            {
+                            	if (row<=26)
+                                    {
+                            				if(column<=5)
+                                            {
+                                                    if ((column==0) || (column==3))
+                                                    {
+                                                            if((seats[row][column]==0) || (seats[row][column+1]==0) || (seats[row][column+2]==0))
+                                                            {
+                                                            	if (H.getgender()==1)
+                                                            	{
+                                                            		seats[row][column]=1;
+                                                            		seats[row][column+1]=1;
+                                                            		seats[row][column+2]=1;
+                                                            	}
+                                                            	else
+                                                            	{
+                                                            	seats[row][column]=2;
+                                                            	seats[row][column+1]=2;
+                                                            	seats[row][column+2]=2;
+                                                            	}
+                                                            	
+                                                            	sum=3+sum;
+                                                                column=column+3;
+                                                        		return;       
+                                                            }
+                                                    }
+                                            }else{
+                                            	row=row+1;
+                                            }
+                                    }
+                            }
+            
+                    }
+            }
+    }
+	
+	public void remove(Human H) 
+	{
+		
+		if(column-1<=5 && column-1>=0)
+		{
+			seats[row][column]=0;
+			sum=sum-1;
+		}
+		else 
+		{
+			row=row-1;
+			column=5;
+			seats[row][column]=0;
+			sum=sum-1;
+		}
+			
+		
+		
+		
+	}
+	
+	public void clear() 
+	{		
+	   	for (int row=0;row<=26;row++)
+		{
+			for(int column=0;column<=5;column++)
+				{
+				seats[row][column]=0;
+				}
+		}
+	   	sum=0;
+			    
+	}
+	
+	public int getCapacity() 
+	{
+		int Capacity = 162 - sum;
+		return Capacity;
+	}
+	
+	public void printSeats(){
+		for (int row=0;row<=26;row++)
+		{
+			for(int column=0;column<=5;column++)
+			{
+				System.out.print(seats[row][column]);
+			if (column==2)
+				System.out.print(" ");
+			}
+		System.out.print(" \n");
+		}	
+	}
+	
+	public int getMales() 
+	{
+		for (row=0;row<26;row++)
+		{
+			for (column=0;column<5;column++)
+			{
+				if(seats[row][column]==1)
+				{
+					males=males+1;
+				}
+				
+			}
+		}
+		
+	return males;
+	}
+	
+	public int getFemales() 
+	{
+		for (row=0;row<26;row++)
+		{
+			for (column=0;column<5;column++)
+			{
+				if(seats[row][column]==2)
+				{
+					females=females+1;
+				}
+				
+			}
+		}
+		
+	return females;
+	}
+	
+	
+	
+}

File plane2/src/plane/main.java

+package plane;
+
+public class Main {
+
+	public void fill(Plane AirPlane) 
+	{
+		Human[] H= new Human[162];
+		for (int n=0;n<162;n++)
+		{
+		H[n]=new Human();
+		}
+		
+		while (Plane.getCapacity() !=0 )
+		{
+			Plane Jet.Add();
+		}	
+		
+	}
+	
+
+	
+	
+	public static void main(String[] args) 
+	{
+	Plane Jet = new Plane();
+	Main M= new Main();
+	M.fill(Jet);
+	Jet.printSeats();
+	}
+}
+