Skip to content

Instantly share code, notes, and snippets.

View rjlutz's full-sized avatar

Bob Lutz rjlutz

  • Georgia Gwinnett College
  • Lawrenceville, GA
View GitHub Profile
@rjlutz
rjlutz / GreatestCommonDivisorMethod.java
Last active June 28, 2017 16:54
Methods (Chapter 6) -- examples from Liang Intro to Java Comprehensive 10e
import java.util.Scanner;
public class GreatestCommonDivisorMethod {
/** Main method */
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter two integers
System.out.print("Enter first integer: ");
@rjlutz
rjlutz / AnalyzeNumbers.java
Created July 17, 2017 20:44
Single Dimensional Arrays (Chapter 7) -- examples from Liang Intro to Java Comprehensive 10e
public class AnalyzeNumbers {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter the number of items: ");
int n = input.nextInt();
double[] numbers = new double[n];
double sum = 0;
System.out.print("Enter the numbers: ");
for (int i = 0; i < n; i++) {
@rjlutz
rjlutz / CircleWithPrivateDataFields.java
Created July 17, 2017 21:30
Objects (Chapter 9) -- examples from Liang Intro to Java Comprehensive 10e
public class CircleWithPrivateDataFields {
/** The radius of the circle */
private double radius = 1;
/** The number of the objects created */
private static int numberOfObjects = 0;
/** Construct a circle with radius 1 */
public CircleWithPrivateDataFields() {
numberOfObjects++;
@rjlutz
rjlutz / Bubble.pde
Last active August 17, 2017 13:11
A Really Simple Demonstration of Processing Using Active Mode and a Bubble Class
public class Bubble {
int x, y;
float r;
int incrX = (int) random(4,8);
int incrY = (int) random(2,8);
int red, green, blue, alpha;
public Bubble() {
x = (int)random(width);
@rjlutz
rjlutz / Circle.pde
Last active August 31, 2017 15:27
ITEC 2150 Chapter 11 Inheritance
public class Circle extends Shape {
private float r; // r is the radius of the circle
public Circle(float a, float b, float c) {
super(); // this is effectively like new Shape()
x = a;
y = b;
r = c;
// accept Shape's default of filled=false
@rjlutz
rjlutz / FIleOutputYahooStockReport.java
Last active September 21, 2017 20:35
File and Web IO Examples
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class FIleOutputYahooStockReport {
public static void main(String[] args) {
System.out.println("Starting ...");
@rjlutz
rjlutz / gist:4e2a84bf3000e5364dd4cb022750623e
Created October 10, 2017 22:02
fixerIO with retrofit notes
capture json from curl or postman, like
{
"base": "USD",
"date": "2017-10-10",
"rates": {
"CAD": 1.2499,
...
...
}
}
@rjlutz
rjlutz / PixabayResult.java
Created October 10, 2017 22:09
Pixabay starter code
package edu.ggc.lutz.pixabayretrofit;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
@rjlutz
rjlutz / ComputeFactorial.java
Created October 12, 2017 18:27
Abstract Classes and Interfaces (Chapter 18) -- examples from Liang Intro to Java Comprehensive 10e
import java.util.Scanner;
public class ComputeFactorial {
/** Main method */
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
System.out.print("Enter a non-negative integer: ");
int n = input.nextInt();
@rjlutz
rjlutz / AnyWildCardDemo.java
Created October 19, 2017 19:07
Java Generics (Chapter 19) -- examples from Liang Intro to Java Comprehensive 10e
public class AnyWildCardDemo {
public static void main(String[] args ) {
GenericStack<Integer> intStack = new GenericStack<Integer>();
intStack.push(1); // 1 is autoboxed into new Integer(1)
intStack.push(2);
intStack.push(-2);
print(intStack);
}