Results 1 to 16 of 16
Thread: Airport problem
- 05-27-2012, 05:26 PM #1
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
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
-
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.
- 05-27-2012, 05:59 PM #3
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
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 ;]
- 05-28-2012, 06:38 PM #4
Re: Airport problem
That looks like a constructor, but its name doesn't match the class. Please post some real, compilable code that demonstrates your problem.Java Code:public Ladowanie(Ladowanie ladowanie, String name){ this.name=name; this.landing=landing; }Get in the habit of using standard Java naming conventions!
- 05-28-2012, 10:07 PM #5
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
Re: Airport problem
yes is mistake can I endind this post because I found my problem and I solved it
Thanks for all
-
Re: Airport problem
- 06-01-2012, 02:22 PM #7
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
Re: Airport problem
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; } }
- 06-01-2012, 06:57 PM #8
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.
- 06-02-2012, 12:00 PM #9
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
Re: Airport problem
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; } }
- 06-02-2012, 02:24 PM #10
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.
- 06-02-2012, 02:37 PM #11
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
Re: Airport problem
- 06-02-2012, 02:42 PM #12
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
Nr1tankIf you don't understand my response, don't ignore it, ask a question.
- 06-03-2012, 11:56 AM #13
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
Re: Airport problem
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;/
- 06-03-2012, 02:19 PM #14
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.
- 06-03-2012, 06:00 PM #15
Member
- Join Date
- May 2012
- Posts
- 8
- Rep Power
- 0
- 06-03-2012, 06:20 PM #16


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks