Results 1 to 8 of 8
  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Smile Coded Life Lesson :)

    Java Code:
    //Computer Humour
    // Lesson learned in life translated to code
    
    
    
    public class LifeFunctions throws Exception
    {
    		boolean compatibilityCheck(Person p)
    		{
    			if(P.personailty == me.personality)
    			{
    				return true;
    			}else
    				return false;
    			
    		}
    		
    		// make people happy
    		void makeHappy (People p)
    		{
    			if(p.size == Everybody)
    			{
    				throw LargeDomainErr;
    			}
    	
    		}
    
    		// NEw method Adopted :)
    		// keep some people distant from your life
    		void dropSomePeople(People p)
    		{
    			while(p.size >0 )
    			{
    				if(compatibilityCheck(p) == false)
    				{
    				p.drop();	
    				}
    				p.size -= 1;
    			}
    
    		}
    
    }
    
    public class LifeLesson 
    {
    
    	
    	
    	public static void main (String args[])
    	{
    		People Everybody = new People();
    		People somePeople = new People();
    		try 
    		{
    	
    			makeHappy(Everybody);
    		}
    		catch (LargeDomainErr e)
    		{
    			system.out.println("not possible :p");
    				
    			somePeople = dropSomePeople(Everybody);
    
    		}
    		finally
    		{
    			System.out.println("..trying again.");
    			
    		}
    	
    				
    		makeHappy(somePeople);
    		
    	
    	}
    }

  2. #2
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    Guess what this code would print out (imagining you made up the dependencies) :)

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    haha funny, but i'm a bit confused on the return type.

    Java Code:
    LifeLesson.java:3: incompatible types
    found   : void
    required: People
        somePeople = dropSomePeople
                     ^
    1 error
    little logic bug...
    Java Code:
    if(compatibilityCheck(p) == false)
    {
      p.drop();	
    }[B] // should be moved below[/B]
    p.size -= 1;
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  4. #4
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    yeah true..
    dropSomePeople() should return People type ...

    Though why do you think I should move the that below???

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    nm i misread that part.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default Coded Life Lesson2 :)

    this actually compiles (although w/ bugs...)

    Java Code:
    import java.util.*;
    
    public class Capitalism {
      public static void main(String[] args){
        List<Company> companies = new ArrayList<Company>();
        
        Company xyz = new Company();
        companies.add(xyz);
        
        Worker angryBoy = new Worker();
        xyz.add(angryBoy);
        
        xyz.start();
        
        try {
          Thread.sleep((int)Math.random()*10);
          angryBoy.bos=true;
          Thread.sleep(10000);
          angryBoy.bos=false;
          Thread.sleep(10);
          angryBoy.quittingTime = true;
        }catch(InterruptedException ex){}
        
      }
    }
    
    /**
      TODO: add timer to control worker...
    */
    class Company {
      private List<Worker> workers = new ArrayList<Worker>();
      
      public void add(Worker w){
        workers.add(w);
      }
      
      public void start(){
        for(Worker w: workers){
          new Thread(w).start();
        }
      }
    }
    
    /**
      TODO: accessor/mutator methods and syncs.
    */
    class Worker implements Runnable{
      public static final int PEAKTIME = 1000; 
      boolean quittingTime = false;
      boolean lunchTime = false;
      boolean breakTime = false;
      boolean bos = false; // boss over shoulder
      
      
      public void run() {
        System.out.println("Start Work:");
        
        while (!quittingTime && !lunchTime && !breakTime){
          try{
            pretendToWork();
          }catch(BosException ex){
            System.out.println("Boss Alert!");
            try{
              work();
            }catch(AllClearException exx){
            }finally{
              if(!bos)System.out.println("All Cleared!");
            }
          }
        }
    
        if(quittingTime) System.out.println("Going home...");
        if(lunchTime) System.out.println("Gone for lunch...");
        if(breakTime) System.out.println("Taking a break...");
        
        //if(quittingTime || lunchTime || breakTime)
          System.out.println("Layback and Drink Beer...");
      }
      
      private void work() throws AllClearException {
        System.out.println("Working Hard!");
        while(bos){
          if(quittingTime || lunchTime || breakTime)
            throw new AllClearException();
          //System.out.println("Working Hard too...");
        }
      }
      
      private void pretendToWork() throws BosException {
        if(bos) throw new BosException();
        
        try {
          System.out.println("Sleeping on the job...");
          Thread.sleep(PEAKTIME);
        }catch(InterruptedException ex){
          throw new BosException();
        }
      }
    
    class BosException extends Exception{}
    class AllClearException extends Exception{}
    }
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #7
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    hehe!!! :D

    lol...

    you must be a brit :)

  8. #8
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

Similar Threads

  1. Coded Message... Help Please
    By maxpower1000sa in forum New To Java
    Replies: 2
    Last Post: 05-03-2009, 09:27 PM
  2. Color coded code
    By tim in forum Suggestions & Feedback
    Replies: 11
    Last Post: 06-29-2008, 10:35 AM
  3. Game of Life assignment
    By javan00b in forum New To Java
    Replies: 4
    Last Post: 04-28-2008, 06:49 AM
  4. Servlet Life Cycle
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-28-2007, 10:57 AM

Posting Permissions

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