Results 1 to 8 of 8
Thread: Coded Life Lesson :)
- 05-05-2009, 12:38 AM #1
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
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); } }
- 05-05-2009, 12:40 AM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
Guess what this code would print out (imagining you made up the dependencies) :)
- 05-05-2009, 02:37 AM #3
haha funny, but i'm a bit confused on the return type.
little logic bug...Java Code:LifeLesson.java:3: incompatible types found : void required: People somePeople = dropSomePeople ^ 1 error
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)
- 05-05-2009, 12:15 PM #4
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
yeah true..
dropSomePeople() should return People type ...
Though why do you think I should move the that below???
- 05-06-2009, 02:39 AM #5
- 05-28-2009, 10:09 PM #6
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)
- 07-29-2009, 08:08 PM #7
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
hehe!!! :D
lol...
you must be a brit :)
- 07-29-2009, 08:16 PM #8
Senior Member
- Join Date
- Jan 2009
- Posts
- 119
- Rep Power
- 0
Similar Threads
-
Coded Message... Help Please
By maxpower1000sa in forum New To JavaReplies: 2Last Post: 05-03-2009, 08:27 PM -
Color coded code
By tim in forum Suggestions & FeedbackReplies: 11Last Post: 06-29-2008, 09:35 AM -
Game of Life assignment
By javan00b in forum New To JavaReplies: 4Last Post: 04-28-2008, 05:49 AM -
Servlet Life Cycle
By Java Tip in forum Java TipReplies: 0Last Post: 11-28-2007, 09:57 AM


LinkBack URL
About LinkBacks

Bookmarks