-
Coded Life Lesson :)
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);
}
}
-
Guess what this code would print out (imagining you made up the dependencies) :)
-
haha funny, but i'm a bit confused on the return type.
Code:
LifeLesson.java:3: incompatible types
found : void
required: People
somePeople = dropSomePeople
^
1 error
little logic bug...
Code:
if(compatibilityCheck(p) == false)
{
p.drop();
}[B] // should be moved below[/B]
p.size -= 1;
-
yeah true..
dropSomePeople() should return People type ...
Though why do you think I should move the that below???
-
-
Coded Life Lesson2 :)
this actually compiles (although w/ bugs...)
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{}
}
-
hehe!!! :D
lol...
you must be a brit :)
-
I said so just bcz of the "beer" part :)