Results 1 to 16 of 16

Thread: Airport problem

  1. #1
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Airport problem

    Hello!,
    C I ask you for help to the task?
    The job looks so that they are flying planes take off and landing
    before I did the plane, and landing class but it does not work if I could ask for help
    to the following program contains the landing?

    Java Code:
    public class Runway extends Thread {
    
    	class Landing implements Runnable  {
    		private Landing landing;
    		private String name;
    		private long delay;
    		
    		
    	public Ladowanie(Ladowanie ladowanie, String name){
    		this.name=name;
    		this.landing=landing;
    		
    	}
    		public synchronized long landing() throws InterruptedException{
    			long delay=10000;
    			start();
    			return delay;
    		}
    
    		
    		public void run() {
    						try {
    							long time = landing();
    							System.out.println(name + "loduje");
    
    					} catch (InterruptedException e) {
    				
    			}
    	
    			int priority = Thread.currentThread().getPriority();
    			Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    			boolean stop = true;
    				System.out.println("plane" + name + "landing");
    				
    		}
    	}
    
    	
    	public static void main(String[] args) throws InterruptedException {
    		// TODO Auto-generated method stub
    		Runway landing = new Runway ();
    
    		
    		Thread Plane1 = new Thread(new Plane("Nr1", landing));
    		Plane1.start();
    		Thread Plane2 = new Thread(new Plane("Nr2",landing));
    		Plane2.start();
    		Thread Plane3 = new Thread(new Plane("Nr3",landing));
    		Plane3.start();
    		Thread Plane4 = new Thread(new Plane("Nr4",landing));
    		Plane4.start();
    	
    
    	}
    
    }
    
    //plane
    
    
    public class Plane implements Runnable {
    
    	private String name;
    	private runway landing;
    
    	
    	public Plane(String name, runway  landing) {
    		this.name = name;
    		this.landind = landing;
    	}
    
    	public void run() {
    		try {
    			Start();
    			System.out.println(this.name + "ready to start");
    
    			long time = getFly();
    			System.out.println(name + "fly");
    
    			time = Tank();
    			System.out.println(name + "tank");
    
    		} catch (InterruptedException e) {
    			
    		}
    	}
    
    	public long Tank() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    	public long getFly() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    	public long Start() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    }
    Last edited by Norm; 05-27-2012 at 09:36 PM. Reason: added code tags

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Airport problem

    Please tell us what your exact question is. Where *exactly* are you stuck? Details may be very important here, so take your time, and tell us all we need to know to be able to help you. And welcome to our forum.

  3. #3
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Hello,
    so I my problem is landing can't working with plane when I run program it show me what's doing my plane so he start fly and tank but no landing
    my problem is how to make the work of landing the plane
    thanks for ypur answer ;]

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Airport problem

    Java Code:
        public Ladowanie(Ladowanie ladowanie, String name){
            this.name=name;
            this.landing=landing;
             
        }
    That looks like a constructor, but its name doesn't match the class. Please post some real, compilable code that demonstrates your problem.
    Get in the habit of using standard Java naming conventions!

  5. #5
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    yes is mistake can I endind this post because I found my problem and I solved it
    Thanks for all

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Airport problem

    Quote Originally Posted by vesna View Post
    yes is mistake can I endind this post because I found my problem and I solved it
    Thanks for all
    Can you tell us all what the problem in fact was?

  7. #7
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Quote Originally Posted by Fubarable View Post
    Can you tell us all what the problem in fact was?
    My program was to create a bootable Belt, which handles aircraft Aircraft that we have a function but in this code is not working I land class and do not know why I asked you why you might be able to think and suggest a solution as I learn and threads, unfortunately are not yet very clear to me Here again the code will now properly constructed means there are no typos

    Java Code:
    public class Runway extends Thread {
    
    	class Ladowanie implements Runnable  {
    		private Landing landing;
    		private String name;
    		private long delay;
    		
    		
    	public Landing(Landing landing, String name){
    		this.name=name;
    		this.landing=landing;
    		
    	}
    		public synchronized long landing() throws InterruptedException{
    			long delay=10000;
    			start();
    			return delay;
    		}
    
    		
    		public void run() {
    						try {
    							long time = landing();
    							System.out.println(name + "landing");
    
    					} catch (InterruptedException e) {
    				
    			}
    	
    			int priority = Thread.currentThread().getPriority();
    			Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    			boolean stop = true;
    				System.out.println("Plane" + name + "landing");
    				
    		}
    	}
    
    	
    	public static void main(String[] args) throws InterruptedException {
    	
    		Runway landing= new Runway();
    
    		Thread plane1= new Thread(new Plane("Nr1", landing));
    		plane1.start();
    		Thread plane2= new Thread(new Plane("Nr2",landing));
    		plane2.start();
    		
    	
    
    	}
    
    }
    
    public class Plane implements Runnable {
    
    	private String name;
    	private Runway landing;
    
    	
    	public Plane(String name, Runway landing) {
    		this.name = name;
    		this.landing= landing;
    	}
    
    	public void run() {
    		try {
    			Starting();
    			System.out.println(this.name + "ready to start");
    
    			long time = getFly();
    			System.out.println(name + "fly");
    
    			time = Tank();
    			System.out.println(name + "tank");
    
    		} catch (InterruptedException e) {
    			
    		}
    	}
    
    	public long Tank() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    	public long getFly() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    	public long Starting() throws InterruptedException {
    		long delay = 1000;
    		Thread.sleep(delay);
    		return delay;
    	}
    
    }
    ]

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: Airport problem

    Can you post the output from the program and add some comments to it describing what is wrong and add comments that show what the output should be?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Quote Originally Posted by Norm View Post
    Can you post the output from the program and add some comments to it describing what is wrong and add comments that show what the output should be?
    Java Code:
    public class Runway extends Thread {  // in here is a class of Runway 
     
        class Landing implements Runnable  { // in here is a class landing
            private Landing landing;
            private String name;
            private long delay;
             
             
        public Landing(Landing landing, String name){
            this.name=name;
            this.landing=landing;
             
        }
            public synchronized long landing() throws InterruptedException{
                long delay=10000;
                start();
                return delay;
            }
     
             
            public void run() {
                            try {
                                long time = landing();
                                System.out.println(name + "landing");
     
                        } catch (InterruptedException e) {
                     
                }
         
                int priority = Thread.currentThread().getPriority();
                Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
                boolean stop = true;
                    System.out.println("Plane" + name + "landing");
                     
            }
        }
     
         
        public static void main(String[] args) throws InterruptedException {
         
            Runway landing= new Runway();  // in here i create  landing that must be function of Runway not plane
     
            Thread plane1= new Thread(new Plane("Nr1", landing)); // I added to the this  thread  a class of landing but the thread does not use                // this class
            plane1.start();
            Thread plane2= new Thread(new Plane("Nr2",landing));
            plane2.start();
             
         
     
        }
     
    }
    
    
    
    
     
    public class Plane implements Runnable {   // in here is a class of plane 
     
        private String name;
        private Runway landing;
     
         
        public Plane(String name, Runway landing) {
            this.name = name;
            this.landing= landing;
        }
     
        public void run() {
            try {
                Starting();
                System.out.println(this.name + "ready to start");
     
                long time = getFlying();
                System.out.println(name + "flying");
     
                time = Tank();
                System.out.println(name + "tank");
     
            } catch (InterruptedException e) {
                 
            }
        }
     
        public long Tank() throws InterruptedException { // in here is  a method of tank start and flying
            long delay = 1000;
            Thread.sleep(delay);
            return delay;
        }
     
        public long getFlying() throws InterruptedException {
            long delay = 1000;
            Thread.sleep(delay);
            return delay;
        }
     
        public long Starting() throws InterruptedException {
            long delay = 1000;
            Thread.sleep(delay);
            return delay;
        }
     
    }

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: Airport problem

    Can you post the output from the program? What it prints on the console screen.
    add some comments to it describing what is wrong and add comments that show what the output should be?
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Quote Originally Posted by Norm View Post
    Can you post the output from the program? What it prints on the console screen.
    add some comments to it describing what is wrong and add comments that show what the output should be?

    The program print

    Plane1 starting
    plane2 strating
    plane3 strating
    plane4 starting
    plane1 flying
    plane2 flying
    plane3 flying
    plane4 flying
    plane1 tank
    plane2 tank
    plane3 tank
    plane4 tank


    and unfortunately the program doesn't print plane 1 landing and the end ;/

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: Airport problem

    Where is the program that creates that output? When I execute the program that was posted in post #9 I get this:

    Nr1ready to start
    Nr2ready to start
    Nr1flying
    Nr2flying
    Nr2tank
    Nr1tank
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Quote Originally Posted by Norm View Post
    Where is the program that creates that output? When I execute the program that was posted in post #9 I get this:

    Nr1ready to start
    Nr2ready to start
    Nr1flying
    Nr2flying
    Nr2tank
    Nr1tank
    I'm sorry you're right
    I saw earlier code and I forgot that I had changed it to a more shorter I'll be much careful about what I look

    When I have a class in the Runway it should be a method of Landing but not class Landing
    but when I to change the class to method of Landing
    Class of aircraft does not want to take the results from the class Runway;/

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: Airport problem

    The code does not create an instance of the Landing class. It needs to do that if you want that code to be executed that prints out "landing".
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    vesna is offline Member
    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Default Re: Airport problem

    Quote Originally Posted by Norm View Post
    The code does not create an instance of the Landing class. It needs to do that if you want that code to be executed that prints out "landing".
    I need to create separate class which will combine topic and the class with function of landing ??

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,561
    Rep Power
    25

    Default Re: Airport problem

    Look at the program's requirements to see what you need to do.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •