Skip to content

Instantly share code, notes, and snippets.

@jimmykurian
jimmykurian / TicTacToeBoard.java
Created February 3, 2012 21:39
A Java program named TicTacToeBoard that prints a tic-tac-toe game board.
//TicTacToeBoard.java - Jimmy Kurian
class TicTacToeBoard {
public static void main(String[] args) {
System.out.println("+---+---+---+");
System.out.println("| | | |");
System.out.println("+---+---+---+");
System.out.println("| | | |");
System.out.println("+---+---+---+");
System.out.println("| | | |");
@jimmykurian
jimmykurian / Sum10.java
Created February 3, 2012 21:41
A Java program named Sum10 that computes the sum of the first ten positive integers 1+2+ … +10. Print the result to the standard output.
//Sum10.java - Jimmy Kurian
class Sum10{
public static void main(String[] args) {
int s = 1+2+3+4+5+6+7+8+9+10;
System.out.println(s);
}
}
@jimmykurian
jimmykurian / SavingsAccount.java
Created February 3, 2012 21:45
A Java program that creates a Bank Account with withdraw, deposit, and intrest functions. And a tester class, that tests the SavingsAccount class.
//SavingsAccount.java - Jimmy Kurian
public class SavingsAccount
{
private double balance;
private double interest;
public SavingsAccount()
{
balance = 0;
@jimmykurian
jimmykurian / OlympicRingComponent.java
Created February 3, 2012 21:54
A Java program that draws the Olympic rings. The other program displays the Olympic rings.
//OlympicRingComponent.java - Jimmy Kurian
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
public class OlympicRingComponent extends JComponent
{
@jimmykurian
jimmykurian / DataSet.java
Created February 3, 2012 22:01
A class named DataSet that computes the sum, the average, the largest and smallest values of a sequence of integers without the use of an array. DataSetTester.java test the DataSet class.
//DataSet.java - Jimmy Kurian
public class DataSet
{
private double sum;
private int count;
private int largest;
private int smallest;
@jimmykurian
jimmykurian / Card.java
Created February 3, 2012 22:04
A Java program that takes user input describing a playing card in shorthand notation.
//Card.java - Jimmy Kurian
public class Card
{
private String denom;
private String suite;
private String String1;
private String String2;
public Card(String s1)
@jimmykurian
jimmykurian / PrimeNumbers.java
Created February 3, 2012 22:11
A Java program that prompts the user for an integer and then prints out all prime numbers up to that integer.
//PrimeNumbers.java - Jimmy Kurian
import java.util.Scanner;
class PrimeNumbers
{
public static void main(String[] args)
{
int n;
int p;
@jimmykurian
jimmykurian / CheckerBoard.java
Created February 3, 2012 22:12
A graphical application that displays a 8x8 chess board with 64 squares, alternating black and white.
//CheckerBoard.java - Jimmy Kurian
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Color;
public class CheckerBoard extends JFrame
{
public void paint(Graphics g)
@jimmykurian
jimmykurian / RegularExpressions.py
Created February 6, 2012 16:39
A Python program, that tests regular expressions.
#RegularExpressions.py - Jimmy Kurian
import re
for test_string in ['555-1212', 'ILL-EGAL']:
if re.match(r'^\d{3}-\d{4}$', test_string):
print test_string, 'is a valid US local phone number'
else:
print test_string, 'rejected'
@jimmykurian
jimmykurian / BankAccount.py
Created February 6, 2012 16:41
A BankAccount program with classes, written in Python.
# BankAccount.py - Jimmy Kurian
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
def overdrawn(self):