Advertisement
Guest User

Thread

a guest
Nov 22nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package trythread;
  6.  
  7.  
  8.  
  9.  
  10.  
  11. /**
  12. *
  13. * @author Dee
  14. */
  15. public class TryThread {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21. // TODO code application logic here
  22.         Kopassus kop = new Kopassus();
  23.         kop.start();
  24.     }
  25. }
  26.  
  27. class Kopassus extends Thread {
  28.  
  29.     @Override
  30.     public void run() {
  31.         System.out.println("First Mission Started");
  32.         System.out.println("------------------------------------");
  33.         System.out.println(" Kopassus entering the battlefield. ");
  34.         System.out.println(" Kopassus begin evacuate the victim. ");
  35.         System.out.println("------------------------------------");
  36.  
  37.         for (int i = 1; i <= 20; i++) {
  38.             try {
  39.                 sleep(200);
  40.             } catch (InterruptedException ex) {
  41.                 ex.printStackTrace();
  42.             }
  43.             if (i < 20) {
  44.                 System.out.println(i + " pregnant women has been evacuated");
  45.             } else if (i == 20) {
  46.                 System.out.println(i + " pregnant women has been evacuated");
  47.                 System.out.println("-------------------------------");
  48.                 Marine marine = new Marine();
  49.                 marine.start();
  50.             }
  51.         }
  52.  
  53.     }
  54. }
  55.  
  56. class Marine extends Thread {
  57.  
  58.     @Override
  59.     public void run() {
  60.         System.out.println("Second Mission Started.");
  61.         System.out.println("Marine Entering Battlefield.");
  62.         System.out.println("-------------------------------");
  63.         for (int a = 1; a <= 50; a++) {
  64.             try {
  65.                 sleep(100);
  66.             } catch (InterruptedException ex) {
  67.                 ex.printStackTrace();
  68.             }
  69.  
  70.             System.out.println("Marine has been kill " + a + " terorist");
  71.             if (a <= 20) {
  72.                 System.out.println(a + " elderly has been evacuated");
  73.                 if (a == 20) {
  74.                     System.out.println(" First Mission Completed.");
  75.                     System.out.println("-------------------------------");
  76.                 }
  77.             }
  78.             if (a == 50) {
  79.                 System.out.println("Second Mission Complete.");
  80.                 System.out.println("---------------------------.");
  81.                 System.out.println("Third Mission Started.");
  82.                 System.out.println("Infantry Start Cleaning.");
  83.                 System.out.println("Third Mission Completed.");
  84.                 System.out.println("--------------------------");
  85.                 System.out.println("All Mission Completed.");
  86. // flag1 = false;
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement