Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,637 members, 8,003,200 topics. Date: Friday, 15 November 2024 at 09:23 AM

Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! (12638 Views)

Python Or C++ Which Is Bera / Simple Code Challenge: C#, Java, C, C++ / How Do I Learn Web Application Using Python Or Other Softwares? (2) (3) (4)

(1) (Reply) (Go Down)

Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(m): 5:02am On Jun 28, 2013
Welcome!! : - )

Here is an attempt, using code snippets, to make you laugh and get a glimpse of good, bad, realities, experience, etc...

INFO
Please post VERY easily UNDERSTOOD code snippets; such that if you posted a Java snippet and I am not a Java programmer, I would still get your point
Pseudo-codes and flowcharts would also be great!!

--->Posting on an ADDITIONAL link to an uploaded code of yours to a syntax highlighting site such as http://www.pastebin.com is a +1!!
---> Post codes that:
----> depicts current situation of a government agency(please also post good side of them if you know!!)
----> models a government agency, firm, or government in the world...
----> models a business or industry in the world...
----> models a celebrity, footballer, or prominent persons
----> models your experience with a lady or ladies, guy or guys..
----> and anything that is worth posting!!!

EXAMPLE:
Nigerian Police Force...
Nigerian Army, Nigerian Courts, Nigerian Embassy, a nigerian leader, politician, banks, footballer
Microsoft, Dangote, Techno, NNPC, NSCDC, etc... ANYTHING Popular

I will try to post snippets in various languages once a week for the next few weeks! keep yours rolling!!! n put a smile on our faces!
***The next post depicts type of posts***

~Thanks.
Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(m): 5:12am On Jun 28, 2013
This is a model of typical Nigerian courts in Java... err... It might not be the same today or tomorrow.. grin

http://pastebin.com/e9pDBgW3

class Nig_Court
{
long _stolen_cash;
boolean bought_judgement;
public Nig_Court(long stolen_cash)
{
bought_judgement = false;
_stolen_cash = stolen_cash;
}

public final void buy_judgement(long bribe)
{
//if bribe is > N200,000 and its also greater than 4% of stolen_cash
if((bribe > 200000) && (bribe > (_stolen_cash * 4 / 100)))
{
bought_judgement = true;
}
}

public final String get_Verdict()
{
if(bought_judgement)
{
return "Case dismised for lack of evidence";
}
// < N10... doesnt deserve to live
else if(_stolen_cash < 10)
{
return "Jailed for life";
}
//N10 to N5,000 :
else if(_stolen_cash >= 10 && _stolen_cash < 5000)
{
return "Jailed for 70 years with hard labor";
}
//N5,000 to N100,000 :
else if(_stolen_cash >= 5000 && _stolen_cash < 100000)
{
return "Jailed for 15 years with mild labor";
}
//N100,000 to N1m :
else if(_stolen_cash >= 100000 && _stolen_cash < 1000000)
{
return "Jailed for 6 years without labor";
}
//N1m to N30m : Sizeable thief
else if(_stolen_cash >= 1000000 && _stolen_cash < 30000000)
{
return "Jailed for 2 months with option of 10% fine: "
+ Long.toString(_stolen_cash * 10 / 100);
}
//N30m to N500m : big thief
else if(_stolen_cash >= 30000000 && _stolen_cash <= 500000000)
{
return "Rest for 3 weeks Sir/Ma with option of 6% fine: "
+ Long.toString(_stolen_cash * 6 / 100);
}

//#Oga @ The Top: ahhh, somebody with goodwill for the nation
//_stolen_cash > N500m ...
else
{
return "Discharged and Acquitted!... Sorry for wasting your ample time"
+ "we thank you for your Patience with us Sir/Ma";
}
}
}

2 Likes

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 9:48pm On Jun 28, 2013

//A love code program in c#
using heart;
namespace MissYou
{
class Love
{
static void Main()
{
Console.WriteLine("MissYou"wink;

Console.writeLine("NeverLetyouGo"wink;
Console.ReadKey();
}
}
}
Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 9:52pm On Jun 28, 2013
smiley

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 9:56pm On Jun 28, 2013
cheesy

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 9:58pm On Jun 28, 2013
sad

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 10:00pm On Jun 28, 2013
tongue

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by Javanian: 10:01pm On Jun 28, 2013
grin

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by spikesC(m): 10:14pm On Jun 28, 2013
I was looking for this thread since....... cheesy

1 Like

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by WhiZTiM(m): 1:44am On Jun 29, 2013
hmmn... I can see someone missing a loved one.

haha... nice imgs

here is another.... (a little bit technical)
http://pastebin.com/SemMk98v


//Pseudo-code for Microsoft Windows 95
//---idea---TiM

//boot the system
init __boot;

//load stuff for keyboards, file system drivers, and Display
init __load_basic_drivers;

//prepare BoSD
init __prepare__ BLUE_SCREEN_OF_DEATH;

//enter event loop
while(!crashed)
{
sleep(1300); //milisecs

load_kernel_sevices();

if(system_still_running)
{
try
{
kernel_load( all(system_programs) );

kernel_unload( most_useful(system_programs) );

if(!unloaded(last_kernel_instruction)) throw Exception;
}
catch(Errors)
{ fire(BLUE_SCREEN_OF_DEATH); }
}

kernel_load( Graphics );
kernel_load( Windows_Explorer );

kernel_init( set( cpu_execution_speed( random % 100 ) ) )

bool legal = verify(Microsoft.Paid.isTrue());

if(legal)
{
call( persuading_daemon(ask_for_more_money) )
}
else
{
kernel_unload(kernel, silently=true, gradually=yes);
}

if(system_is_ok)
{
attempt(crash);
}

if(system_survived_last_crash_attempt)
{
kernel_load( all(backdoors_and_memory_exploits) );

init __set(BLUE_SCREEN_OF_DEATH, fire(in(2000, seconds)));
}

if(system.isIdle())
{
kernel_init( all( sleep(hardware) && sleep(software) ) );
kernel_interrupt( DISABLE_ALL );

set( kernel.neverWakeUp = true );
}

while(still_not_crashed)
{
do (NOTHING for random.minutes)
wait_for_user_events();

attempt(crash) && break;
}

if(is lucky)
{
kernel_programs_manager.set( FAIL );
load( all(programs), haphazardly );
}

if(execution_reached_this_point)
{
kernel_init( kill_All_useful_programs );

fire(BLUE_SCREEN_OF_DEATH);

kernel_unload( kernel );
}

assert(system_is_DEAD);
}

1 Like

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by kambo(m): 6:01am On Jun 29, 2013
in the shadows of an old thread!!? angry sad sad angry sad


class Express
{
public static Exception displeasure()
{
throw new Exception();
}
}

class Complain
{
public Exception about(final String theGripe)
{
throw new Exception(theGripe);
}
}

public class Client
{
public Client(final Object argument)throws Exception
{
if(valid(argument))
// do nothing
else Express.displeasure();
}

public boolean valid(final Object o){}
}


interface ListWalker
{
public boolean futureBright()
public boolean pastBeckons()
public void moveForward();
public void backtrack();
}

class List implements ListWalker{}

Class Client
{
List<Object> list = new List<Object>();
Iterator johnny = list.getWalker();
//.....

while(johnny.futureBright())
{
johnny.moveForward();
else
johnny.backtrack();
}

}

Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by danvery2k6(m): 2:35pm On Jul 06, 2013



package Hot.thoughts;

/**
*
* @author HP USER
*/
public class PrettyGirl {

private String jewelry;
private String boyfriend;
private double account;
private double cost;
/* Thi rarely happens, but it is true that some
* pretty girls actually go withut a boyfriend
* and are content that way. Quite rare I must
* admit though. So as tribute to "that Kind" of
* pretty girl I initialise this cos=nstructor
* without a boyfriend parameter
*/

public PrettyGirl() {
}
/* But of course the pretty girls, I mean the real
* ones have something in common. No offense meant.
* So here we go.
*/

public PrettyGirl(String jewelry, String boyfriend) {

this.boyfriend = boyfriend;
this.jewelry = jewelry;

} // end two argument constructor

/* Well, as we all mightn have known, either
* learning it the hard way or through others
* (the wise, or should I say, the fortunate
* ones), Beign a boyfriend to a pretty girl
* requires that certain parameters be in place.
* Here is my little simulation of those parameters
*/
public void setAccount(double accountStatement) {

/* certain account figures are vompletely acceptable,
* others raise concerns whereas others are completely
* unacceptable. Read this:
*/
boolean validAccount = isValidAccount(accountStatement);
if (validAccount == true) {
this.account = accountStatement;
}
}

public double getAccount() {
return account;
}

public void setBoyfriend(String boyfriend) {
this.boyfriend = boyfriend;
}

public String getBoyfriend() {
return boyfriend;
}

/*A little prying is done, either directly, for the rude
* ones, or indirectlly for the sensible ones, before
* final consent and acceptance is granted. here is to
* validate that your bank statement agrees.
*/
public boolean isValidAccount(double accountStatement) {
boolean isValid = false;
if (accountStatement != 0.00 && accountStatement >= 500000.00) {
isValid = true;
}
return isValid;
}

/* after boyfreind has been gotten, the following activities ensue
* thee benefits of which range from total bankruptcy, if you are not carefull
* to a collapse of the relationship for the real "bad guy"
*
*
* I put the return type void because, surely you get nothing from this
*/
public void setJewelry(double cost, String jewelry) {
this.cost = (cost >= 10000.00) ? cost : 0.00;
this.jewelry = jewelry;

/* setting cost to 0.00 in this case means that the
* jewelry cannot be bought. "Too cheap, not good"
*/
}

public String getJewelry() {

return jewelry;
}
/* time to do a little shopping. And trust me,
* this is the real annoying part where if you
* are not the patient tyoe, you just give
* up and blow the relationship into the winds
*/

public String goShopping(double minimumCash) {
String reaction = null;
if (minimumCash >= 50000.00) {

reaction = "Ok. Manageable, I will just manage it";
} else {
reaction = "What do you take me for. Do you want me to go "
+ "buy some peanuts? Take your filthy money";
// throws money at you.
}
return String.format("%s", reaction);
}
/* There are an endless litany of woes to discuss. I therefore make this
* piece "Open Source". You guys can help me make it complete.
*
* And to the ladies, No offence meant. ***Winks***
*/
}



Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by ensodev(m): 8:43pm On Dec 04, 2018
danvery2k6:



package Hot.thoughts;

/**
*
* @author HP USER
*/
public class PrettyGirl {

private String jewelry;
private String boyfriend;
private double account;
private double cost;
/* Thi rarely happens, but it is true that some
* pretty girls actually go withut a boyfriend
* and are content that way. Quite rare I must
* admit though. So as tribute to "that Kind" of
* pretty girl I initialise this cos=nstructor
* without a boyfriend parameter
*/

public PrettyGirl() {
}
/* But of course the pretty girls, I mean the real
* ones have something in common. No offense meant.
* So here we go.
*/

public PrettyGirl(String jewelry, String boyfriend) {

this.boyfriend = boyfriend;
this.jewelry = jewelry;

} // end two argument constructor

/* Well, as we all mightn have known, either
* learning it the hard way or through others
* (the wise, or should I say, the fortunate
* ones), Beign a boyfriend to a pretty girl
* requires that certain parameters be in place.
* Here is my little simulation of those parameters
*/
public void setAccount(double accountStatement) {

/* certain account figures are vompletely acceptable,
* others raise concerns whereas others are completely
* unacceptable. Read this:
*/
boolean validAccount = isValidAccount(accountStatement);
if (validAccount == true) {
this.account = accountStatement;
}
}

public double getAccount() {
return account;
}

public void setBoyfriend(String boyfriend) {
this.boyfriend = boyfriend;
}

public String getBoyfriend() {
return boyfriend;
}

/*A little prying is done, either directly, for the rude
* ones, or indirectlly for the sensible ones, before
* final consent and acceptance is granted. here is to
* validate that your bank statement agrees.
*/
public boolean isValidAccount(double accountStatement) {
boolean isValid = false;
if (accountStatement != 0.00 && accountStatement >= 500000.00) {
isValid = true;
}
return isValid;
}

/* after boyfreind has been gotten, the following activities ensue
* thee benefits of which range from total bankruptcy, if you are not carefull
* to a collapse of the relationship for the real "bad guy"
*
*
* I put the return type void because, surely you get nothing from this
*/
public void setJewelry(double cost, String jewelry) {
this.cost = (cost >= 10000.00) ? cost : 0.00;
this.jewelry = jewelry;

/* setting cost to 0.00 in this case means that the
* jewelry cannot be bought. "Too cheap, not good"
*/
}

public String getJewelry() {

return jewelry;
}
/* time to do a little shopping. And trust me,
* this is the real annoying part where if you
* are not the patient tyoe, you just give
* up and blow the relationship into the winds
*/

public String goShopping(double minimumCash) {
String reaction = null;
if (minimumCash >= 50000.00) {

reaction = "Ok. Manageable, I will just manage it";
} else {
reaction = "What do you take me for. Do you want me to go "
+ "buy some peanuts? Take your filthy money";
// throws money at you.
}
return String.format("%s", reaction);
}
/* There are an endless litany of woes to discuss. I therefore make this
* piece "Open Source". You guys can help me make it complete.
*
* And to the ladies, No offence meant. ***Winks***
*/
}





Am sorry.. i just want to ask..WHAT IS THIS...SHEWWWWW!!!!!!!!
Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by ensodev(m): 8:45pm On Dec 04, 2018
Wait ensodev this are codes...try to digest it you might make some sense out of it.
Re: Programming FUN With Code Snippets!! -C++,C#, Java,php,python Or Any Language!! by ensodev(m): 8:48pm On Dec 04, 2018
Ok...sorry guy i brought this out just for the love i use to have for c++ then not anymore but more respect to the guy that stated this trend...

Re-candle it if you know c++ abeg

(1) (Reply)

Nigerian, Kehinde Adeyemi, Among Best Global IT Developers / Data Scientists In Nigeria, Lets Talk / Integrating Your Website With Interswitch Payment Gateway For Beginners

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 46
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.