Skip to content

Instantly share code, notes, and snippets.

@JHarry444
JHarry444 / Animal.Java
Created December 12, 2018 15:33
Inheritance - Animal demo
package animals;
public abstract class Animal {
private int bones;
private int age;
private String colour;
private int size;
private int weight;
private String diet;
@JHarry444
JHarry444 / Animal.java
Created January 22, 2019 15:05
OOP principles - Animal example
package main;
public abstract class Animal {
public abstract void eat();
public abstract void sleep();
private String colour;
private int noOfLegs;
@JHarry444
JHarry444 / Blackjack.java
Last active May 16, 2019 08:51
TDD example
package main;
public class Blackjack {
public static int play(int hand1, int hand2) {
if (hand1 > 21 && hand2 > 21) {
return 0;
} else if (hand1 > 21) {
return hand2;
} else if (hand2 > 21) {
return hand1;
let xhr = new XMLHttpRequest();
xhr.open("GET", "api/movie/getAllMovies");
xhr.onload = () => {
document.write(xhr.responseText);
}
xhr.send();
let xhr = new XMLHttpRequest();
xhr.open("GET", "api/movie/getAllMovies");
xhr.onload = () => {
document.write(xhr.responseText);
}
xhr.send();
package main;
public class Hello {
public void print() {
System.out.println("Hello World!");
}
public String returnHello() {
return "HelloWorld!";
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// list = list.stream().filter(x -> x % 2 != 0 && x > 6 && x < 9).collect(Collectors.toList());
// list = list.stream().map(x -> x * 10).collect(Collectors.toList());
// System.out.println(list.stream().reduce((x, y) -> Math.max(x, y)).get());
// list.stream().reduce(Math::max).get();
System.out.println(list);
public void oneToThousand() {
String[] units = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
String[] tens = { "", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
String[] hundreds = { "", "One Hundred", "Two Hundred", "Three Hundred", "Four Hundred", "Five Hundred",
"Six Hundred", "Seven Hundred", "Eight Hundred", "Nine Hundred" };
for (int i = 0; i < 1000; i++) {
if (i > 99 && i % 100 > 19) {
System.out.println("" + hundreds[i / 100] + " " + tens[i / 10 % 10] + " " + units[i % 10]);
} else if (i > 99) {
package main;
public abstract class Animal {
private int numLimbs;
private int numEyes;
public Animal(int numLimbs, int numEyes) {
this.numLimbs = numLimbs;
this.numEyes = numEyes;
}
package main;
public class DogShow {
public static String exclude(int place) {
StringBuilder output = new StringBuilder();
for (int i = 1; i <= 100; i++) {
if (i != place) {
output.append(i);
if (i > 3 && i < 21) {
output.append("th");