Skip to content

Instantly share code, notes, and snippets.

@benfb
benfb / BBaileyBook.java
Created October 2, 2012 15:05
BBaileyBook
public class BBaileyBook //the name of the class should be "Book"
{
private String bookName; //the variables need to be private because they are instance variables
private int bookISBN; //you don't need to assign default values because they are assigned in the constructors
public BBaileyBook(){ //default constructor named book that should provide default values ("" and 0, respectively) for the instance variables
bookName = ""; //when no arguments are passed, the title defaults to ""
bookISBN = 0; //when no arguments are passed, the ISBN defaults to 0
}
public BBaileyBook(String name, int isbn){ //creates a book object and assigns the name and isbn arguments to the instance variables
@benfb
benfb / BBaileyBookRunner.java
Created October 2, 2012 15:08
BBaileyBookRunner
public class BBaileyBookRunner
{
public static void main(String args[])
{
BBaileyBook textBook = new Book(); //creates a new object textbook of class Book
textBook.setName("Scooby Doo"); //sets the name of textBook to "Scooby Doo"
textBook.getName(); //println would print default values if the default constructor was called. In this case, the output matches the input
System.out.println(textBook); //What does this line do? It calls the .toString() method
BBaileyBook theStranger = new Book("The Stranger", 123456789); //creates a new book with title "The Stranger" and ISBN 123...
System.out.println(textBook.getName); //prints textBook's name
@benfb
benfb / InOrder.java
Created October 7, 2012 18:12
inOrder
public class InOrder //creates the InOrder class
{
private int numOne; //creates the instance variable numOne
private int numTwo; //creates the instance variable numTwo
private int numThree; //creates the instance variable numThree
boolean b = false; //creates the boolean value b (not instance)
public InOrder() //default constructor
{ //assigns default values to instance variables
numOne = 0;
@benfb
benfb / InOrderRunner.java
Created October 7, 2012 18:13
inOrderRunner
// name:
// purpose: determine whether three input values are in order: x <= y <= z
import java.util.*; //for our purposes, imports scanner
public class InOrderRunner //creates the InOrderRunner class
{
// main(): program starting point
public static void main( String[] args )
{
@benfb
benfb / CalculatorRunner.java
Created October 14, 2012 18:28
CalculatorRunner
import java.util.Scanner;
public class CalculatorRunner
{
public static void main(String[] args)
{
int num1;
int num2;
char operator;
boolean valid;
@benfb
benfb / gcd.java
Created October 28, 2012 21:11
GCD
public class GCD
{
//instance variables - DO NOT ADD ANY MORE INSTANCE VARIABLES
private int numerator;
private int denominator;
//default constructor
public GCD()
{
numerator = 0; //initiates numerator variable
@benfb
benfb / GCDRunner.java
Created October 28, 2012 21:12
GCDRunner
//import Scanner
import java.util.Scanner; //imports only scanner
public class GCDRunner
{
//main method
public static void main(String[] args)
{
//instantiate Scanner object
Scanner scan = new Scanner(System.in);
@benfb
benfb / AliceCount.java
Created November 4, 2012 23:57
AliceCount
// add import statements
import java.util.*;
import java.io.*; //imports the io library. Note: Importing java.* does NOT work
// create class AliceCount
public class AliceCount
{
// create main method - remember to catch the exception
public static void main(String[] args)
@benfb
benfb / Vigenere.java
Created December 2, 2012 19:18
Vigenere
public class Vigenere
{
//declare instance variables for text and keyword
private String pt = "";
private String key = "";
Vigenere(){ //default constructor
pt = "";
key = "";
}
@benfb
benfb / WordSearch.java
Created December 2, 2012 19:20
WordSearch
import java.util.Arrays;
public class WordSearch
{
/** 2D array instance variable*/
private String[][] grid;
/** constructor used to set the number of rows and columns in the 2D array
* @param row
* @param col*/