Skip to content

Instantly share code, notes, and snippets.

@dhust
dhust / comments.py
Created July 24, 2018 15:56
Commenting
# This is a comment
<script id="jsbin-javascript">
var number = 5;
var text = '5';
console.log(number);
console.log(text);
console.log(number == text);
console.log(number === text);
@dhust
dhust / and.java
Last active May 23, 2017 00:20
Operators - && (AND)
public static void main(String[] args) {
int a = 14;
if ( (a > 0) && (a < 10) ) {
System.out.println("a is between 0 and 10.");
}
else if (a >= 10 && a < 20) {
System.out.println("a is between 10 and 20, including 10.");
}
@dhust
dhust / IfStrings.java
Last active May 23, 2017 00:15
If statement comparing Strings
public static void main(String[] args) {
// Variables
Scanner input = new Scanner(System.in);
String name;
// Ask and get the user's answer
System.out.print("Enter your name: ");
name = input.next();
@dhust
dhust / IfNumbers.java
Last active May 23, 2017 00:08
If statement comparing numbers
public static void main(String[] args) {
// Variables
Scanner input = new Scanner(System.in);
int age;
// Ask a question and save their answer
System.out.print("Enter your age: ");
age = input.nextInt();
@dhust
dhust / methodBasic.java
Last active May 20, 2017 00:39
An example of a basic method
public static void main(String[] args) {
// Three "calls" to the method 'printStuff'
printStuff();
printStuff();
printStuff();
}
// This code only runs if it's "called"
public static void printStuff () {
@dhust
dhust / NotEncapsulation.java
Last active January 20, 2017 13:24
Encapsulation non-example. There's no setter for the age & the age is public, so anyone can change it to anything they want, even invalid values.
public class EncapsulationNonExample {
// variables
public int age;
// default constructor
public EncapsulationNonExample() {
}
@dhust
dhust / Encapsulation.java
Last active January 20, 2017 13:23
Encapsulation example. Need to make the age variable private so no one can directly change it, and the setAge() method is checking for a valid age.
public class EncapsulationExample {
// variables
private int age;
// default constructor
public EncapsulationExample() {
}
@dhust
dhust / Test.java
Last active January 19, 2017 20:35
This class is testing the Person super class and the Employee subclass.
public class Testing {
public static void main(String[] args) {
Person steve = new Person();
steve.info();
Person jessica = new Person("Jessica", 23, true);
jessica.info();
@dhust
dhust / Employee.java
Last active January 19, 2017 17:18
This is the Employee subclass. It will "extends" the Person super class.
public class Employee extends Person {
// default constructor
public Employee() {
}
// constructor with arguments
public Employee(String name, int age, boolean isFemale) {
super(name, age, isFemale);