Initial Commit

This commit is contained in:
2012-01-22 16:14:32 -05:00
commit f5e306f67f
155 changed files with 5097 additions and 0 deletions

3
C/.directory Normal file
View File

@@ -0,0 +1,3 @@
[Dolphin]
Timestamp=2011,10,24,7,45,18
Version=2

4
C/Sudoku/Makefile Normal file
View File

@@ -0,0 +1,4 @@
all:
g++ -o sudoku sudoku.cpp
clean:
rm sudoku

BIN
C/Sudoku/sudoku Executable file

Binary file not shown.

169
C/Sudoku/sudoku.cpp Normal file
View File

@@ -0,0 +1,169 @@
/**
* sudoku.cpp
*
* This program will be used to solve sudoku puzzles
*
* @date oct, 25, 2011
* @author ricky barrette
*/
#include <iostream>
#include "sudoku.h"
int mPuzzle[PUZZLE_SIZE][PUZZLE_SIZE] = { {6,0,0, 8,3,0, 0,4,0},
{0,8,5, 1,0,0, 0,0,0},
{0,0,0, 0,0,0, 0,0,0},
{4,0,0, 0,6,0, 0,8,0},
{0,0,0, 0,0,8, 0,0,3},
{1,6,0, 0,0,2, 0,0,0},
{0,0,9, 0,0,3, 0,1,0},
{0,5,0, 6,0,0, 0,0,0},
{0,1,0, 0,4,0, 2,9,0} };
int mCount = 0;
/**
* Main function
*/
int main(){
std::cout << "\nHello World, Sudoku!\n\n\n";
printPuzzle(mPuzzle);
if(solve(mPuzzle) == 0) {
std::cout << "NO SOLUTION\n";
std::cout << mCount;
std::cout << " trys\n\n";
} else {
std::cout << "\nSolved in ";
std::cout << mCount;
std::cout << " trys\n\n";
printPuzzle(mPuzzle);
}
return 1;
}
/**
* Checks the Row
* @returns 1 if legal, 0 if illegal
* @author ricky barrette
*/
int checkRow(int n, int r, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
for(int index = 0; index < PUZZLE_SIZE; index++)
if(n == puzzle[r][index])
return 0;
return 1;
}
/**
* Checks the Column
* @returns 1 if legal, 0 if illegal
* @author ricky barrette
*/
int checkColumn(int n, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
for(int index = 0; index < PUZZLE_SIZE; index++)
if(n == puzzle[index][c])
return 0;
return 1;
}
/**
* Checks the "Box"
* @returns 1 if legal, 0 if illegal
* @author ricky barrette
*/
int checkBox(int n, int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
r = (r/BOX_SIZE)*BOX_SIZE;
c = (c/BOX_SIZE)*BOX_SIZE;
for(int ri = 0; ri < BOX_SIZE; ri++)
for(int ci = 0; ci < BOX_SIZE; ci++)
if(n == puzzle[r+ri][c+ci])
return 0;
//no violations
return 1;
}
/**
* Solves a sudoku puzzle
* @returns 1 if solvable, 0 if not
* @author ricky barrette
*/
int solve(int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
return solve(0,0, puzzle);
}
/**
* Solves a sudoku puzzle
* @returns 1 if solvable, 0 if not
* @author ricky barrette
*/
int solve(int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
if(DEBUG){
sleep(1);
printPuzzle(puzzle);
}
mCount++;
if (r == PUZZLE_SIZE) {
r = 0;
if (++c == PUZZLE_SIZE)
return 1;
}
//skip filled cells
if (puzzle[r][c] != 0)
return solve(r+1,c,puzzle);
for (int n = 1; n <= PUZZLE_SIZE; n++) {
if (legal(n,r,c,puzzle) == 1) {
puzzle[r][c] = n;
if (solve(r+1,c,puzzle) == 1)
return 1;
}
}
//reset on backtrack
puzzle[r][c] = 0;
return 0;
}
/**
* Prints the puzzle onto the screen
* @author ricky barrette
*/
void printPuzzle(int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
for(int ri = 0; ri < PUZZLE_SIZE; ri++){
for(int ci = 0; ci < PUZZLE_SIZE; ci++){
std::cout << puzzle[ri][ci];
//format: break for groups of BOX_SIZE
if(ci % BOX_SIZE == 2)
std::cout <<" ";
}
//format: break columns of BOX_SIZE
if(ri % BOX_SIZE == 2)
std::cout <<"\n";
//format: break for new row
std::cout << "\n";
}
std::cout <<"\n-------------\n";
}
/**
* Checks the puzzle if it is legal
* @returns 1 if legal; 0 if not
* @author ricky barrette
*/
int legal(int n, int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]){
if(checkRow(n, r, puzzle) == 1)
if(checkColumn(n, c, puzzle) == 1)
if(checkBox(n, r, c, puzzle) == 1)
return 1;
return 0;
}

18
C/Sudoku/sudoku.h Normal file
View File

@@ -0,0 +1,18 @@
/**
* sudoku.h
* @date Oct 25, 2011
* @author ricky barrette
*/
#define DEBUG false
#define PUZZLE_SIZE 9
#define BOX_SIZE (PUZZLE_SIZE / 3)
int main();
int checkRow(int n, int r, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
int checkColumn(int n, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
int checkBox(int n, int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
int solve(int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
int solve(int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
void printPuzzle(int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);
int legal(int n, int r, int c, int puzzle[PUZZLE_SIZE][PUZZLE_SIZE]);

16
C/ThousandToOne.c Normal file
View File

@@ -0,0 +1,16 @@
/**
* ThousandToOne.c
* This program will display the numbers 1000 to 1 in the terminal
*
* Note: compile option: -std=c99
* @author ricky barrette
* @date Oct, 24 2011
*/
#include "stdio.h"
void main(){
for (int i = 1000; i > 0; i--){
printf("%d\n",i);
}
}

10
C/hello.c Normal file
View File

@@ -0,0 +1,10 @@
/**
* This is a simple Hello World program writen in C
* @author ricky barrette
* @date 10 17, 2011
*/
#include "stdio.h"
void main() {
printf("Hello World\n");
}

18
C/io.c Normal file
View File

@@ -0,0 +1,18 @@
/**
* io.c
* This program will demonstrate basic I\O
* @author ricky barrette
* @date Oct 24, 2011
*/
#include <iostream>
using namespace std;
void main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << ".\n";
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Java/BankAccount/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BankAccount</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Sun Nov 21 20:19:35 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,123 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 21, 2010
*/
package com.TwentyCodes.java.BankAccount;
/**
* This is an account class
* @author ricky barrette
*/
public class Account implements Comparable<Account>{
private double mBalance;
private String mOwner;
private long mAccountNumber;
/**
* Creates a new Account
* @param balance starting balance
* @param owner
* @param accountNumber
* @author ricky barrette
*/
public Account(double balance, String owner, long accountNumber) {
mBalance = balance;
mOwner = owner;
mAccountNumber = accountNumber;
}
/**
* withdraws money from the account
* @param amount to withdraw
* @return new balance
* @author ricky barrette
*/
public double withdraw(double amount){
mBalance = mBalance - amount;
return mBalance;
}
/**
* deposits money into the account
* @param amount to deposit
* @return new balance
* @author ricky barrette
*/
public double deposit(double amount){
mBalance = mBalance + amount;
return amount;
}
/**
* getter method for the account balance
* @return current balance
* @author ricky barrette
*/
public double getBalance(){
return mBalance;
}
/**
* getter method for the owner name
* @return owners name
* @author ricky barrette
*/
public String getOwner(){
return mOwner;
}
/**
* returns a human readable string
* (non-Javadoc)
* @see java.lang.Object#toString()
* @return human readable string
* @author ricky barrette
*/
@Override
public String toString(){
return "Owner: "+ mOwner +"; Acount: "+ mAccountNumber +"; Banace: "+ mBalance;
}
/**
* changes the owners name
* @param name
* @author ricky barrette
*/
public void changeOwnerName(String name){
mOwner = name;
}
/**
* charges a $10 to the account
* @return new balance
* @author ricky barrette
*/
public double chargeFee(){
mBalance = mBalance - 10;
return mBalance;
}
/**
* compares accounts by owners names
* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
* @author ricky barrette
*/
@Override
public int compareTo(Account account) {
return this.mOwner.compareTo(account.getOwner());
}
/**
* gets the account number
* @return account number
* @author ricky barrette
*/
public long getAccount() {
return mAccountNumber;
}
}

View File

@@ -0,0 +1,215 @@
/**
* @author Twenty Codess, LLC
* @author ricky barrette
* @data Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
* This class will be a account database
*/
public class AccountDB {
private ArrayList<Account> array;
/**
* Creates a new AccountDB
*/
public AccountDB() {
array = new ArrayList<Account>(0);
}
/**
* returns a human readable string (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
for (Account item : array)
sb.append(item.toString() + "\n");
return sb.toString();
}
/**
* saves the database to a text file
* @param file to be saved to
* @author ricky barrette
* @throws IOException
*/
public void save(File file) throws IOException{
StringBuffer sb = new StringBuffer();
for(Account item : array)
sb.append(item.getBalance()+","+item.getOwner()+","+item.getAccount()+"\n");
FileOutputStream theFile = new FileOutputStream(file);
theFile.write(sb.toString().getBytes());
theFile.flush();
theFile.close();
}
public void load(File file) throws FileNotFoundException{
Scanner scan = new Scanner(file);
String line = null;
String [] lineParts;
do{
line = scan.nextLine();
lineParts = line.split(",");
try {
addAccount(new Account(Double.parseDouble(lineParts[0]), lineParts[1], Long.parseLong(lineParts[2])));
} catch (AccountExistsException e) {
e.printStackTrace();
}
}while(scan.hasNextLine());
}
/**
* added the account to the database
*
* @param account
* @throws AccountExistsException
*/
public void addAccount(Account account) throws AccountExistsException {
boolean isExisting = getAccount(account.getAccount()) != null ? true : false;
if(! isExisting){
array.add(account);
Collections.sort(array);
} else
throw new AccountExistsException("Account "+ account.getAccount()+" Already Exists");
}
/**
* finds the all occurrences of an account with the owner
*
* @param owner
* @return a list containing all the accounts with the provided owner
*/
public ArrayList<Account> findAccount(String owner) {
ArrayList<Account> temp = new ArrayList<Account>(0);
for (Account item : array)
if (item.getOwner().equals(owner))
temp.add(item);
return temp;
}
/**
*
* @param search
* @return arraylist containing all the
* @author ricky barrette
*/
public ArrayList<Account> searchForAccount(String search) {
long account = -1;
try {
account = Long.parseLong(search);
} catch (Exception e) {
// TO NOTHING
}
ArrayList<Account> temp = new ArrayList<Account>(0);
for (Account item : array) {
if (item.getOwner().contains(search))
temp.add(item);
if (account > 0 && item.getAccount() == account)
temp.add(item);
}
return temp;
}
/**
* removes the all occurrences of an account with the owner
*
* @param owner
*/
public void deleteAccounts(String owner) {
long account = -1;
try {
account = Long.parseLong(owner);
} catch (Exception e) {
// TO NOTHING
}
Object[] temp = array.toArray();
for (int index = 0; index < temp.length; index++) {
if (((Account) temp[index]).getOwner().equals(owner))
temp[index] = null;
if (account > 0 && ((Account) temp[index]).getAccount() == account)
temp[index] = null;
}
array.removeAll(array);
for (Object item : temp)
if (item != null)
array.add((Account) item);
}
/**
* returns the specified account
*
* @param accountNumber
* @return account or null if account doesnt exist
* @author ricky barrette
*/
public Account getAccount(long accountNumber) {
for (Account item : array)
if (item.getAccount() == accountNumber)
return item;
return null;
}
/**
* deposits money into the specified account
* @param accountNumber
* @param amount
* @return true if successful
* @author ricky barrette
*/
public boolean deposit(long accountNumber, double amount) {
for (Account item : array)
if (item.getAccount() == accountNumber) {
item.deposit(amount);
return true;
}
return false;
}
/**
* charges a fee to the specified account
* @param accountNumber
* @return true if successful
* @author ricky barrette
*/
public boolean chargeFee(long accountNumber) {
for (Account item : array)
if (item.getAccount() == accountNumber) {
item.chargeFee();
return true;
}
return false;
}
/**
* withdraws money from the specified account
* @param accountNumber
* @param amount
* @return true if successful
* @author ricky barrette
*/
public boolean withdraw(long accountNumber, double amount) {
for (Account item : array)
if (item.getAccount() == accountNumber) {
item.withdraw(amount);
return true;
}
return false;
}
}

View File

@@ -0,0 +1,56 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 24, 2010
*/
package com.TwentyCodes.java.BankAccount;
/**
*
* @author ricky barrette
*/
public class AccountExistsException extends Exception {
/**
* @author ricky barrette
*/
private static final long serialVersionUID = 4605163237489852355L;
/**
* Creates a new AccountExistsException
* @author ricky barrette
*/
public AccountExistsException() {
super();
}
/**
* Creates a new AccountExistsException
* @param arg0
* @author ricky barrette
*/
public AccountExistsException(String arg0) {
super(arg0);
}
/**
* Creates a new AccountExistsException
* @param arg0
* @author ricky barrette
*/
public AccountExistsException(Throwable arg0) {
super(arg0);
}
/**
* Creates a new AccountExistsException
* @param arg0
* @param arg1
* @author ricky barrette
*/
public AccountExistsException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
}

View File

@@ -0,0 +1,17 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 22, 2010
*/
package com.TwentyCodes.java.BankAccount;
/**
* this enum will represent trantions types
* @author ricky barrette
*/
public enum TransactionType {
DEPOSIT, WITHDRAW, CHARGE_FEE
}

View File

@@ -0,0 +1,128 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import com.TwentyCodes.java.BankAccount.Account;
/**
* this class will allow the user to enter a new vehicle into the database
*/
public class AddAccountDialog extends JFrame implements ActionListener{
private static final long serialVersionUID = 3165335189780349167L;
private JButton ok;
private JLabel errorMsg;
private JTextField owner;
private JTextField account;
private JTextField balance;
/**
* Creates a new AddAccountDialog
*/
public AddAccountDialog() {
super();
setTitle("Add Account");
this.setSize(744, 118);
//create a JPanel to hold the text area and button
JPanel panel = new JPanel();
JLabel label_1 = new JLabel("Owner: ");
owner = new JTextField();
owner.setColumns(10);
JLabel label_2 = new JLabel("Account Number: ");
account = new JTextField();
account.setColumns(10);
JLabel label = new JLabel("Initial Banlance: ");
balance = new JTextField();
balance.setColumns(10);
ok = new JButton("Ok");
ok.addActionListener(this);
//add the JPanel to the frame, and display
getContentPane().add(panel, BorderLayout.SOUTH);
errorMsg = new JLabel("Please verify the account information, and try again");
errorMsg.setVisible(false);
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addGap(21)
.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_panel.createSequentialGroup()
.addComponent(errorMsg)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(ok, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(gl_panel.createSequentialGroup()
.addComponent(label_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(owner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(label_2)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(account, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(label)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(balance, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(877, Short.MAX_VALUE))
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_panel.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(label_1, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(owner, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(label_2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(account, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(label, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(balance, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
.addComponent(errorMsg, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
.addComponent(ok))
.addContainerGap())
);
panel.setLayout(gl_panel);
// pack();
setVisible(true);
}
/**
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok) {
try{
long accountNumber = Long.parseLong(account.getText());
MainWindow.db.addAccount(new Account(Double.parseDouble(balance.getText()), owner.getText(), accountNumber));
setVisible(false);
} catch(Exception ex){
errorMsg.setVisible(true);
}
}
}
}

View File

@@ -0,0 +1,131 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.TwentyCodes.java.BankAccount.AccountDB;
/**
* this is the main window and class of this application
*/
public class MainWindow extends JFrame implements ActionListener{
private JButton search;
private JButton addAccount;
private JButton addTransaction;
private JButton removeAccount;
private JButton showAllAccount;
private JButton saveToFile;
private JButton loadFile;
private JFileChooser fc;
public static AccountDB db;
/**
* Generated Serial Version ID
*/
private static final long serialVersionUID = 1841715561053331517L;
public MainWindow() {
setTitle("Account Database");
JPanel panel = new JPanel();
search = new JButton("Search");
addAccount = new JButton("Add Account");
addTransaction = new JButton("Add Transaction");
removeAccount = new JButton("Remove Account");
showAllAccount = new JButton("Show All Accounts");
loadFile = new JButton("Load File");
saveToFile = new JButton("Save");
search.addActionListener(this);
addAccount.addActionListener(this);
addTransaction.addActionListener(this);
removeAccount.addActionListener(this);
showAllAccount.addActionListener(this);
saveToFile.addActionListener(this);
loadFile.addActionListener(this);
panel.add(search);
panel.add(addAccount);
panel.add(addTransaction);
panel.add(removeAccount);
panel.add(showAllAccount);
panel.add(loadFile);
panel.add(saveToFile);
add(panel);
setVisible(true);
pack();
db = new AccountDB();
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
}
/**
* main method, called when the application starts
* @param args
*/
public static void main(String[] args){
new MainWindow();
}
/**
* called when a button is clicked
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == search) {
new SearchDialog();
}
if (e.getSource() == addAccount) {
new AddAccountDialog();
}
if (e.getSource() == removeAccount) {
new RemoveAccounteDialog();
}
if (e.getSource() == showAllAccount) {
new ShowAllDialog(db.toString());
}
if(e.getSource() == addTransaction){
new TransactionDialog();
}
if(e.getSource() == saveToFile){
try {
if(fc.showSaveDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION)
db.save(fc.getSelectedFile());
} catch (HeadlessException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if(e.getSource() == loadFile){
try {
if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION)
db.load(fc.getSelectedFile());
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}

View File

@@ -0,0 +1,66 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* This class will be the delete vehicle dialog
*/
public class RemoveAccounteDialog extends JFrame implements ActionListener {
private static final long serialVersionUID = -36245710370532319L;
private JButton ok;
private JTextField textField;
/**
* Creates a new RemoveVehicleDialog
*/
public RemoveAccounteDialog(){
super();
setTitle("Delete Accounts");
//create a JPanel to hold the text area and button
JPanel panel = new JPanel();
ok = new JButton("Ok");
JLabel label = new JLabel("Enter Account Owner or Number");
ok.addActionListener(this);
panel.add(label);
textField = new JTextField();
panel.add(textField);
textField.setColumns(10);
panel.add(ok);
//add the JPanel to the frame, and display
getContentPane().add(panel);
pack();
setVisible(true);
}
/**
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok) {
MainWindow.db.deleteAccounts(textField.getText());
setVisible(false);
}
}
}

View File

@@ -0,0 +1,71 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @data Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.TwentyCodes.java.BankAccount.Account;
/**
* This class will be the dialog that will ask the user for a specific make to show
*/
public class SearchDialog extends JFrame implements ActionListener {
private static final long serialVersionUID = 1750326106927701404L;
private JButton ok;
private JTextField editText;
/**
* Creates a new ShowAllMakeDialog
*/
public SearchDialog() {
super();
setTitle("Search");
//create a JPanel to hold the text area and button
JPanel panel = new JPanel();
ok = new JButton("Ok");
JLabel label = new JLabel("Enter Acount Owner or Number:");
ok.addActionListener(this);
panel.add(label);
editText = new JTextField();
panel.add(editText);
editText.setColumns(10);
panel.add(ok);
//add the JPanel to the frame, and display
getContentPane().add(panel);
pack();
setVisible(true);
}
/**
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok) {
StringBuilder sb = new StringBuilder();
for(Account item : MainWindow.db.searchForAccount(editText.getText()))
sb.append(item.toString()+"\n");
new ShowAllDialog(sb.toString());
setVisible(false);
}
}
}

View File

@@ -0,0 +1,75 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 18, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
/**
* This panel will be used to display all Vehicles in the VechicleDB
*/
public class ShowAllDialog extends JFrame implements ActionListener {
private static final long serialVersionUID = -8416144493079733535L;
/**
* Creates a new ShowAllDialog
*/
public ShowAllDialog(String list){
super();
setTitle("Show All Accounts");
//create a JPanel to hold the text area and button
JPanel panel = new JPanel();
this.setSize(400, 540);
//add the JPanel to the frame, and display
getContentPane().add(panel);
JButton ok = new JButton("Ok");
ok.addActionListener(this);
JTextArea results = new JTextArea();
results.setEditable(false);
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addContainerGap()
.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
.addComponent(results, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
.addComponent(ok, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE))
.addContainerGap())
);
gl_panel.setVerticalGroup(
gl_panel.createParallelGroup(Alignment.LEADING)
.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
.addComponent(results, GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(ok)
.addContainerGap())
);
panel.setLayout(gl_panel);
results.setText(list);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent arg0) {
setVisible(false);
}
}

View File

@@ -0,0 +1,296 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 22, 2010
*/
package com.TwentyCodes.java.BankAccount.UI;
import java.awt.BorderLayout;
import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import com.TwentyCodes.java.BankAccount.Account;
import com.TwentyCodes.java.BankAccount.TransactionType;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class TransactionDialog extends JFrame implements ActionListener {
private static final long serialVersionUID = -6130586697078071325L;
private JPanel mContentPane;
private JTextField mAmount;
private JTextField mAccountNumber;
private JRadioButton mDeposit;
private JRadioButton mWithdraw;
private JRadioButton mChargeFee;
private JButton mBtnFind;
private JButton mBtnOk;
private TransactionType mType = TransactionType.DEPOSIT;
private JLabel mErrorMsg;
private JLabel mAccountInfoLabel;
/**
* Create the frame.
*/
public TransactionDialog() {
setTitle("Add Transaction");
setBounds(100, 100, 495, 181);
mContentPane = new JPanel();
mContentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
mContentPane.setLayout(new BorderLayout(0, 0));
setContentPane(mContentPane);
JPanel panel = new JPanel();
mContentPane.add(panel, BorderLayout.WEST);
// create radio buttons and group them
ButtonGroup group = new ButtonGroup();
mDeposit = new JRadioButton("Deposit");
mDeposit.setSelected(true);
mWithdraw = new JRadioButton("Withdraw");
mChargeFee = new JRadioButton("Charge Fee");
group.add(mDeposit);
group.add(mWithdraw);
group.add(mChargeFee);
// radio button action listeners
mDeposit.addActionListener(this);
mWithdraw.addActionListener(this);
mChargeFee.addActionListener(this);
JLabel lblTransationType = new JLabel("Transation Type");
GroupLayout gl_panel = new GroupLayout(panel);
gl_panel.setHorizontalGroup(gl_panel
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addGroup(
gl_panel.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(
mDeposit))
.addGroup(
gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(
lblTransationType))
.addGroup(
gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(
mWithdraw))
.addGroup(
gl_panel.createSequentialGroup()
.addContainerGap()
.addComponent(
mChargeFee)))
.addContainerGap(GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)));
gl_panel.setVerticalGroup(gl_panel.createParallelGroup(
Alignment.LEADING).addGroup(
gl_panel.createSequentialGroup().addContainerGap()
.addComponent(lblTransationType)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(mDeposit)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(mWithdraw)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(mChargeFee)
.addContainerGap(156, Short.MAX_VALUE)));
panel.setLayout(gl_panel);
JPanel panel_1 = new JPanel();
mContentPane.add(panel_1, BorderLayout.CENTER);
JLabel lblTransationAmount = new JLabel("Transation Amount");
mAmount = new JTextField();
mAmount.setColumns(10);
JLabel lblAccountNumber = new JLabel("Account Number");
mAccountNumber = new JTextField();
mAccountNumber.setColumns(10);
mBtnFind = new JButton("Find");
mBtnFind.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
mBtnOk = new JButton("Ok");
mBtnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
GroupLayout gl_panel_1 = new GroupLayout(panel_1);
gl_panel_1
.setHorizontalGroup(gl_panel_1
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_panel_1
.createSequentialGroup()
.addContainerGap()
.addGroup(
gl_panel_1
.createParallelGroup(
Alignment.TRAILING)
.addGroup(
Alignment.LEADING,
gl_panel_1
.createSequentialGroup()
.addComponent(
lblTransationAmount)
.addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(
mAmount,
GroupLayout.DEFAULT_SIZE,
164,
Short.MAX_VALUE))
.addComponent(
mBtnOk,
GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(
Alignment.LEADING,
gl_panel_1
.createSequentialGroup()
.addComponent(
lblAccountNumber)
.addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(
mAccountNumber,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(
mBtnFind)))
.addGap(94)));
gl_panel_1
.setVerticalGroup(gl_panel_1
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_panel_1
.createSequentialGroup()
.addContainerGap()
.addGroup(
gl_panel_1
.createParallelGroup(
Alignment.BASELINE)
.addComponent(
lblAccountNumber)
.addComponent(
mAccountNumber,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(mBtnFind))
.addPreferredGap(
ComponentPlacement.RELATED)
.addGroup(
gl_panel_1
.createParallelGroup(
Alignment.BASELINE)
.addComponent(
lblTransationAmount)
.addComponent(
mAmount,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
ComponentPlacement.RELATED)
.addComponent(mBtnOk).addGap(41)));
panel_1.setLayout(gl_panel_1);
mErrorMsg = new JLabel("");
mContentPane.add(mErrorMsg, BorderLayout.SOUTH);
mAccountInfoLabel = new JLabel("");
mContentPane.add(mAccountInfoLabel, BorderLayout.NORTH);
// Action listners for ok and find buttons
mBtnOk.addActionListener(this);
mBtnFind.addActionListener(this);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == mDeposit) {
mType = TransactionType.DEPOSIT;
mAmount.setEnabled(true);
}
if (e.getSource() == mWithdraw) {
mType = TransactionType.WITHDRAW;
mAmount.setEnabled(true);
}
if (e.getSource() == mChargeFee) {
mType = TransactionType.CHARGE_FEE;
mAmount.setEnabled(false);
mAmount.setText("10.00");
}
if (e.getSource() == mBtnFind) {
try {
Account account = MainWindow.db.getAccount(Long.parseLong(mAccountNumber.getText()));
if(account != null){
mAccountInfoLabel.setText(account.toString());
mErrorMsg.setText("");
} else {
mAccountInfoLabel.setText("");
mErrorMsg.setText("No Such Account");
}
} catch (NumberFormatException e1) {
mAccountInfoLabel.setText("");
mErrorMsg.setText("Invalid Account Entry");
}
}
if (e.getSource() == mBtnOk) {
try{
switch(mType){
case DEPOSIT:
if(MainWindow.db.deposit(Long.parseLong(mAccountNumber.getText()), Double.parseDouble(mAmount.getText())))
setVisible(false);
else
mErrorMsg.setText("No Such Account");
break;
case WITHDRAW:
if(MainWindow.db.withdraw(Long.parseLong(mAccountNumber.getText()), Double.parseDouble(mAmount.getText())))
setVisible(false);
else
mErrorMsg.setText("No Such Account");
break;
case CHARGE_FEE:
if(MainWindow.db.chargeFee(Long.parseLong(mAccountNumber.getText())))
setVisible(false);
else
mErrorMsg.setText("No Such Account");
break;
}
} catch(Exception ex){
mErrorMsg.setText("Invalid Entry, Check Input");
}
}
}
}

17
Java/Count.java Normal file
View File

@@ -0,0 +1,17 @@
/*
* this class will demonstrate how to use a for loop
* @author ricky.barrette
*/
public class Count {
/*
* this is the main method of this class
*
* @author ricky.barrette
*/
public static void main(String[] args) {
for(int index = 1000; index > 4; index--) {
System.out.println("index = "+ index);
}
}
}

28
Java/DiceRoller.java Normal file
View File

@@ -0,0 +1,28 @@
import java.util.Random;
import java.util.Scanner;
/*
* This application is a simple dice roller. It will ask the user for two values:
* 1. quantity of dice
* 2. number of sides
*/
class DiceRoller {
/*
* The main method. It all starts here
*/
public static void main(String[] args) {
Random ran = new Random();
int rolledValue = 1;
/*
* Almost done. Time to roll them dice
*/
while(rolledValue != 0){
rolledValue = (ran.nextInt(7));
System.out.println("And the roll is: " + rolledValue);
}
} //end main method
} //end class

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Java/DiceRoller/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DiceRoller</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Sun Nov 07 18:45:39 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,33 @@
/**
* @author ricky barrette
* @author Twenty Codes, LLC
*/
import java.util.Random;
/**
* This class will be used to has a helper class for the dice roller application
* @author ricky barrette
*/
public class DiceRoller {
/**
* rolls the dice
* @param rolls
* @param sides
* @return
* @author ricky barrette
*/
protected static String rollDice(int rolls, int sides) {
Random gen = new Random();
int tally = 0, number;
/*
* now we process the user's input and generate results for them.
*/
for (int i = 0; i < rolls; i++) {
number = gen.nextInt(sides) +1;
tally = tally + number;
}
return "You rolled: " + tally;
}
}

View File

@@ -0,0 +1,173 @@
import java.awt.Button;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 19, 2010
*/
/**
* this is the main window of the dice roller application
* @author ricky barrette
*/
public class MainWindow extends JFrame implements ActionListener {
private static final long serialVersionUID = -382484290158631244L;
private Button mRollButton;
private JTextField mRolls;
private JRadioButton mD2;
private JRadioButton mD3;
private JRadioButton mD4;
private JRadioButton mD6;
private JRadioButton mD10;
private JRadioButton mD8;
private JRadioButton mD20;
private JRadioButton mD100;
private int mSides = 2;
private JLabel mRolled;
/**
* Creates a new MainWindow
* @author ricky barrette
*/
public MainWindow(){
setTitle("Dice Roller");
this.setMinimumSize(new Dimension(190,310));
initializedButtonsAndSuch();
}
/**
* initializes everything
* @author ricky barrette
*/
private void initializedButtonsAndSuch() {
//lets create the main window
JPanel panel = new JPanel();
panel.setLayout(null);
JLabel label = new JLabel("Number of dice: ");
label.setBounds(12, 7, 115, 15);
panel.add(label);
mRolls = new JTextField();
mRolls.setBounds(135, 5, 48, 19);
mRolls.setColumns(4);
panel.add(mRolls);
//create radio buttons and group them
ButtonGroup group = new ButtonGroup();
mRollButton = new Button("Roll!");
mRollButton.setBounds(10, 219, 173, 23);
//set action listeners
mRollButton.addActionListener(this);
setVisible(true);
mD2 = new JRadioButton("D2");
mD3 = new JRadioButton("D3");
mD4 = new JRadioButton("D4");
mD6 = new JRadioButton("D6");
mD8 = new JRadioButton("D8");
mD10 = new JRadioButton("D10");
mD20 = new JRadioButton("D20");
mD100 = new JRadioButton("D100");
group.add(mD2);
group.add(mD3);
group.add(mD4);
group.add(mD6);
group.add(mD8);
group.add(mD10);
group.add(mD20);
group.add(mD100);
mD2.setSelected(true);
//Put the radio buttons in a column in a panel.
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
radioPanel.setBounds(44, 29, 59, 184);
radioPanel.add(mD2);
radioPanel.add(mD3);
radioPanel.add(mD4);
radioPanel.add(mD6);
radioPanel.add(mD8);
radioPanel.add(mD10);
radioPanel.add(mD20);
radioPanel.add(mD100);
mD2.addActionListener(this);
mD3.addActionListener(this);
mD4.addActionListener(this);
mD6.addActionListener(this);
mD8.addActionListener(this);
mD10.addActionListener(this);
mD20.addActionListener(this);
mD100.addActionListener(this);
panel.add(radioPanel);
panel.add(mRollButton);
this.getContentPane().add(panel);
mRolled = new JLabel();
mRolled.setBounds(12, 248, 171, 15);
panel.add(mRolled);
}
/**
* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* @author ricky barrette
*/
@Override
public void actionPerformed(ActionEvent event) {
if(event.getSource() == mRollButton){
try{
mRolled.setText(DiceRoller.rollDice(Integer.parseInt(mRolls.getText()), mSides));
} catch (Exception e){
mRolled.setText("FAIL");
}
}
if(event.getSource() == mD2){
mSides = 2;
}
if(event.getSource() == mD3){
mSides = 3;
}
if(event.getSource() == mD4){
mSides = 4;
}
if(event.getSource() == mD6){
mSides = 6;
}
if(event.getSource() == mD8){
mSides = 8;
}
if(event.getSource() == mD10){
mSides = 10;
}
if(event.getSource() == mD20){
mSides = 20;
}
if(event.getSource() == mD100){
mSides =100;
}
}
/**
* main method, called when the application starts
* @param args
* @author ricky barrette
*/
public static void main(String[] args) {
new MainWindow();
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EnhancedForLoop</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Sun Nov 21 11:27:11 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

View File

@@ -0,0 +1,58 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 21, 2010
*/
/**
* this class will be used to demonstrate an enhanced for loop that is discussed here
* http://download.oracle.com/javase/tutorial/java/nutsandbolts/for.html
* We recommend using this form of the for statement instead of the general form whenever possible
* @author ricky barrette
*/
public class Main {
static int[] array = new int[] { 1, 2, 3, 4, 5, 6, 6, 6, 7, 8, 9, 10};
static char[] helloWorld = new char[] { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
/**
* called when the application is first started
* @param args
* @author ricky barrette
*/
public static void main(String[] args) {
/*
* the way this works is that you provide 2 arguments for the for loop.
*
* the first is the object to hold an item in the array, and the second is the array it self.
*
* the to are separated by a colon.
*
* the output for this for loop will be:
* 1
* 2
* 3
* 4
* 5
* 6
* 6
* 6
* 7
* 8
* 9
* 10
*/
for(int item : array){
System.out.println(item);
}
/*
* here is another example, this time with a char array
*/
for(char character : helloWorld){
System.out.print(character);
}
}
}

35
Java/EvenOrOdd.java Normal file
View File

@@ -0,0 +1,35 @@
/**
* @date 10, 24, 2010
* @author ricky.barrette
* @author Twenty Codes, LLC
*/
import java.util.Scanner;
/*
* this class will be used to demostrate how to use an if/else block
* @author ricky.barrette
*/
public class EvenOrOdd{
/*
* this is the main method of the class
* @param args from command line
* @author ricky.barrette
*/
public static void main(String[] args){
//prepear the variables and the sccanner for input
Scanner scan = new Scanner(System.in);
int input;
//ask user for input and get the input
System.out.print("Enter a number: ");
input = scan.nextInt();
//process the input and print the results
if ( (input % 2) == 0){
System.out.println("The number is even");
} else {
System.out.println("The number is odd");
}
}
}
//END CLASS

15
Java/HelloWord.java Normal file
View File

@@ -0,0 +1,15 @@
/**
* this is a test class yay!
* @author ricky.barrette
*/
class HelloWorld{
/**
* this is the main method of the class
* @param args
* @author ricky.barrette
*/
public static void main(String[] args){
System.out.println("Hello World Bitch!");
}
}

6
Java/IsPrime/.classpath Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Java/IsPrime/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>IsPrime</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,62 @@
10
dir
180
svn+ssh://tcdevsvn1/svn/test/trunk/Examples/IsPrime/.settings
svn+ssh://tcdevsvn1/svn/test
2010-11-21T15:30:21.130254Z
108
ricky.barrette
svn:special svn:externals svn:needs-lock
9a5aac6f-9f22-4a63-bd53-bef70477a034
org.eclipse.jdt.core.prefs
file
2012-01-22T19:47:00.000000Z
d25cfe62b7ff12e295da66a35642af8b
2010-11-21T15:30:21.130254Z
108
ricky.barrette
has-props
617

View File

@@ -0,0 +1,5 @@
K 13
svn:mime-type
V 10
text/plain
END

View File

@@ -0,0 +1,12 @@
#Sun Oct 31 20:11:09 EDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -0,0 +1,12 @@
#Sun Oct 31 20:11:09 EDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

105
Java/IsPrime/.svn/entries Normal file
View File

@@ -0,0 +1,105 @@
10
dir
180
svn+ssh://tcdevsvn1/svn/test/trunk/Examples/IsPrime
svn+ssh://tcdevsvn1/svn/test
2010-11-21T15:33:27.340663Z
111
ricky.barrette
svn:special svn:externals svn:needs-lock
9a5aac6f-9f22-4a63-bd53-bef70477a034
.classpath
file
2012-01-22T19:47:00.000000Z
0feefca3562e5167ed8224d805b3b922
2010-11-21T15:30:21.130254Z
108
ricky.barrette
has-props
295
.project
file
2012-01-22T19:47:00.000000Z
3fe9afba4d2403c478ac165804542a88
2010-11-21T15:30:21.130254Z
108
ricky.barrette
has-props
366
.settings
dir
bin
dir
src
dir

View File

@@ -0,0 +1,5 @@
K 13
svn:mime-type
V 10
text/plain
END

View File

@@ -0,0 +1,5 @@
K 13
svn:mime-type
V 10
text/plain
END

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>IsPrime</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,62 @@
10
dir
180
svn+ssh://tcdevsvn1/svn/test/trunk/Examples/IsPrime/bin
svn+ssh://tcdevsvn1/svn/test
2010-11-21T15:30:21.130254Z
108
ricky.barrette
svn:special svn:externals svn:needs-lock
9a5aac6f-9f22-4a63-bd53-bef70477a034
IsPrime.class
file
delete
2012-01-22T19:47:00.000000Z
e79e996b5b85364052888227f589016a
2010-11-21T15:30:21.130254Z
108
ricky.barrette
has-props
1518

View File

@@ -0,0 +1,5 @@
K 13
svn:mime-type
V 24
application/octet-stream
END

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,62 @@
10
dir
180
svn+ssh://tcdevsvn1/svn/test/trunk/Examples/IsPrime/src
svn+ssh://tcdevsvn1/svn/test
2010-11-21T15:30:21.130254Z
108
ricky.barrette
svn:special svn:externals svn:needs-lock
9a5aac6f-9f22-4a63-bd53-bef70477a034
IsPrime.java
file
2012-01-22T19:47:00.000000Z
4b8c36f33e4ec6860a8d7dc7c9f9ace5
2010-11-21T15:30:21.130254Z
108
ricky.barrette
has-props
1252

View File

@@ -0,0 +1,5 @@
K 13
svn:mime-type
V 10
text/plain
END

View File

@@ -0,0 +1,63 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Oct 31, 2010
*/
import java.util.Scanner;
/**
* this is my example class for is prime
* @author ricky barrette
*/
public class IsPrime {
/*
* this is the main method of the class
*
* @param args from command line
*
* @author ricky.barrette
*/
public static void main(String[] args) {
int input = 0;
boolean isPrime = true;
boolean isNumber;
/*
* we ask the user for input
* if they don't enter an int, ask for input again
*/
do{
Scanner scan = new Scanner(System.in);
System.out.print("Enter an Integer: ");
isNumber = true;
try {
input = scan.nextInt();
} catch (Exception e) {
System.out.println("Please try agian");
isNumber = false;
}
}while(! isNumber);
System.out.println("number, index, mod");
// process the input
for (int i = 2; i < input; i++) {
System.out.println(input +", "+ i +", "+ (input % i));
if ((input % i) == 0) {
isPrime = false;
// there is not point of continuing, break the loop (aka stop)
break;
}
}
// display the results
if (isPrime)
System.out.println("The number is prime");
else
System.out.println("The number is not prime");
}
}

View File

@@ -0,0 +1,63 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Oct 31, 2010
*/
import java.util.Scanner;
/**
* this is my example class for is prime
* @author ricky barrette
*/
public class IsPrime {
/*
* this is the main method of the class
*
* @param args from command line
*
* @author ricky.barrette
*/
public static void main(String[] args) {
int input = 0;
boolean isPrime = true;
boolean isNumber;
/*
* we ask the user for input
* if they don't enter an int, ask for input again
*/
do{
Scanner scan = new Scanner(System.in);
System.out.print("Enter an Integer: ");
isNumber = true;
try {
input = scan.nextInt();
} catch (Exception e) {
System.out.println("Please try agian");
isNumber = false;
}
}while(! isNumber);
System.out.println("number, index, mod");
// process the input
for (int i = 2; i < input; i++) {
System.out.println(input +", "+ i +", "+ (input % i));
if ((input % i) == 0) {
isPrime = false;
// there is not point of continuing, break the loop (aka stop)
break;
}
}
// display the results
if (isPrime)
System.out.println("The number is prime");
else
System.out.println("The number is not prime");
}
}

62
Java/IsPrimeFor.java Normal file
View File

@@ -0,0 +1,62 @@
/**
* @date 10, 24, 2010
* @author ricky.barrette
* @author Twenty Codes, LLC
*/
import java.util.Scanner;
/**
* this is my example class for is prime
* @author ricky barrette
*/
public class IsPrimeFor {
/*
* this is the main method of the class
*
* @param args from command line
*
* @author ricky.barrette
*/
public static void main(String[] args) {
int input = 0;
boolean isPrime = true;
boolean isNumber;
/*
* we ask the user for input
* if they don't enter a number, ask for input again
*/
do{
Scanner scan = new Scanner(System.in);
System.out.print("Enter an Integer: ");
isNumber = true;
try {
input = scan.nextInt();
} catch (Exception e) {
System.out.println("please try agian");
isNumber = false;
}
}while(! isNumber);
System.out.println("number, index, mod");
// process the input
for (int i = 2; i < input; i++) {
System.out.println(input +", "+ i +", "+ (input % i));
if ((input % i) == 0) {
isPrime = false;
// there is not point of continuing, break the loop (aka stop)
break;
}
}
// display the results
if (isPrime)
System.out.println("The number is prime");
else
System.out.println("The number is not prime");
}
}

71
Java/IsPrimeMethods.java Normal file
View File

@@ -0,0 +1,71 @@
/**
* @date 10, 25, 2010
* @author ricky.barrette
* @author Twenty Codes, LLC
*/
import java.util.Scanner;
/*
* this class will be used to demostrate how to use methods, to replace a loop
* please note that this is not a good method to use,
* as it is very memory intesive, and is prone to stack overflow
* @author ricky.barrette
*/
public class IsPrimeMethods{
/*
* this is the main method of the class
* @param args from command line
* @author ricky.barrette
*/
public static void main(String[] args){
//prepear the variables and the scanner for input
Scanner scan = new Scanner(System.in);
int input;
//ask user for input and get the input
System.out.print("Enter a number: ");
input = scan.nextInt();
//process the input and display the results
if(isPrime(input))
System.out.println("The number "+input+" is prime");
else
System.out.println("The number "+input+" is not prime");
}
/**
* tests id the number is prime
* @param number being tested
* @return true if the number is prime
* @author ricky.barrette
*/
private static boolean isPrime(int number){
System.out.println("number, index, mod");
return isPrime(number, 2);
}
/**
* test if the number provided is prime
* @param number being tested
* @param index of the test
* @return true if the number is prime
* @author ricky.barrette
*/
private static boolean isPrime(int number, int index){
System.out.println(number +", "+ index +", "+ (number % index));
//the number is not prime
if ( (number % index) == 0)
return false;
// if there is another test, lets run it
if( index < (number -1))
return isPrime(number, (index +1) );
//if we get to this point, the number is prime
return true;
}
}
//END CLASS

51
Java/IsPrimeWhile.java Normal file
View File

@@ -0,0 +1,51 @@
/**
* @date 10, 25, 2010
* @author ricky.barrette
* @author Twenty Codes, LLC
*/
import java.util.Scanner;
/*
* this class will be used to demostrate how to use a while loop to deermine if a number is prime
* @author ricky.barrette
*/
public class IsPrimeWhile{
/*
* this is the main method of the class
* @param args from command line
* @author ricky.barrette
*/
public static void main(String[] args){
//prepear the variables and the scanner for input
Scanner scan = new Scanner(System.in);
int input;
int index = 2;
boolean isPrime = true;
//ask user for input and get the input
System.out.print("Enter a number: ");
input = scan.nextInt();
//while there are more test to preform...
while ( index < (input -1)){
System.out.println(input +", "+ index +", "+ (input % index));
//the number is not prime break the loop
if ( (input % index) == 0){
isPrime = false;
break;
}
index++;
}
//process the input and display the results
if(isPrime)
System.out.println("The number "+input+" is prime");
else
System.out.println("The number "+input+" is not prime");
}
}
//END CLASS

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Java/MazeTester/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MazeTester</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Thu Nov 25 09:11:17 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,185 @@
/**
* This Maze Object is a maze made up of paths ' ' and walls '*'
*/
public class Maze {
private char[][] mMaze;
private char[][] mLastMaze;
/*
* XXX this is for testing, comment out all dependencies
* i use this to see how the maze is being transverse'd
*/
// private final boolean DEBUG = true;
/**
* Creates a new Maze
* @author ricky barrette
* @param m
*/
public Maze(char[][] m) {
mMaze = m;
}
/**
* cleans the markings from mLastMaze. leaving only the solution path, and walls
*/
private void cleanMaze(){
char[][] m = new char[mLastMaze.length][mLastMaze[0].length];
for (int i = 0; i < m.length; i++) {
for (int index = 0; index < m[0].length; index++) {
if(mLastMaze[i][index] == 'X')
mLastMaze[i][index] = ' ';
// XXX for testing only, comment out for production code
// if (DEBUG) {
// if (mLastMaze[i][index] == 'B')
// mLastMaze[i][index] = ' ';
// if (mLastMaze[i][index] == 'W')
// mLastMaze[i][index] = '*';
// }
}
}
}
/**
* checks if the current point is a path on the maze
* @param row
* @param column
* @param maze
* @return true if the point is a path
*/
private boolean isPath(int row, int column, char[][] maze){
// XXX this if for testing, comment out for production
// if (DEBUG) {
// //i use this if block to see walls are encountered within the maze while being transverse'd
// if (maze[row][column] == '*')
// maze[row][column] = 'W';
// //this will show me where i backtrack
// if (maze[row][column] == 'X')
// maze[row][column] = 'B';
// }
if(maze[row][column] == ' ')
return true;
return false;
}
/**
* finds out if you can escape this maze from the supplied starting point
* @param row
* @param coloumn
* @return true if the maze is escapable
*/
public boolean escape(int row, int column){
mLastMaze = null;
boolean isEscapable = escape(row, column, makeTempMaze());
cleanMaze();
//here we will mark the starting point with a 'S'
mLastMaze[row][column] = 'S';
System.out.print(mazeToString(mLastMaze));
return isEscapable;
}
/**
* finds out if you can escape this maze from the supplied point
* 19 (< 20) lines of code (including }'s )
* @param row
* @param column
* @param tempMaze that we can mark up
* @return true if you can escape, false otherwise
*/
private boolean escape(int row, int column, char[][] tempMaze) {
boolean done = false;
/*
* if the current point is a point is a part of the path
* then mark it, and move forward
*/
if (isPath(row, column, tempMaze)) {
tempMaze[row][column] = 'X';
try {
done = escape(row + 1, column, tempMaze); // down
if (!done)
done = escape(row, column + 1, tempMaze); // right
if (!done)
done = escape(row - 1, column, tempMaze); // up
if (!done)
done = escape(row, column - 1, tempMaze); // left
} catch (ArrayIndexOutOfBoundsException e) {
/*
* if we get this, that mean we can escape the maze...
* so We escaped the maze! yay!
*/
done = true;
}
/*
* if done, then mark the point as part of the final escape path
*/
if (done)
tempMaze[row][column] = '.';
}
/*
* XXX This is only for testing comment out for production
* this allows us to watch the maze being solved
*/
// if (DEBUG) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// System.out.println(mazeToString(tempMaze));
// }
//pass the tempMaze to mLastMaze
mLastMaze = tempMaze;
return done;
}
/**
* creates a copy of the maze that we can modify and discard
* @return a copy of the maze
*/
private char[][] makeTempMaze() {
char[][] m = new char[mMaze.length][mMaze[0].length];
for (int i = 0; i < m.length; i++) {
for (int index = 0; index < m[0].length; index++) {
m[i][index] = mMaze[i][index];
}
}
return m;
}
/**
* converts the maze into a human readable string
* @param maze
* @return string for of the maze
*/
private String mazeToString(char[][] maze){
StringBuffer s = new StringBuffer();
s.append("\n");
for (int i = 0; i < maze.length; i++) {
for (int index = 0; index < maze[0].length; index++) {
s.append(maze[i][index] + " ");
}
s.append("\n");
}
return s.toString();
}
/**
* returns a human readable String of this maze
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString(){
return mazeToString(mMaze);
}
}

View File

@@ -0,0 +1,57 @@
/**
* This class is the Main class that will drive the Maze class
*/
public class MazeTester {
/**
* Called when the application first starts
* @param args
*/
public static void main(String[] args) {
char[][] m = {
{ '*', ' ', '*', '*', '*', '*', '*', '*', '*' },
{ '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', '*' },
{ '*', ' ', '*', '*', '*', '*', '*', ' ', '*' },
{ '*', ' ', '*', ' ', '*', ' ', ' ', ' ', '*' },
{ '*', ' ', '*', ' ', '*', '*', '*', ' ', '*' },
{ '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*' },
{ '*', '*', '*', ' ', '*', ' ', '*', '*', '*' },
{ '*', ' ', ' ', ' ', '*', ' ', '*', ' ', '*' },
{ '*', '*', '*', '*', '*', '*', '*', ' ', '*' } };
Maze maze = new Maze(m);
System.out.println("**********The Maze**********");
System.out.println(maze.toString());
System.out.println("**********The Tests:*********\n" +
"Walls are '*'\n" +
"Paths are ' '\n" +
"The Starting point is marked with 'S'\n" +
"The Soultion Path are '.'");
System.out.print("\nStarting Point:"+ 4+", "+3);
System.out.println("escape possiable: "+ maze.escape(4, 3));
System.out.print("\nStarting Point:"+ 5+", "+5);
System.out.println("escape possiable: "+ maze.escape(5, 5));
System.out.print("\nStarting Point:"+ 7+", "+1);
System.out.println("escape possiable: "+ maze.escape(7, 1));
// It may be necessary to test each call to "escape" independent of the
// other calls - by commenting out the other lines
// Do this if the maze is altered while finding an escape route
// Please remove these last 3 comment lines in your submitted code
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RecursiveFactorial</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Fri Nov 26 08:35:17 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

View File

@@ -0,0 +1,46 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 26, 2010
*/
/**
* this is a simple class to demonstrate java's recursive ability
* @author ricky barrette
*/
public class Main {
/**
* Creates a new Main
* @author ricky barrette
*/
public Main() {
System.out.println(factorial(5));
}
/**
* this method will calculate the factorial of an integer
* @param i
* @return the factorial of the supplied number
* @author ricky barrette
*/
private long factorial(int i) {
/*
* if the number is greater than 1, then we continue
* else we return our results
*/
if(i > 1)
return factorial(i -1) * i;
return i;
}
/**
* main method, called when the application starts
* @param args
* @author ricky barrette
*/
public static void main(String[] args) {
new Main();
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RecursiveLargestNumber</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Sun Dec 05 14:18:28 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,126 @@
import java.util.Arrays;
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 5, 2010
*/
/**
*
* @author ricky barrette
*/
public class LargestNumber {
private int[] mNumbers;
/**
* Creates a new LargestNumber
* @author ricky barrette
*/
public LargestNumber(int[] numbers) {
mNumbers = numbers;
sortArray();
}
/**
* sorts the array
*
* @author ricky barrette
*/
private void sortArray() {
Arrays.sort(mNumbers);
// for(int item : mNumbers)
// System.out.print(item+" ");
// System.out.println();
}
/**
* returns the largest number
* @return
* @author ricky barrette
*/
public int getLargestNumber(){
return mNumbers[mNumbers.length-1];
// return getLargestNumber(0, 0);
}
/**
* returns the largest number in the array
* @param i
* @param index
* @return the largest number in the array
* @deprecated since we started sorting the array
* @author ricky barrette
*/
private int getLargestNumber(int i, int index) {
try{
if (mNumbers[index] > i)
i = mNumbers[index];
} catch (ArrayIndexOutOfBoundsException e){
return i;
} finally {
index++;
}
return getLargestNumber(i, index);
}
/**
* finds a number in a sorted array
* @param number to find
* @return true if the number exist
* @author ricky barrette
*/
public boolean find(int number){
int min= 0, max = mNumbers.length - 1;
return find(number, min, min + ((max - min) / 2), max) != -1 ? true : false;
}
/**
* Recursively finds a number in the array
* @param number
* @param min
* @param mid
* @param max
* @return the index of the value, or -1 if it doesn't exist
* @author ricky barrette
*/
private int find(int number, int min, int mid, int max) {
// System.out.println(min+", "+mid+", "+max);
/*
* if the min, mid, max is what were looking for, then
* lets return the designated index
*/
if (mNumbers[min] == number) {
return min;
}
if (mNumbers[mid] == number) {
return mid;
}
if (mNumbers[max] == number) {
return max;
}
/*
* if we get to this point, lets prep our values for the next round
*/
if (mNumbers[mid] < number) {
min = mid;
}
if (mNumbers[mid] > number) {
max = mid;
}
mid = min + ((max - min) / 2);
/*
* if the mid is == max -1 then we will exit, or we will loop indefinitely
*/
if(mid == max-1)
return -1;
return find( number, min, mid, max);
}
}

View File

@@ -0,0 +1,36 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Dec 5, 2010
*/
/**
* This is the main driver class
* @author ricky barrette
*/
public class Main {
int[] mNumber = new int[]{ 1, 2, 3, 5, 45, 7, 9, 10, 16, 2, 100, 42, 23, 9, 0 };
/**
* Creates a new Main
* @author ricky barrette
*/
private Main(){
LargestNumber ln = new LargestNumber(mNumber);
System.out.println(ln.getLargestNumber());
System.out.println(ln.find(5));
System.out.println(ln.find(34));
}
/**
* main method, this is called when the application is first started
* @param args
* @author ricky barrette
*/
public static void main(String[] args) {
new Main();
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>StudentLedger</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Sun Jan 22 14:47:15 EST 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,135 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 21, 2010
*/
import java.util.ArrayList;
/**
* this will be a student ledger for grading students
* @author ricky barrette
*/
public class Ledger {
private ArrayList<Integer> mGradeList;
private String mStudentName;
/**
*
* Creates a new Ledger
* @param studentName
* @author ricky barrette
*/
public Ledger(String studentName) {
mGradeList = new ArrayList<Integer>();
mStudentName = studentName;
}
/**
* Creates a new Ledger
* @param studentName
* @param gradeList
* @author ricky barrette
*/
public Ledger(String studentName, ArrayList<Integer> gradeList) {
mGradeList = new ArrayList<Integer>();
addGrades(gradeList);
mStudentName = studentName;
}
/**
* Creates a new Ledger
* @param studentName
* @param gradeList
* @author ricky barrette
*/
public Ledger(String studentName, int[] gradeList) {
mGradeList = new ArrayList<Integer>();
addGrades(gradeList);
mStudentName = studentName;
}
/**
* Adds grades from an array
* @param gradeList
* @return the list of invalid grades, or null
* @author ricky barrette
*/
public ArrayList<Integer> addGrades (int[] gradeList){
ArrayList<Integer> badList = new ArrayList<Integer>();
for(int item : gradeList){
if(! addGrade(item)){
badList.add(item);
}
}
if(badList.size() != 0)
return badList;
return null;
}
/**
* adds grades from a list
* @param gradeList
* @return the list of inValid grades, or null
* @author ricky barrette
*/
public ArrayList<Integer> addGrades (ArrayList<Integer> gradeList){
ArrayList<Integer> badList = new ArrayList<Integer>();
for(int item : gradeList){
if(! addGrade(item)){
badList.add(item);
}
}
if(badList.size() != 0)
return badList;
return null;
}
/**
* adds a new grade to the grade list if valid
* @param newGrade
* @return true if the grade was added
* @author ricky barrette
*/
public boolean addGrade(int newGrade){
if(newGrade >= 0 && newGrade <= 100){
mGradeList.add(newGrade);
return true;
}
System.out.println(newGrade +" is an invalid grade");
return false;
}
/**
* gets all the grades for this student
* @return an array containing all the grades
* @author ricky barrette
*/
public ArrayList<Integer> getGrades(){
return mGradeList;
}
/**
* returns the name of the student
* @return student's name
* @author ricky barrette
*/
public String getStudentName(){
return mStudentName;
}
/**
* computes the average grade of the student
* @return the students current average
* @author ricky barrette
*/
public int getAverage(){
int total = 0;
int count;
for(count = 0; count < mGradeList.size(); count++){
total = total + mGradeList.get(count);
}
return total / count;
}
}

View File

@@ -0,0 +1,49 @@
/**
* @author Twenty Codes, LLC
* @author ricky barrette
* @date Nov 22, 2010
*/
/**
* this will be the driver class to test the Ledger
* @author ricky barrette
*/
public class Students {
private int[] startingGrades = new int[] { 90, 75, 100, 60, 90, 92, 96, 100, 42, 100 };
/**
* Creates a new Students
* @author ricky barrette
*/
public Students() {
Ledger student1 = new Ledger("Student 1", startingGrades);
System.out.println(student1.getAverage());
student1.addGrade(100);
System.out.println(student1.getAverage());
int[] semester2 = new int[] { 90, 80, 70, 100, 101, 90, 90 };
System.out.println(student1.addGrades(semester2).get(0));
System.out.println(student1.getAverage() +"\n");
for(int item : student1.getGrades()){
System.out.print(item+", ");
}
System.out.println("\n"+student1.getAverage());
}
/**
* main method, called when the application starts
* @param args
* @author ricky barrette
*/
public static void main(String[] args) {
new Students();
}
}

6
Java/Sudoku/.classpath Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>

17
Java/Sudoku/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Sudoku</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
#Tue Dec 07 18:50:24 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Some files were not shown because too many files have changed in this diff Show More