Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
gitaficionado / PairOfDie
Last active December 15, 2016 17:22
Programming Project 4.5
package chapter4;
public class PairOfDie {
private int _dieSides1;
private int _dieSides2;
private int _die1;
private int _die2;
PairOfDie(){
@gitaficionado
gitaficionado / BoxCars
Created December 15, 2016 17:57
Programming Project 4..4
package chapter4;
import java.util.*;
public class BoxCars {
public static void main (String args[]) {
PairOfDie dice = new PairOfDie();
________________________ // define integer called boxCarCounter and set it equal to zero
for(int i = 0; i < 1000; i++){
dice.rollBothDie();
if(dice.getDieTotal() == 12)
boxCarCounter ++;
@gitaficionado
gitaficionado / DrawFigureOne
Last active March 21, 2017 18:16
Program version 2
public class FigureDemo {
public static void main(String[] args) {
System.out.println(" ______");
System.out.println(" / \\");
System.out.println("/_________");
System.out.println("\\ /");
System.out.println(" \\______/");
System.out.println();
System.out.println("\\ /");
public class ComputerPlayer extends Player {
public ComputerPlayer(String name, PairOfDice pod) {
super(name, pod);
}
@Override
public boolean rollAgain() {
if(sk.getRoundTotal() < 20) {
@gitaficionado
gitaficionado / memmory_puzzle_buggy1
Created December 19, 2016 19:58
This version of the game has a bug in it. See if you can figure out how to fix it. Bug Description: Graphics are messed up.
# This version of the game has a bug in it. See if you can figure out how to fix it.
# Bug Description: Graphics are messed up.
# Memory Puzzle
# By Al Sweigart al@inventwithpython.com
# Released under a "Simplified BSD" license
import random, pygame, sys
from pygame.locals import *
@gitaficionado
gitaficionado / memmory_puzzle_buggy5
Created December 19, 2016 23:05
Try out to understand how the code works is to intentionally break it by commenting out random lines. Doing this to some of the lines will probably cause a syntactic error that will prevent the script from running at all. But commenting out other lines will result in weird bugs and other cool effects. Try doing this and then figure out why a pro…
# This version of the game has a bug in it. See if you can figure out how to fix it.
# Bug Description: NameError: global name 'getRandomizedBoard' is not defined
# Memory Puzzle
# By Al Sweigart al@inventwithpython.com
# Released under a "Simplified BSD" license
import random, pygame, sys
from pygame.locals import *
@gitaficionado
gitaficionado / Mirror.java
Last active December 21, 2016 01:50
Partial solution for Mirror.java
Draws a scalable mirror
Goal (size 3):
#============#
| <><> |
| <>....<> |
|<>........<>|
|<>........<>|
| <>....<> |
/**
The DrawingPanel class provides a simple interface for drawing persistent
images using a Graphics object. An internal BufferedImage object is used
to keep track of what has been drawn. A client of the class simply
constructs a DrawingPanel of a particular size and then draws on it with
the Graphics object, setting the background color if they so choose.
<p>
To ensure that the image is always displayed, a timer calls repaint at
regular intervals.
@gitaficionado
gitaficionado / MysteryNumber
Last active December 21, 2016 16:44
Print mystery to the console window using the format shown in the the template.
public static void main(String[] args)
{
int mystery = 100;
mystery = mystery + ___;
mystery = mystery - ___;
mystery = mystery ______;
mystery = mystery + 1;
mystery = mystery _____;
mystery = mystery + 15;
@gitaficionado
gitaficionado / GraphicsIntro
Last active December 21, 2016 18:27
Starter File for Graphics Introduction
// Introduction to DrawingPanel, Graphics, Color
import java.awt.*; // to use Graphics, Color
public class GraphicsIntro {
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(300, 200);