This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class CalculatorRunner | |
{ | |
public static void main(String[] args) | |
{ | |
int num1; | |
int num2; | |
char operator; | |
boolean valid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Vigenere | |
{ | |
//declare instance variables for text and keyword | |
private String pt = ""; | |
private String key = ""; | |
Vigenere(){ //default constructor | |
pt = ""; | |
key = ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/ |