Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let's make some simple programs!

Name: Anonymous 2010-05-08 4:03

Because I know that half of /prog/ can't program, let's make simple ones!

---------------------- MySavings.java ----------------------

/**
 * @(#)MySavings.java
 *
 * MySavings application
 *
 * @author Tim H
 * @version 1.00 2010/5/7
 */
 
import java.util.Scanner;

public class MySavings {
   
    public static void printInterface() {
        System.out.print(
            "1. Show total in bank.\n" +
            "2. Add a penny.\n" +
            "3. Add a nickel.\n" +
            "4. Add a dime.\n" +
            "5. Add a quarter.\n" +
            "6. Take money of out bank.\n" +
            "Enter 0 to quit.\n" +
            "Enter your choice: "
            );
    }
   
    public static void main(String[] args) {
       
        Scanner input = new Scanner(System.in);
        int choice = 1;
        int moneyChoice = 0;
        double amount = 0;
       
        PiggyBank bank = new PiggyBank();
       
        while(choice > 0){
            printInterface();
            choice = input.nextInt();
           
            switch(choice){
                case 0: System.out.println("(c)Tim H 2010\nHave a nice day!"); break;
                case 1: System.out.println("Your current total is: " + bank.GetTotal()); break;
                case 2:
                case 3:
                case 4:
                case 5: moneyChoice = choice - 2; bank.AddMoney(moneyChoice); break;
                case 6:
                    System.out.print("Enter the amount you wish to withdraw: ");
                    amount = input.nextDouble();
                    bank.SubtractTotal(amount);
                    break;
                default:
                    System.out.println("Please enter a choice between 1-6!");
                    break;
            }
               
        }

---------------------- PiggyBank.java ----------------------


class PiggyBank {
    double total;
   
   
    public PiggyBank(){
        total = 100;
    }
   
    public void AddMoney(int choice){
        switch (choice) {
            case 0:
                total += 0.01;
                System.out.println("One penny added to total!\nYour total is now: " + total);
                break;
            case 1:
                total += 0.05;
                System.out.println("One nickel added to total!\nYour total is now: " + total);
                break;
            case 2:
                total += 0.10;
                System.out.println("One dime added to total!\nYour total is now: " + total);
                break;
            case 3:
                total += 0.25;
                System.out.println("One quarter added to total!\nYour total is now: " + total);
                break;
           
        }
    }
   
    public double GetTotal(){
        return total;
    }
   
    public void SubtractTotal(double amount){
        total -= amount;
        System.out.println(amount + " has been subtracted from your total!\nYour total is now: " + total);
    }
}

    }
   
}

Name: Anonymous 2010-05-09 15:31

Close call! We almost had an interesting discussion here with >>33,35-36. Thanks for nipping that in the bud, >>37,40-kun.

Name: Anonymous 2010-05-09 16:08

Does anyone have anything on designing a better RNG?

Name: Anonymous 2010-05-09 16:17

>>42
TAoCP for PRNGs. RNG - use some really random data, like radiation measurements/atmospheric noise or whatever.

Name: Anonymous 2010-05-09 17:13

install python if you dont have it, then install pygame,
then save this image: http://img525.imageshack.us/img525/1223/balll.gif

copy this code and save it with the .py extention in the same place you saved the ball image and run it (I recommend using the pyscripter IDE over IDLE)

import sys, pygame
pygame.init()

size = width, height = 320, 240
speed = [1, 1]
black = 0, 0, 0

screen = pygame.display.set_mode(size)

ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()

    ballrect = ballrect.move(speed)
    if ballrect.left < 0 or ballrect.right > width:
        speed[0] = -speed[0]
    if ballrect.top < 0 or ballrect.bottom > height:
        speed[1] = -speed[1]

    screen.fill(black)
    screen.blit(ball, ballrect)
    pygame.display.flip()

Name: Anonymous 2010-05-09 19:51

Name: Anonymous 2010-11-17 20:14

OP is a flaming black homosexual.

Name: Anonymous 2010-11-17 23:03

>>46
your a fucking faggot

Name: Anonymous 2010-11-18 13:24

>>44
Rewrite that with pyglet and we'll talk.

Name: Anonymous 2010-11-18 15:19


#Another Version of the Sieve of Eratosthenes
l, n = [], 100
for i in range(n): l.append(True)
i = 2
while i * i <= n:   
    if l[i-1] == True:
        #if not i%2:
        for j in range(i*i, n+1, i): l[j-1] = False                   
    i += 1
i = 2
while i <= n:
    if l[i-1] == True : print(i, " ", end = "")
    i += 1

Name: VIPPER 2010-11-18 16:37

#!/bin/perl

my $JEWS = "";
print $JEWS .= "JEWS " while 1;
print "this message will never be printed, prepare your anus for VIPPER\n";

#JEWS

Name: Anonymous 2010-11-18 21:49

>>50
/bin/perl
Faggot.

Name: barbour mens classic duffle 2011-12-01 22:42

There are many brands of <a href="http://www.barbourjackets-uk.org/"><strong>barbour fusilier</strong></a> in the market today. Each of the brand promises to bring out something new to the customers.

Name: Anonymous 2011-12-02 13:29

>>55
wow amazing dubs bro

Name: Anonymous 2011-12-02 14:11

hehe thanks >>54

Name: Anonymous 2011-12-02 16:13

>>55
lol np ^^;

Name: Anonymous 2011-12-02 16:33

#!/bin/clojure
(assert (eq lisp shit))

Name: Anonymous 2011-12-02 18:16

[code]print "Hello World![\code]

Name: Anonymous 2011-12-02 22:59


10 LET A=0
20 LET A=A+1
30 IF A MOD 15=0 THEN 80
40 IF A MOD 3=0 THEN 100
50 IF A MOD 5=0 THEN 120
60 GOTO 140
80 PRINT"FIZZBUZZ"
90 GOTO 20
100 PRINT"FIZZ"
110 GOTO 20
120 PRINT"BUZZ"
130 IF A<100 THEN 20
131 SLEEP
132 END
140 PRINT A
150 GOTO 20

Name: Anonymous 2011-12-02 23:26

<?function f($x){return(!$x)?1:$x*f($x-1);}?>

Name: Anonymous 2011-12-03 7:56


#t ; Enjoy a Scheme/Python quine
'''() ;
(print "Hello from Scheme!")
; '''
(); print "Hello from Python!"


Try it at http://repl.it

Name: Anonymous 2011-12-03 8:04

The following is valid C, Sepples, Python, Ruby and Brainfuck program that prints out the name of the language it's run as:

#ifdef v 
'''>+++>"egnufeB":v<++++ 
+[<++++++++>-][v:,_@]<++ 
.>+++++++[<++++>  ^<+++> 
-]<-.>++++[<---->-]<-.>+ 
++[<+++>-]<-.>++[<++>-]< 
+.>+++[<--->-]<+.>++++[< 
++++>-]<-.>++++[<---->-] 
<--.>+++[<+++>-]<-> 
#endif 
#include <stdio.h> 
int main(){ 
    printf("C"); 
#ifdef __cplusplus 
    printf("++"); 
#endif 
    return 0; 

//'''"#{puts 'Ruby';exit}"; print 'Python'

Name: Anonymous 2011-12-03 8:06

>>62
*and Befunge

Name: Anonymous 2011-12-03 8:21

>>62
The following is valid C, Sepples
False. The first #ifdef block contains invalid preprocessing tokens.

Name: Anonymous 2011-12-03 8:27

>>64
Which will be promptly ignored.

Name: Anonymous 2011-12-03 8:29

>>65
The norm doesn't require the parser to skip unused blocks; undefined behaviourdesu.

Name: Anonymous 2011-12-03 8:32

>>66
Well, okay.
The following is a C, Sepples, Python, Ruby and Brainfuck program ...
If it doesn't work, your compiler is shit.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List