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 / 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 / Person.java
Created January 19, 2017 17:17
This is a Parent super class. It will be extended by an Employee class.
public class Person {
// Fields or Instance variables
private String name;
private int age;
private boolean isFemale;
// Default contructor
public Person () {
name = "Steve";
@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);
public static void main(String[] args) {
// Variables
Scanner in = new Scanner(System.in);
int shapeLength;
String shape;
// Get length and shape from the user
System.out.print("Enter the length of the shape: ");
shapeLength = in.nextInt();
@dhust
dhust / Slider.java
Created March 3, 2016 14:39
Slider - event handling. One way to do it.
public class FXMLDocumentController implements Initializable {
// Needs to have @FXML otherwise you'll get errors and your program will not run
@FXML private Slider mySlider;
@Override
public void initialize(URL url, ResourceBundle rb) {
// You have three different variables available
// I used newValue which is the sliders value after it is moved
@dhust
dhust / ifCompoundAnd.java
Last active September 15, 2016 21:14
Using the AND Compound Logical Operator
public static void main(String[] args) {
// Variables
Scanner in = new Scanner(System.in);
int shapeLength;
String shape;
// Get length and shape from the user
System.out.print("Enter the length of the shape: ");
shapeLength = in.nextInt();