Skip to content

Instantly share code, notes, and snippets.

@rebekah
rebekah / Game.java
Last active December 12, 2023 07:43
package tetris;
import java.awt.*;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.IOException;
import java.util.*;
import java.lang.Thread;
import javax.sound.sampled.*;
import java.awt.*;
import java.util.*;
import java.awt.Color;
import java.util.Random;
public class SandLab
{
public static void main(String[] args)
{
SandLab lab = new SandLab(120, 80);
@rebekah
rebekah / TruckDemo.java
Created October 29, 2023 20:12
Basic Inheritance
//Vehicle.java
public class Vehicle {
String color;
}
//Truck.java
public class Truck extends Vehicle {
int bedLength;
}
class Rational{
private int numerator;
private int denominator;
int getNumerator() {
return numerator;
}
int getDenominator() {
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
public class SplitWord {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println(
"This program will split those characters into array items delimited by the comma.\n" +
import java.util.Arrays;
import java.util.Scanner;
import java.util.Random;
public class HangMan {
final String[] words = {
"abandon",
"cabaret",
"eagerly",
"habitat",
"iceberg",
public class MergeArrays {
public static void main(String[] args) {
int[][] arrays = {{1,2,3},{14,15,16,17}};
int mergedArrayLen = arrays[0].length + arrays[1].length;
int[] mergedArray = new int[mergedArrayLen];
int mergedArrayIndex = 0;
for(int i = 0; i < arrays.length; i++){
for(int j = 0; j < arrays[i].length; j++) {
mergedArray[mergedArrayIndex] = arrays[i][j];
mergedArrayIndex++;
import java.util.Scanner;
import java.util.ArrayList;
public class Metrics {
public static void main(String[] args) {
ArrayList<Integer> hieghtInInches = new ArrayList<Integer>();
ArrayList<Integer> weightInPounds = new ArrayList<Integer>();
String request = "Please add height(in inches) and weight(in pounds) for each " +
"person seperated by a colon. When you are done enter the letter Q.";
System.out.println(request);
class MultiDimensionalArray {
public static void main(String[] args){
int[][] arrayOfArrays = new int[10][];
for (int i = 0; i < 10; i++){
arrayOfArrays[i] = new int[i + 1];
for(int j = 0; j < i + 1; j++){
arrayOfArrays[i][j] = j;
}
}
public class MyClass {
public static void main(String args[]) {
int numerator1 = 3;
int denominator1 = 5;
int numerator2 = 2;
int denominator2 = 15;
numerator1 = numerator1 * denominator2;
numerator2 = numerator2 * denominator1;