commit f5e306f67f1e4215df8d16a5e68d6c6fb0f49b3f Author: Ricky Barrette Date: Sun Jan 22 16:14:32 2012 -0500 Initial Commit diff --git a/C/.directory b/C/.directory new file mode 100644 index 0000000..a26ba62 --- /dev/null +++ b/C/.directory @@ -0,0 +1,3 @@ +[Dolphin] +Timestamp=2011,10,24,7,45,18 +Version=2 diff --git a/C/Sudoku/Makefile b/C/Sudoku/Makefile new file mode 100644 index 0000000..96130e7 --- /dev/null +++ b/C/Sudoku/Makefile @@ -0,0 +1,4 @@ +all: + g++ -o sudoku sudoku.cpp +clean: + rm sudoku \ No newline at end of file diff --git a/C/Sudoku/sudoku b/C/Sudoku/sudoku new file mode 100755 index 0000000..d0c9cfd Binary files /dev/null and b/C/Sudoku/sudoku differ diff --git a/C/Sudoku/sudoku.cpp b/C/Sudoku/sudoku.cpp new file mode 100644 index 0000000..3389268 --- /dev/null +++ b/C/Sudoku/sudoku.cpp @@ -0,0 +1,169 @@ + +/** + * sudoku.cpp + * + * This program will be used to solve sudoku puzzles + * + * @date oct, 25, 2011 + * @author ricky barrette + */ + +#include +#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; +} diff --git a/C/Sudoku/sudoku.h b/C/Sudoku/sudoku.h new file mode 100644 index 0000000..f70d302 --- /dev/null +++ b/C/Sudoku/sudoku.h @@ -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]); \ No newline at end of file diff --git a/C/ThousandToOne.c b/C/ThousandToOne.c new file mode 100644 index 0000000..145f6bc --- /dev/null +++ b/C/ThousandToOne.c @@ -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); + } +} diff --git a/C/hello.c b/C/hello.c new file mode 100644 index 0000000..3459e19 --- /dev/null +++ b/C/hello.c @@ -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"); +} \ No newline at end of file diff --git a/C/io.c b/C/io.c new file mode 100644 index 0000000..87c418a --- /dev/null +++ b/C/io.c @@ -0,0 +1,18 @@ +/** + * io.c + * This program will demonstrate basic I\O + * @author ricky barrette + * @date Oct 24, 2011 + */ + +#include +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"; +} diff --git a/Java/BankAccount/.classpath b/Java/BankAccount/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/BankAccount/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/BankAccount/.project b/Java/BankAccount/.project new file mode 100644 index 0000000..7b8f5b3 --- /dev/null +++ b/Java/BankAccount/.project @@ -0,0 +1,17 @@ + + + BankAccount + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/BankAccount/.settings/org.eclipse.jdt.core.prefs b/Java/BankAccount/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..81e689b --- /dev/null +++ b/Java/BankAccount/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/Account.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/Account.class new file mode 100644 index 0000000..d873bbd Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/Account.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountDB.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountDB.class new file mode 100644 index 0000000..452c3fd Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountDB.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountExistsException.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountExistsException.class new file mode 100644 index 0000000..8c632a8 Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/AccountExistsException.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/TransactionType.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/TransactionType.class new file mode 100644 index 0000000..84b22aa Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/TransactionType.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.class new file mode 100644 index 0000000..5cd5dfe Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/MainWindow.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/MainWindow.class new file mode 100644 index 0000000..c134568 Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/MainWindow.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.class new file mode 100644 index 0000000..bad7086 Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/SearchDialog.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/SearchDialog.class new file mode 100644 index 0000000..659b635 Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/SearchDialog.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.class new file mode 100644 index 0000000..593ddee Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$1.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$1.class new file mode 100644 index 0000000..090b51f Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$1.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$2.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$2.class new file mode 100644 index 0000000..370980b Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog$2.class differ diff --git a/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.class b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.class new file mode 100644 index 0000000..06dc02d Binary files /dev/null and b/Java/BankAccount/bin/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.class differ diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/Account.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/Account.java new file mode 100644 index 0000000..5a4dfeb --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/Account.java @@ -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{ + + 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; + } + +} \ No newline at end of file diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountDB.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountDB.java new file mode 100644 index 0000000..ceaf88d --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountDB.java @@ -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 array; + + /** + * Creates a new AccountDB + */ + public AccountDB() { + array = new ArrayList(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 findAccount(String owner) { + ArrayList temp = new ArrayList(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 searchForAccount(String search) { + long account = -1; + try { + account = Long.parseLong(search); + } catch (Exception e) { + // TO NOTHING + } + ArrayList temp = new ArrayList(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; + } + +} \ No newline at end of file diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountExistsException.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountExistsException.java new file mode 100644 index 0000000..4e20306 --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/AccountExistsException.java @@ -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); + } + +} diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/TransactionType.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/TransactionType.java new file mode 100644 index 0000000..32d02f1 --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/TransactionType.java @@ -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 + +} diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.java new file mode 100644 index 0000000..fa8798e --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/AddAccountDialog.java @@ -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); + } + } + } +} \ No newline at end of file diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/MainWindow.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/MainWindow.java new file mode 100644 index 0000000..0e9034c --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/MainWindow.java @@ -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(); + } + } + } + +} \ No newline at end of file diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.java new file mode 100644 index 0000000..b3e409f --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/RemoveAccounteDialog.java @@ -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); + } + } + +} diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/SearchDialog.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/SearchDialog.java new file mode 100644 index 0000000..e219005 --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/SearchDialog.java @@ -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); + } + } + +} diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.java new file mode 100644 index 0000000..e7a68da --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/ShowAllDialog.java @@ -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); + } +} diff --git a/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.java b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.java new file mode 100644 index 0000000..5620631 --- /dev/null +++ b/Java/BankAccount/src/com/TwentyCodes/java/BankAccount/UI/TransactionDialog.java @@ -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"); + } + } + } +} diff --git a/Java/Count.java b/Java/Count.java new file mode 100644 index 0000000..18cdd2a --- /dev/null +++ b/Java/Count.java @@ -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); + } + } +} diff --git a/Java/DiceRoller.java b/Java/DiceRoller.java new file mode 100644 index 0000000..fd732e3 --- /dev/null +++ b/Java/DiceRoller.java @@ -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 diff --git a/Java/DiceRoller/.classpath b/Java/DiceRoller/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/DiceRoller/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/DiceRoller/.project b/Java/DiceRoller/.project new file mode 100644 index 0000000..0bb6026 --- /dev/null +++ b/Java/DiceRoller/.project @@ -0,0 +1,17 @@ + + + DiceRoller + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/DiceRoller/.settings/org.eclipse.jdt.core.prefs b/Java/DiceRoller/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c8485ef --- /dev/null +++ b/Java/DiceRoller/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/DiceRoller/bin/DiceRoller.class b/Java/DiceRoller/bin/DiceRoller.class new file mode 100644 index 0000000..721e2b9 Binary files /dev/null and b/Java/DiceRoller/bin/DiceRoller.class differ diff --git a/Java/DiceRoller/bin/MainWindow.class b/Java/DiceRoller/bin/MainWindow.class new file mode 100644 index 0000000..f3fae65 Binary files /dev/null and b/Java/DiceRoller/bin/MainWindow.class differ diff --git a/Java/DiceRoller/src/DiceRoller.java b/Java/DiceRoller/src/DiceRoller.java new file mode 100644 index 0000000..002130c --- /dev/null +++ b/Java/DiceRoller/src/DiceRoller.java @@ -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; + } + +} \ No newline at end of file diff --git a/Java/DiceRoller/src/MainWindow.java b/Java/DiceRoller/src/MainWindow.java new file mode 100644 index 0000000..e13aefa --- /dev/null +++ b/Java/DiceRoller/src/MainWindow.java @@ -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(); + } +} diff --git a/Java/EnhancedForLoop/.classpath b/Java/EnhancedForLoop/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/EnhancedForLoop/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/EnhancedForLoop/.project b/Java/EnhancedForLoop/.project new file mode 100644 index 0000000..f85c84d --- /dev/null +++ b/Java/EnhancedForLoop/.project @@ -0,0 +1,17 @@ + + + EnhancedForLoop + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/EnhancedForLoop/.settings/org.eclipse.jdt.core.prefs b/Java/EnhancedForLoop/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..2a39bfd --- /dev/null +++ b/Java/EnhancedForLoop/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/EnhancedForLoop/bin/Main.class b/Java/EnhancedForLoop/bin/Main.class new file mode 100644 index 0000000..38d43d9 Binary files /dev/null and b/Java/EnhancedForLoop/bin/Main.class differ diff --git a/Java/EnhancedForLoop/src/Main.java b/Java/EnhancedForLoop/src/Main.java new file mode 100644 index 0000000..3e5f1b7 --- /dev/null +++ b/Java/EnhancedForLoop/src/Main.java @@ -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); + } + } + +} \ No newline at end of file diff --git a/Java/EvenOrOdd.java b/Java/EvenOrOdd.java new file mode 100644 index 0000000..6fa0e08 --- /dev/null +++ b/Java/EvenOrOdd.java @@ -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 diff --git a/Java/HelloWord.java b/Java/HelloWord.java new file mode 100644 index 0000000..76876ac --- /dev/null +++ b/Java/HelloWord.java @@ -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!"); + } +} diff --git a/Java/IsPrime/.classpath b/Java/IsPrime/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/IsPrime/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/IsPrime/.project b/Java/IsPrime/.project new file mode 100644 index 0000000..e90d560 --- /dev/null +++ b/Java/IsPrime/.project @@ -0,0 +1,17 @@ + + + IsPrime + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/IsPrime/.settings/.svn/entries b/Java/IsPrime/.settings/.svn/entries new file mode 100644 index 0000000..2d0d9b8 --- /dev/null +++ b/Java/IsPrime/.settings/.svn/entries @@ -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 + diff --git a/Java/IsPrime/.settings/.svn/prop-base/org.eclipse.jdt.core.prefs.svn-base b/Java/IsPrime/.settings/.svn/prop-base/org.eclipse.jdt.core.prefs.svn-base new file mode 100644 index 0000000..138f983 --- /dev/null +++ b/Java/IsPrime/.settings/.svn/prop-base/org.eclipse.jdt.core.prefs.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 10 +text/plain +END diff --git a/Java/IsPrime/.settings/.svn/text-base/org.eclipse.jdt.core.prefs.svn-base b/Java/IsPrime/.settings/.svn/text-base/org.eclipse.jdt.core.prefs.svn-base new file mode 100644 index 0000000..95bb6e8 --- /dev/null +++ b/Java/IsPrime/.settings/.svn/text-base/org.eclipse.jdt.core.prefs.svn-base @@ -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 diff --git a/Java/IsPrime/.settings/org.eclipse.jdt.core.prefs b/Java/IsPrime/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..95bb6e8 --- /dev/null +++ b/Java/IsPrime/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/IsPrime/.svn/entries b/Java/IsPrime/.svn/entries new file mode 100644 index 0000000..1d5c01c --- /dev/null +++ b/Java/IsPrime/.svn/entries @@ -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 + diff --git a/Java/IsPrime/.svn/prop-base/.classpath.svn-base b/Java/IsPrime/.svn/prop-base/.classpath.svn-base new file mode 100644 index 0000000..138f983 --- /dev/null +++ b/Java/IsPrime/.svn/prop-base/.classpath.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 10 +text/plain +END diff --git a/Java/IsPrime/.svn/prop-base/.project.svn-base b/Java/IsPrime/.svn/prop-base/.project.svn-base new file mode 100644 index 0000000..138f983 --- /dev/null +++ b/Java/IsPrime/.svn/prop-base/.project.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 10 +text/plain +END diff --git a/Java/IsPrime/.svn/text-base/.classpath.svn-base b/Java/IsPrime/.svn/text-base/.classpath.svn-base new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/IsPrime/.svn/text-base/.classpath.svn-base @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/IsPrime/.svn/text-base/.project.svn-base b/Java/IsPrime/.svn/text-base/.project.svn-base new file mode 100644 index 0000000..e90d560 --- /dev/null +++ b/Java/IsPrime/.svn/text-base/.project.svn-base @@ -0,0 +1,17 @@ + + + IsPrime + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/IsPrime/bin/.svn/entries b/Java/IsPrime/bin/.svn/entries new file mode 100644 index 0000000..784cdc6 --- /dev/null +++ b/Java/IsPrime/bin/.svn/entries @@ -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 + diff --git a/Java/IsPrime/bin/.svn/prop-base/IsPrime.class.svn-base b/Java/IsPrime/bin/.svn/prop-base/IsPrime.class.svn-base new file mode 100644 index 0000000..5e9587e --- /dev/null +++ b/Java/IsPrime/bin/.svn/prop-base/IsPrime.class.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 24 +application/octet-stream +END diff --git a/Java/IsPrime/bin/.svn/text-base/IsPrime.class.svn-base b/Java/IsPrime/bin/.svn/text-base/IsPrime.class.svn-base new file mode 100644 index 0000000..beef9a7 Binary files /dev/null and b/Java/IsPrime/bin/.svn/text-base/IsPrime.class.svn-base differ diff --git a/Java/IsPrime/bin/IsPrime.class b/Java/IsPrime/bin/IsPrime.class new file mode 100644 index 0000000..beef9a7 Binary files /dev/null and b/Java/IsPrime/bin/IsPrime.class differ diff --git a/Java/IsPrime/src/.svn/entries b/Java/IsPrime/src/.svn/entries new file mode 100644 index 0000000..fafeef5 --- /dev/null +++ b/Java/IsPrime/src/.svn/entries @@ -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 + diff --git a/Java/IsPrime/src/.svn/prop-base/IsPrime.java.svn-base b/Java/IsPrime/src/.svn/prop-base/IsPrime.java.svn-base new file mode 100644 index 0000000..138f983 --- /dev/null +++ b/Java/IsPrime/src/.svn/prop-base/IsPrime.java.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:mime-type +V 10 +text/plain +END diff --git a/Java/IsPrime/src/.svn/text-base/IsPrime.java.svn-base b/Java/IsPrime/src/.svn/text-base/IsPrime.java.svn-base new file mode 100644 index 0000000..67af37e --- /dev/null +++ b/Java/IsPrime/src/.svn/text-base/IsPrime.java.svn-base @@ -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"); + } + +} \ No newline at end of file diff --git a/Java/IsPrime/src/IsPrime.java b/Java/IsPrime/src/IsPrime.java new file mode 100644 index 0000000..67af37e --- /dev/null +++ b/Java/IsPrime/src/IsPrime.java @@ -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"); + } + +} \ No newline at end of file diff --git a/Java/IsPrimeFor.java b/Java/IsPrimeFor.java new file mode 100644 index 0000000..f08e726 --- /dev/null +++ b/Java/IsPrimeFor.java @@ -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"); + } + +} diff --git a/Java/IsPrimeMethods.java b/Java/IsPrimeMethods.java new file mode 100644 index 0000000..829103c --- /dev/null +++ b/Java/IsPrimeMethods.java @@ -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 diff --git a/Java/IsPrimeWhile.java b/Java/IsPrimeWhile.java new file mode 100644 index 0000000..b8c0b5e --- /dev/null +++ b/Java/IsPrimeWhile.java @@ -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 diff --git a/Java/MazeTester/.classpath b/Java/MazeTester/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/MazeTester/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/MazeTester/.project b/Java/MazeTester/.project new file mode 100644 index 0000000..e14f9b7 --- /dev/null +++ b/Java/MazeTester/.project @@ -0,0 +1,17 @@ + + + MazeTester + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/MazeTester/.settings/org.eclipse.jdt.core.prefs b/Java/MazeTester/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..dc0732e --- /dev/null +++ b/Java/MazeTester/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/MazeTester/bin/Maze.class b/Java/MazeTester/bin/Maze.class new file mode 100644 index 0000000..3353008 Binary files /dev/null and b/Java/MazeTester/bin/Maze.class differ diff --git a/Java/MazeTester/bin/MazeTester.class b/Java/MazeTester/bin/MazeTester.class new file mode 100644 index 0000000..f4ca749 Binary files /dev/null and b/Java/MazeTester/bin/MazeTester.class differ diff --git a/Java/MazeTester/src/Maze.java b/Java/MazeTester/src/Maze.java new file mode 100644 index 0000000..5c22589 --- /dev/null +++ b/Java/MazeTester/src/Maze.java @@ -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); + } +} \ No newline at end of file diff --git a/Java/MazeTester/src/MazeTester.java b/Java/MazeTester/src/MazeTester.java new file mode 100644 index 0000000..c51d988 --- /dev/null +++ b/Java/MazeTester/src/MazeTester.java @@ -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 + } +} diff --git a/Java/RecursiveFactorial/.classpath b/Java/RecursiveFactorial/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/RecursiveFactorial/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/RecursiveFactorial/.project b/Java/RecursiveFactorial/.project new file mode 100644 index 0000000..1f7f084 --- /dev/null +++ b/Java/RecursiveFactorial/.project @@ -0,0 +1,17 @@ + + + RecursiveFactorial + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/RecursiveFactorial/.settings/org.eclipse.jdt.core.prefs b/Java/RecursiveFactorial/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..fca110b --- /dev/null +++ b/Java/RecursiveFactorial/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/RecursiveFactorial/bin/Main.class b/Java/RecursiveFactorial/bin/Main.class new file mode 100644 index 0000000..1153248 Binary files /dev/null and b/Java/RecursiveFactorial/bin/Main.class differ diff --git a/Java/RecursiveFactorial/src/Main.java b/Java/RecursiveFactorial/src/Main.java new file mode 100644 index 0000000..ef608d1 --- /dev/null +++ b/Java/RecursiveFactorial/src/Main.java @@ -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(); + } + +} diff --git a/Java/RecursiveLargestNumber/.classpath b/Java/RecursiveLargestNumber/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/RecursiveLargestNumber/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/RecursiveLargestNumber/.project b/Java/RecursiveLargestNumber/.project new file mode 100644 index 0000000..d1f6aa2 --- /dev/null +++ b/Java/RecursiveLargestNumber/.project @@ -0,0 +1,17 @@ + + + RecursiveLargestNumber + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/RecursiveLargestNumber/.settings/org.eclipse.jdt.core.prefs b/Java/RecursiveLargestNumber/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..e91cf1e --- /dev/null +++ b/Java/RecursiveLargestNumber/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/RecursiveLargestNumber/bin/LargestNumber.class b/Java/RecursiveLargestNumber/bin/LargestNumber.class new file mode 100644 index 0000000..2f309a0 Binary files /dev/null and b/Java/RecursiveLargestNumber/bin/LargestNumber.class differ diff --git a/Java/RecursiveLargestNumber/bin/Main.class b/Java/RecursiveLargestNumber/bin/Main.class new file mode 100644 index 0000000..789176c Binary files /dev/null and b/Java/RecursiveLargestNumber/bin/Main.class differ diff --git a/Java/RecursiveLargestNumber/src/LargestNumber.java b/Java/RecursiveLargestNumber/src/LargestNumber.java new file mode 100644 index 0000000..8f32b78 --- /dev/null +++ b/Java/RecursiveLargestNumber/src/LargestNumber.java @@ -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); + } + +} \ No newline at end of file diff --git a/Java/RecursiveLargestNumber/src/Main.java b/Java/RecursiveLargestNumber/src/Main.java new file mode 100644 index 0000000..3c851d3 --- /dev/null +++ b/Java/RecursiveLargestNumber/src/Main.java @@ -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(); + } + +} \ No newline at end of file diff --git a/Java/StudentLedger/.classpath b/Java/StudentLedger/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/StudentLedger/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/StudentLedger/.project b/Java/StudentLedger/.project new file mode 100644 index 0000000..abc13e5 --- /dev/null +++ b/Java/StudentLedger/.project @@ -0,0 +1,17 @@ + + + StudentLedger + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/StudentLedger/.settings/org.eclipse.jdt.core.prefs b/Java/StudentLedger/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..017fc91 --- /dev/null +++ b/Java/StudentLedger/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/StudentLedger/bin/Ledger.class b/Java/StudentLedger/bin/Ledger.class new file mode 100644 index 0000000..afa71c5 Binary files /dev/null and b/Java/StudentLedger/bin/Ledger.class differ diff --git a/Java/StudentLedger/bin/Students.class b/Java/StudentLedger/bin/Students.class new file mode 100644 index 0000000..bef348f Binary files /dev/null and b/Java/StudentLedger/bin/Students.class differ diff --git a/Java/StudentLedger/src/Ledger.java b/Java/StudentLedger/src/Ledger.java new file mode 100644 index 0000000..7d4deb2 --- /dev/null +++ b/Java/StudentLedger/src/Ledger.java @@ -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 mGradeList; + private String mStudentName; + + /** + * + * Creates a new Ledger + * @param studentName + * @author ricky barrette + */ + public Ledger(String studentName) { + mGradeList = new ArrayList(); + mStudentName = studentName; + } + + /** + * Creates a new Ledger + * @param studentName + * @param gradeList + * @author ricky barrette + */ + public Ledger(String studentName, ArrayList gradeList) { + mGradeList = new ArrayList(); + addGrades(gradeList); + mStudentName = studentName; + } + + /** + * Creates a new Ledger + * @param studentName + * @param gradeList + * @author ricky barrette + */ + public Ledger(String studentName, int[] gradeList) { + mGradeList = new ArrayList(); + addGrades(gradeList); + mStudentName = studentName; + } + + /** + * Adds grades from an array + * @param gradeList + * @return the list of invalid grades, or null + * @author ricky barrette + */ + public ArrayList addGrades (int[] gradeList){ + ArrayList badList = new ArrayList(); + 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 addGrades (ArrayList gradeList){ + ArrayList badList = new ArrayList(); + 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 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; + } +} \ No newline at end of file diff --git a/Java/StudentLedger/src/Students.java b/Java/StudentLedger/src/Students.java new file mode 100644 index 0000000..bbefec1 --- /dev/null +++ b/Java/StudentLedger/src/Students.java @@ -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(); + } + +} diff --git a/Java/Sudoku/.classpath b/Java/Sudoku/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/Sudoku/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/Sudoku/.project b/Java/Sudoku/.project new file mode 100644 index 0000000..b273577 --- /dev/null +++ b/Java/Sudoku/.project @@ -0,0 +1,17 @@ + + + Sudoku + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/Sudoku/.settings/org.eclipse.jdt.core.prefs b/Java/Sudoku/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..064827e --- /dev/null +++ b/Java/Sudoku/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/Java/Sudoku/bin/Main.class b/Java/Sudoku/bin/Main.class new file mode 100644 index 0000000..9513488 Binary files /dev/null and b/Java/Sudoku/bin/Main.class differ diff --git a/Java/Sudoku/bin/Sudoku.class b/Java/Sudoku/bin/Sudoku.class new file mode 100644 index 0000000..c8ccba6 Binary files /dev/null and b/Java/Sudoku/bin/Sudoku.class differ diff --git a/Java/Sudoku/src/Main.java b/Java/Sudoku/src/Main.java new file mode 100644 index 0000000..e8fc56b --- /dev/null +++ b/Java/Sudoku/src/Main.java @@ -0,0 +1,53 @@ +/** + * @author Twenty Codes, LLC + * @author ricky barrette + * @date Dec 7, 2010 + */ + +/** + * Driver class to test my sudoku class + * @author ricky barrette + */ +public class Main { + + int[][] puzzle = new int[][] { + {0, 8, 0, 4, 0, 2, 0, 6, 0}, + {0, 3, 4, 0, 0, 0, 9, 1, 0}, + {9, 6, 0, 0, 0, 0, 0, 8, 4}, + {0, 0, 0, 2, 1, 6, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 3, 5, 7, 0, 0, 0}, + {8, 4, 0, 0, 0, 0, 0, 7, 5}, + {0, 2, 6, 0, 0, 0, 1, 3, 0}, + {0, 9, 0, 7, 0, 1, 0, 4, 0}, + }; + + int[][] puzzle2 = new int[][] { + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + }; + + public Main(){ + Sudoku s = new Sudoku(puzzle2); + System.out.println(s.solve()); + System.out.println(s.toString()); + + } + + /** + * + * @param args + * @author ricky barrette + */ + public static void main (String[] args){ + new Main(); + } + +} \ No newline at end of file diff --git a/Java/Sudoku/src/Sudoku.java b/Java/Sudoku/src/Sudoku.java new file mode 100644 index 0000000..e501bfd --- /dev/null +++ b/Java/Sudoku/src/Sudoku.java @@ -0,0 +1,170 @@ +/** + * @author Twenty Codes, LLC + * @author ricky barrette + * @date Dec 7, 2010 + */ + +/** + * This will be a sudoku puzzle + * @author ricky barrette + */ +public class Sudoku { + + private int[][] mPuzzle; + private final boolean DEBUG = true; + + /** + * Creates a new Sudoku + * @author ricky barrette + * @param puzzle + */ + public Sudoku(int[][] puzzle) { + mPuzzle = puzzle; + } + + /** + * creates a copy of the maze that we can modify and discard + * @return a copy of the maze + */ + private int[][] makeTempMaze() { + int[][] m = new int[mPuzzle.length][mPuzzle[0].length]; + for (int i = 0; i < m.length; i++) { + for (int index = 0; index < m[0].length; index++) { + m[i][index] = mPuzzle[i][index]; + } + } + return m; + } + + /** + * solves the puzzle + * @return true if the puzzle is solvable + * @author ricky barrette + */ + public boolean solve(){ + return solve(0,0, mPuzzle); + } + + /** + * Recursively solves a sudoku puzzle + * @return true if the puzzle is solvable + * @author ricky barrette + */ + private boolean solve(int row, int column, int[][] temp){ + + /* + * move on to the next row, if we have no more columns + */ + if (column == 9) { + column = 0; + if (++row == 9) + return true; + } + + /* + * if this spot is filled in, then lets move on + */ + if (temp[row][column] != 0) + solve(row, column +1, temp); + + /* + * we are going to try every number, to find one that is valid. + */ + for(int i = 1; i <= 9; ++i){ + if(isValid(i, row, column, temp)){ + temp[row][column] = i; + if(solve(row, column +1, temp)) + return true; + } + } + + /* + * reset on backtrack + */ + temp[row][column] = 0; + + /* + * 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(puzzleToString(temp)); + } + return false; + } + + /** + * checks to see if the value is a valid answer for this location + * @param newValue in question + * @param row of newValue + * @param column of newValue + * @param temp puzzle + * @return true if the newValue is a valid answer + * @author ricky barrette + */ + private boolean isValid(int newValue, int row, int column, int[][] temp) { + + /* + * row + */ + for (int i = 0; i < 9; ++i) + if (newValue == temp[i][column]) + return false; + + /* + * column + */ + for (int i = 0; i < 9; ++i) + if (newValue == temp[row][i]) + return false; + + int boxRowOffset = (row / 3)*3; + int boxColOffset = (column / 3)*3; + + /* + * box + */ + for (int i = 0; i < 3; ++i) + for (int index = 0; index < 3; ++index) + if (newValue == temp[boxRowOffset+i][boxColOffset+index]) + return false; + + /* + * no violations, so it's legal + */ + return true; + } + + /** + * converts the maze into a human readable string + * @param maze + * @return string for of the maze + */ + private String puzzleToString(int[][] puzzle){ + StringBuffer s = new StringBuffer(); + s.append("\n"); + for (int i = 0; i < puzzle.length; i++) { + for (int index = 0; index < puzzle[0].length; index++) { + s.append(puzzle[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 puzzleToString(mPuzzle); + } + +} \ No newline at end of file diff --git a/Java/TempConverter/.classpath b/Java/TempConverter/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/TempConverter/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/TempConverter/.project b/Java/TempConverter/.project new file mode 100644 index 0000000..a1fdd5e --- /dev/null +++ b/Java/TempConverter/.project @@ -0,0 +1,17 @@ + + + TempConverter + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/TempConverter/.settings/org.eclipse.jdt.core.prefs b/Java/TempConverter/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6a580ba --- /dev/null +++ b/Java/TempConverter/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Nov 18 10:03:34 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 diff --git a/Java/TempConverter/bin/TempConverter.class b/Java/TempConverter/bin/TempConverter.class new file mode 100644 index 0000000..8b36f51 Binary files /dev/null and b/Java/TempConverter/bin/TempConverter.class differ diff --git a/Java/TempConverter/bin/TempUnit.class b/Java/TempConverter/bin/TempUnit.class new file mode 100644 index 0000000..3870798 Binary files /dev/null and b/Java/TempConverter/bin/TempUnit.class differ diff --git a/Java/TempConverter/src/TempConverter.java b/Java/TempConverter/src/TempConverter.java new file mode 100644 index 0000000..dece7ad --- /dev/null +++ b/Java/TempConverter/src/TempConverter.java @@ -0,0 +1,220 @@ +import java.util.Scanner; + +/** + * @author Twenty Codes, LLC + * @author ricky barrette + * @date Nov 18, 2010 + */ + +/** + * This is a simple temp converter application + * + * @author ricky barrette + */ +public class TempConverter { + + /** + * This is the main method of this application + * + * @param args + * @author ricky barrette + */ + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + Scanner scanInput; + String input; + boolean isValid = false; + boolean isNumber; + double value = 0; + double answer = 0; + + /* + * the following code will be used for units: + * 0 F + * 1 C + * 2 R + * 3 K + */ + int startingUnit = -1; + int endingUnit = -1; + + System.out.println("*****************************************************************\n" + + "This is ricky's temp converter\n" + + "The format used here will be \n" + + "example: 32.0 F C\n" + + "The output will be: 0 °C\n" + + "Supported units are °F, °C, °R, °K\n" + + "*****************************************************************"); + + /* + * here we will get the users input and process it + */ + do { + isValid = true; + System.out.print("please enter the desired temp conversion:"); + input = scan.nextLine(); + + scanInput = new Scanner(input); + + /* + * here we will get the first token from the provided string + */ + try { + value = scanInput.nextFloat(); + isNumber = true; + } catch (Exception e) { + System.out.print("Sorry that was not a valid entry, please try again"); + isNumber = false; + isValid = false; + } + + /* + * if the first token was a valid entry, then lets check the next token + */ + if (isNumber) { + String unit = null; + try { + unit = scanInput.next(); + if (unit.equalsIgnoreCase("f")) { + startingUnit = 0; + } else if (unit.equalsIgnoreCase("c")) { + startingUnit = 1; + } else if (unit.equalsIgnoreCase("r")) { + startingUnit = 2; + } else if (unit.equalsIgnoreCase("k")) { + startingUnit = 3; + } else { + isValid = false; + } + } catch (Exception e1) { + isValid = false; + } + + /* + * now the last token + */ + String newUnit = null; + try { + newUnit = scanInput.next(); + if (newUnit.equalsIgnoreCase("f")) { + endingUnit = 0; + } else if (newUnit.equalsIgnoreCase("c")) { + endingUnit = 1; + } else if (newUnit.equalsIgnoreCase("r")) { + endingUnit = 2; + } else if (newUnit.equalsIgnoreCase("k")) { + endingUnit = 3; + } else { + isValid = false; + } + } catch (Exception e) { + isValid = false; + } + + + } + } while (!isValid); + + /* + * This switch block will handle figuring out which equation to use + * now that we have a valid entry, its time for some math! + * Remember: + * 0 F + * 1 C + * 2 R + * 3 K + */ + switch(startingUnit){ + case 0: + switch(endingUnit){ + case 0: + answer = value; + break; + case 1: + answer = ((5.0/9.0) * (value - 32)); + break; + case 2: + answer = value + 460; + break; + case 3: + answer = (5.0/9.0) * (value - 32); + answer = answer + 273; + break; + } + break; + + case 1: + switch(endingUnit){ + case 0: + answer = ((9.0/5.0) * value) + 32; + break; + case 1: + answer = value; + break; + case 2: + answer = ((9.0/5.0) * value) + 32; + answer = answer + 460; + break; + case 3: + answer = value + 273; + break; + } + break; + + case 2: + switch(endingUnit){ + case 0: + answer = value - 460; + break; + case 1: + answer = value - 460; + answer = (5.0/9.0) * (answer - 32); + break; + case 2: + answer = value; + break; + case 3: + answer = value - 460; + answer = ((5.0/9.0) * (answer - 32)); + answer = answer + 273; + break; + } + break; + + case 3: + switch(endingUnit){ + case 0: + answer = value - 273; + answer = ((9.0/5.0) * answer) + 32; + break; + case 1: + answer = value - 273; + break; + case 2: + answer = value - 293; + answer = ((9.0/5.0) * answer) + 32; + answer = answer + 460; + break; + case 3: + answer = value; + break; + } + break; + } + + switch(endingUnit){ + case 0: + System.out.println(answer +"°F"); + break; + case 1: + System.out.println(answer +"°C"); + break; + case 2: + System.out.println(answer +"°R"); + break; + case 3: + System.out.println(answer+"°K"); + break; + } + } +} \ No newline at end of file diff --git a/Java/TempConverter/src/TempUnit.java b/Java/TempConverter/src/TempUnit.java new file mode 100644 index 0000000..cb21880 --- /dev/null +++ b/Java/TempConverter/src/TempUnit.java @@ -0,0 +1,13 @@ +/** + * @author Twenty Codes, LLC + * @author ricky barrette + * @date Nov 21, 2010 + */ + +/** + * This will be a temp unit enum + * @author ricky barrette + */ +public enum TempUnit { + FARENHEIT, CELCIUS, KELVIN, RANKIN +} \ No newline at end of file diff --git a/Java/Test.java b/Java/Test.java new file mode 100644 index 0000000..a1c8935 --- /dev/null +++ b/Java/Test.java @@ -0,0 +1,95 @@ +/* +* this is my test class that will test a number ented to see if it is even/odd, and if it is prime or not +* this class demonstrates how to handle: + * arguments passed from the starting command + * if/else blocks, for loops + * and how to use simple methods + * how to parse a String to an int + * try/catch blocks for error checking +* @author ricky.barrette +*/ +import java.util.Scanner; + +public class Test{ + + /* + * this is the main method of this program + * @param args from the command + * @author ricky.barrette + */ + public static void main(String args[]){ + + long number; + + /* + * if the user provided input then try to parse that, + * if we can not parse it, then we notify the user + */ + if (args.length > 0){ + try{ + number = Long.parseLong(args[0]); + } catch(Exception e){ + System.out.println("Sorry that was not a number, please try again"); + System.out.println(e.toString()); + number = getUserInput(); + } + } else + number = getUserInput(); + + //output results + System.out.println(number+" is "+ evenOrOdd(number)); + System.out.println(number+" is "+ isNumberPrime(number)); + } + + /* + * returns whether or not the number is even + * @param number in question + * @author ricky.barrette + */ + public static String evenOrOdd(long number){ + //tell me if the number is even or odd + if ( (number % 2) == 0 ) + return "even"; + else + return "odd"; + } + + /* + * asks for users input + * @return users input + * @author ricky.barrette + */ + private static long getUserInput(){ + boolean isNumber = false; + long number = 0; + //retive data + while(! isNumber){ + try{ + // create a scanner to except user input via keyboard + Scanner scan = new Scanner(System.in); + //ask for users input + System.out.print("Enter a number:"); + number = scan.nextLong(); + isNumber = true; + } catch(Exception e){ + System.out.println("Sorry that was not a number, please try again"); + System.out.println(e.toString()); + } + } + return number; + } + + /* + * returns whether or not the number is prime + * @param number in question + * @author ricky.barrette + */ + public static String isNumberPrime(long number){ + //tell me if the number is prime or not + for (long i = 2; i < number; i++){ + if ( (number % i) == 0) + return "not prime"; + } + return "prime"; + } +} diff --git a/Java/ThousandTofive/.classpath b/Java/ThousandTofive/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/ThousandTofive/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/ThousandTofive/.project b/Java/ThousandTofive/.project new file mode 100644 index 0000000..a8c688c --- /dev/null +++ b/Java/ThousandTofive/.project @@ -0,0 +1,17 @@ + + + ThousandTofive + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/ThousandTofive/.settings/org.eclipse.jdt.core.prefs b/Java/ThousandTofive/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..47e55db --- /dev/null +++ b/Java/ThousandTofive/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Nov 25 15:47:54 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 diff --git a/Java/ThousandTofive/bin/ThousandToFive.class b/Java/ThousandTofive/bin/ThousandToFive.class new file mode 100644 index 0000000..4c7c5f2 Binary files /dev/null and b/Java/ThousandTofive/bin/ThousandToFive.class differ diff --git a/Java/ThousandTofive/src/ThousandToFive.java b/Java/ThousandTofive/src/ThousandToFive.java new file mode 100644 index 0000000..db024f4 --- /dev/null +++ b/Java/ThousandTofive/src/ThousandToFive.java @@ -0,0 +1,16 @@ +/* + * This class will display all numbers from 1000 to 5 inclusive displays in + * decreasing order + */ + +class ThousandToFive{ + + /* + * Main method. everything starts here + */ + public static void main(String[] args){ + for (int i = 1000; i > 4; i--){ + System.out.println(i); + } //end for loop + } //end main method +} //end class \ No newline at end of file diff --git a/Java/Vehicle Exception Project/.classpath b/Java/Vehicle Exception Project/.classpath new file mode 100644 index 0000000..18d70f0 --- /dev/null +++ b/Java/Vehicle Exception Project/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Java/Vehicle Exception Project/.project b/Java/Vehicle Exception Project/.project new file mode 100644 index 0000000..bc770d6 --- /dev/null +++ b/Java/Vehicle Exception Project/.project @@ -0,0 +1,17 @@ + + + Vehicle Exception Project + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Java/Vehicle Exception Project/.settings/org.eclipse.jdt.core.prefs b/Java/Vehicle Exception Project/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..41b0704 --- /dev/null +++ b/Java/Vehicle Exception Project/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Fri Dec 10 14:42:44 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 diff --git a/Java/Vehicle Exception Project/Vehicles b/Java/Vehicle Exception Project/Vehicles new file mode 100644 index 0000000..aeae6ee --- /dev/null +++ b/Java/Vehicle Exception Project/Vehicles @@ -0,0 +1,19 @@ +#Comments begin with # +#the following format will be used +#model make year horsepower capacity +truck jeep 140 240 2400 +bus dodge 2007 500 40 +truck dodge 910 240 2400 +bus poop 2007 500 50 +truck jeep 10 240 2400 +bus poop 2007 500 50 +truck jeep 190 240 2400 +bus vw 2007 500 50 +truck jeep 10 240 2400 +bus ford 2007 500 50 +truck jeep 190 240 200 +bus poop 2007 500 50 +truck jeep 10 240 400 +bus poop 2007 500 50 +truck jeep 100 240 240 +bus vw 2007 500 50 \ No newline at end of file diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/AddVehicleDialog.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/AddVehicleDialog.class new file mode 100644 index 0000000..ab8ec8c Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/AddVehicleDialog.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Bus.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Bus.class new file mode 100644 index 0000000..eb35fac Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Bus.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidHorsepowerException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidHorsepowerException.class new file mode 100644 index 0000000..22a9bb6 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidHorsepowerException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidMakeException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidMakeException.class new file mode 100644 index 0000000..b5f535f Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidMakeException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidTowingCapacityException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidTowingCapacityException.class new file mode 100644 index 0000000..86968b2 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidTowingCapacityException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidYearException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidYearException.class new file mode 100644 index 0000000..8c20f6d Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/InvalidYearException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/MainWindow.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/MainWindow.class new file mode 100644 index 0000000..101ced8 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/MainWindow.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/NegativeBusPassengerException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/NegativeBusPassengerException.class new file mode 100644 index 0000000..e048138 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/NegativeBusPassengerException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/OverloadedBusException.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/OverloadedBusException.class new file mode 100644 index 0000000..eea8384 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/OverloadedBusException.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/RemoveVehicleDialog.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/RemoveVehicleDialog.class new file mode 100644 index 0000000..3302888 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/RemoveVehicleDialog.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog$ButtonListener.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog$ButtonListener.class new file mode 100644 index 0000000..9ae9666 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog$ButtonListener.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog.class new file mode 100644 index 0000000..c47d71d Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllDialog.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllMakeDialog.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllMakeDialog.class new file mode 100644 index 0000000..5508fca Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/ShowAllMakeDialog.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test$1.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test$1.class new file mode 100644 index 0000000..8522942 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test$1.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test.class new file mode 100644 index 0000000..16e85d7 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Test.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Truck.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Truck.class new file mode 100644 index 0000000..4d806f8 Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Truck.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Vehicle.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Vehicle.class new file mode 100644 index 0000000..89778ba Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/Vehicle.class differ diff --git a/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/VehicleDB.class b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/VehicleDB.class new file mode 100644 index 0000000..09dbe5c Binary files /dev/null and b/Java/Vehicle Exception Project/bin/com/VehicleExcetionProject/VehicleDB.class differ diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/AddVehicleDialog.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/AddVehicleDialog.java new file mode 100644 index 0000000..bd9d816 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/AddVehicleDialog.java @@ -0,0 +1,102 @@ +package com.VehicleExcetionProject; + +import java.awt.Dimension; +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.JTextArea; + +/** + * this class will allow the user to enter a new vehicle into the database + */ +public class AddVehicleDialog extends JFrame implements ActionListener{ + + private static final long serialVersionUID = 3165335189780349167L; + private JButton ok; + private JTextArea model; + private JTextArea make; + private JTextArea year; + private JTextArea hp; + private JTextArea cap; + + /** + * Creates a new AddVehicleDialog + */ + public AddVehicleDialog() { + super(); + setTitle("Add Vehicle"); + setMinimumSize(new Dimension(590, 20)); + + //create a JPanel to hold the text area and button + JPanel panel = new JPanel(); + ok = new JButton("Ok"); + ok.addActionListener(this); + model = new JTextArea(); + model.setEditable(true); + model.setColumns(10); + model.setRows(1); + + make = new JTextArea(); + make.setEditable(true); + make.setColumns(10); + make.setRows(1); + + year = new JTextArea(); + year.setEditable(true); + year.setColumns(10); + year.setRows(1); + + hp = new JTextArea(); + hp.setEditable(true); + hp.setColumns(10); + hp.setRows(1); + + cap = new JTextArea(); + cap.setEditable(true); + cap.setColumns(10); + cap.setRows(1); + + panel.add(new JLabel("Model: ")); + panel.add(model); + panel.add(new JLabel("Make: ")); + panel.add(make); + panel.add(new JLabel("Year: ")); + panel.add(year); + panel.add(new JLabel("Horse Power: ")); + panel.add(hp); + panel.add(new JLabel("Capacity: ")); + panel.add(cap); + + 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) { + try{ + if(model.getText().equals("truck")){ + MainWindow.db.addVehicle(new Truck(make.getText(), Integer.parseInt(year.getText()), Double.parseDouble(hp.getText()), Double.parseDouble(cap.getText()))); + } + if(model.getText().equals("bus")){ + MainWindow.db.addVehicle(new Bus(make.getText(), Integer.parseInt(year.getText()), Double.parseDouble(hp.getText()), Integer.parseInt(cap.getText())));; + } + setVisible(false); + } catch(Exception ex){ + ex.printStackTrace(); + } + } + } +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Bus.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Bus.java new file mode 100644 index 0000000..e1c77b7 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Bus.java @@ -0,0 +1,109 @@ +/** + * Bus class with super class + * + * @author Jonathan Warning + * @version 11.01.10 + */ +package com.VehicleExcetionProject; + + +public class Bus extends Vehicle { + public final int MAXPASSENGERS = 50; + private int numOfPassengers; + + /* + * constructs a Bus object + */ + public Bus() { + super(); + numOfPassengers = 0; + } + + /* + * constructs a Bus object + * + * @param String aMake the make of the vehicle + * + * @param int aYear the year of the vehicle + * + * @param double aHorsepower the horsepower of the vehicle + * + * @param int aNumOfPassengers the number of passsengers + */ + public Bus(String aMake, int aYear, double aHorsepower, int aNumOfPassengers) { + super(aMake, aYear, aHorsepower); + if (aNumOfPassengers > MAXPASSENGERS) + throw new OverloadedBusException( + "Number of passengers cannot exceed " + MAXPASSENGERS); + else if (aNumOfPassengers < 0) + throw new NegativeBusPassengerException( + "Number of passegers cannot be less than 0."); + else + numOfPassengers = aNumOfPassengers; + } + + /* + * sets the number of passengers on the Bus + * + * @param int numOfPassengers the number of passengers on the Bus + */ + public void setPassengers(int aNumOfPassengers) { + if (aNumOfPassengers > MAXPASSENGERS) + throw new OverloadedBusException( + "Number of passengers cannot exceed " + MAXPASSENGERS); + else if (aNumOfPassengers < 0) + throw new NegativeBusPassengerException( + "Number of passegers cannot be less than 0."); + else + numOfPassengers = aNumOfPassengers; + } + + /* + * gets the number of passengers on the Bus + * + * @return int numOfPassengers the number of passengers on the Bus + */ + public int getPassengers() { + return numOfPassengers; + } + + /* + * calculates miles per gallon + * + * @return double milesPerGal the miles per gallon of the Bus + */ + public double calculateMPG() { + return milesPerGal = 10000 / numOfPassengers / horsepower; + } + + /* + * String with all of the parameters of the Bus + * + * @return int year year of the Bus + * + * @return String make make of the Bus + * + * @return double horsepower horsepower of the Bus + * + * @return int numOfPassengers number of passengers in Bus + */ + @Override + public String toString() { + return "The " + super.year + ", " + super.horsepower + " horsepower " + + super.make + " is carrying " + numOfPassengers + " people."; + } + + /* + * Compares two Busses number of passengers + * + * @return boolean are the busses number of passengers equal + */ + @Override + public boolean equals(Object otherObj) { + if (otherObj instanceof Bus) { + Bus otherBus = (Bus) otherObj; + return (numOfPassengers == otherBus.numOfPassengers); + } else + return false; + } +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidHorsepowerException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidHorsepowerException.java new file mode 100644 index 0000000..abb6d0e --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidHorsepowerException.java @@ -0,0 +1,15 @@ +package com.VehicleExcetionProject; + +public class InvalidHorsepowerException extends RuntimeException { + + private static final long serialVersionUID = -3775197702871511450L; + + public InvalidHorsepowerException() { + + } + + public InvalidHorsepowerException(String message) { + super(message); + } + +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidMakeException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidMakeException.java new file mode 100644 index 0000000..51b6512 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidMakeException.java @@ -0,0 +1,15 @@ +package com.VehicleExcetionProject; + +public class InvalidMakeException extends RuntimeException { + + private static final long serialVersionUID = -7536710583729590772L; + + public InvalidMakeException() { + + } + + public InvalidMakeException(String message) { + super(message); + } + +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidTowingCapacityException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidTowingCapacityException.java new file mode 100644 index 0000000..0c82e0c --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidTowingCapacityException.java @@ -0,0 +1,14 @@ +package com.VehicleExcetionProject; + +public class InvalidTowingCapacityException extends RuntimeException { + + private static final long serialVersionUID = -3525837906090455018L; + + public InvalidTowingCapacityException() { + + } + + public InvalidTowingCapacityException(String message) { + super(message); + } +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidYearException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidYearException.java new file mode 100644 index 0000000..3e5e45d --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/InvalidYearException.java @@ -0,0 +1,14 @@ +package com.VehicleExcetionProject; + +public class InvalidYearException extends RuntimeException { + + private static final long serialVersionUID = 7185150702544438062L; + + public InvalidYearException() { + + } + + public InvalidYearException(String message) { + super(message); + } +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/MainWindow.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/MainWindow.java new file mode 100644 index 0000000..0836746 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/MainWindow.java @@ -0,0 +1,96 @@ +package com.VehicleExcetionProject; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JPanel; + +/** + * this is the main window and class of this application + */ +public class MainWindow extends JFrame implements ActionListener{ + + private JButton search; + private JButton addVehicle; + private JButton addFromFile; + private JButton removeVehicle; + private JButton showAllVehicles; + private JFileChooser fc; + public static VehicleDB db; + + /** + * Generated Serial Version ID + */ + private static final long serialVersionUID = 1841715561053331517L; + + public MainWindow() { + setTitle("Vehicle Database"); + JPanel panel = new JPanel(); + search = new JButton("Search"); + addVehicle = new JButton("Add Vehicle"); + addFromFile = new JButton("Add From File"); + removeVehicle = new JButton("Remove Vehicle"); + showAllVehicles = new JButton("Show All Vehicles"); + + search.addActionListener(this); + addVehicle.addActionListener(this); + addFromFile.addActionListener(this); + removeVehicle.addActionListener(this); + showAllVehicles.addActionListener(this); + + panel.add(search); + panel.add(addVehicle); + panel.add(addFromFile); + panel.add(removeVehicle); + panel.add(showAllVehicles); + + add(panel); + setVisible(true); + this.setMinimumSize(new Dimension(680,70)); + + fc = new JFileChooser(); + + fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + + db = new VehicleDB(); + } + + /** + * 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 ShowAllMakeDialog(); + } + if (e.getSource() == addVehicle) { + new AddVehicleDialog(); + } + if (e.getSource() == addFromFile) { + if(fc.showOpenDialog(MainWindow.this) == JFileChooser.APPROVE_OPTION){ + db.processFile(fc.getSelectedFile()); + } + } + if (e.getSource() == removeVehicle) { + new RemoveVehicleDialog(); + } + if (e.getSource() == showAllVehicles) { + new ShowAllDialog(db.toString()); + } + } + +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/NegativeBusPassengerException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/NegativeBusPassengerException.java new file mode 100644 index 0000000..d29cad9 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/NegativeBusPassengerException.java @@ -0,0 +1,14 @@ +package com.VehicleExcetionProject; + +public class NegativeBusPassengerException extends RuntimeException { + + private static final long serialVersionUID = 2864975327138368535L; + + public NegativeBusPassengerException() { + + } + + public NegativeBusPassengerException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/OverloadedBusException.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/OverloadedBusException.java new file mode 100644 index 0000000..73771dd --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/OverloadedBusException.java @@ -0,0 +1,14 @@ +package com.VehicleExcetionProject; + +public class OverloadedBusException extends RuntimeException { + + private static final long serialVersionUID = -1979540068583138964L; + + public OverloadedBusException() { + + } + + public OverloadedBusException(String message) { + super(message); + } +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/RemoveVehicleDialog.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/RemoveVehicleDialog.java new file mode 100644 index 0000000..fd7dbd1 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/RemoveVehicleDialog.java @@ -0,0 +1,63 @@ +package com.VehicleExcetionProject; + +import java.awt.Dimension; +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.JTextArea; + +/** + * This class will be the delete vehicle dialog + */ +public class RemoveVehicleDialog extends JFrame implements ActionListener { + + private static final long serialVersionUID = -36245710370532319L; + private JButton ok; + private JTextArea editText; + + /** + * Creates a new RemoveVehicleDialog + */ + public RemoveVehicleDialog(){ + super(); + setTitle("Delete Vehicles"); + setMinimumSize(new Dimension(590, 20)); + + //create a JPanel to hold the text area and button + JPanel panel = new JPanel(); + ok = new JButton("Ok"); + editText = new JTextArea(); + JLabel label = new JLabel("Enter Vehicle Make To Remove"); + ok.addActionListener(this); + editText.setEditable(true); + editText.setColumns(25); + editText.setRows(1); + + panel.add(label); + panel.add(editText); + 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.deleteVehicle(editText.getText()); + setVisible(false); + } + } + +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllDialog.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllDialog.java new file mode 100644 index 0000000..c9409d5 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllDialog.java @@ -0,0 +1,65 @@ +package com.VehicleExcetionProject; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +/** + * This panel will be used to display all Vehicles in the VechicleDB + */ +public class ShowAllDialog extends JFrame { + + private static final long serialVersionUID = -8416144493079733535L; + private JButton ok; + private JTextArea results; + + /** + * Creates a new ShowAllDialog + */ + public ShowAllDialog(String list){ + super(); + setTitle("Show All Vehicles"); + setMinimumSize(new Dimension(590, 460)); + + //create a JPanel to hold the text area and button + JPanel panel = new JPanel(); + ok = new JButton("Ok"); + results = new JTextArea(); + ButtonListener listener = new ButtonListener(); + ok.addActionListener(listener); + results.setEditable(false); + results.setText(list); + results.setColumns(50); + results.setRows(25); + JScrollPane scrollPane = new JScrollPane(results); + setPreferredSize(new Dimension(450, 110)); + add(scrollPane, BorderLayout.CENTER); + panel.add(scrollPane); + panel.add(ok); + + //add the JPanel to the frame, and display + getContentPane().add(panel); + pack(); + setVisible(true); + } + + /** + * Listener class for this JPanel + */ + private class ButtonListener implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + ShowAllDialog.this.setVisible(false); + } + + } + +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllMakeDialog.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllMakeDialog.java new file mode 100644 index 0000000..d57327d --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/ShowAllMakeDialog.java @@ -0,0 +1,66 @@ +package com.VehicleExcetionProject; + +import java.awt.Dimension; +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.JTextArea; + +/** + * This class will be the dialog that will ask the user for a specific make to show + */ +public class ShowAllMakeDialog extends JFrame implements ActionListener { + + private static final long serialVersionUID = 1750326106927701404L; + private JButton ok; + private JTextArea editText; + + /** + * Creates a new ShowAllMakeDialog + */ + public ShowAllMakeDialog() { + super(); + setTitle("Search"); + setMinimumSize(new Dimension(590, 20)); + + //create a JPanel to hold the text area and button + JPanel panel = new JPanel(); + ok = new JButton("Ok"); + editText = new JTextArea(); + JLabel label = new JLabel("Enter Vehicle Make To Show"); + ok.addActionListener(this); + editText.setEditable(true); + editText.setColumns(25); + editText.setRows(1); + + panel.add(label); + panel.add(editText); + 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(Vehicle item : MainWindow.db.findVehicle(editText.getText())) + sb.append(item.toString()+"\n"); + new ShowAllDialog(sb.toString()); + setVisible(false); + } + } + +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Test.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Test.java new file mode 100644 index 0000000..8473cba --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Test.java @@ -0,0 +1,43 @@ +package com.VehicleExcetionProject; + +import java.awt.EventQueue; + +import javax.swing.JFrame; + +public class Test { + + private JFrame frame; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Test window = new Test(); + window.frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the application. + */ + public Test() { + initialize(); + } + + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frame = new JFrame(); + frame.setBounds(100, 100, 450, 300); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Truck.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Truck.java new file mode 100644 index 0000000..6a3183b --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Truck.java @@ -0,0 +1,106 @@ +/** + * Truck class with superclass + * + * @author Jonathan Warning + * @version 11.01.10 + */ + +package com.VehicleExcetionProject; + + +public class Truck extends Vehicle { + public final double MINCAPACITY = 0.5; + + private double towingCapacity; + + /* + * constructs a Truck object + */ + public Truck() { + super(); + towingCapacity = 0; + } + + /* + * constructs a Truck object + * + * @param String aMake the make of the vehicle + * + * @param int aYear the year of the vehicle + * + * @param double aHorsepower the horsepower of the vehicle + * + * @param double aTowingCapacity the towing capacity of the Truck + */ + public Truck(String aMake, int aYear, double aHorsepower, + double aTowingCapacity) { + super(aMake, aYear, aHorsepower); + if (aTowingCapacity < MINCAPACITY) + throw new InvalidTowingCapacityException( + "Towing capacity cannot be less than " + MINCAPACITY); + else + towingCapacity = aTowingCapacity; + } + + /* + * sets the towing capacity of the truck + * + * @param double aTowingCapacity the towing capacity of the truck + */ + public void setTowingCapacity(double aTowingCapacity) { + if (aTowingCapacity < MINCAPACITY) + throw new InvalidTowingCapacityException("Towing capacity cannot be less than " + MINCAPACITY); + else + towingCapacity = aTowingCapacity; + } + + /* + * gets the towing capacity of the truck + * + * @return double aTowingCapacity the towing capacity of the Truck + */ + public double getTowingCapacity() { + return towingCapacity; + } + + /* + * calculates miles per gallon + * + * @return double milesPerGal the miles per gallon of the Truck + */ + public double calculateMPG() { + return milesPerGal = 5000 / towingCapacity / horsepower; + } + + /* + * String with all of the parameters of the Truck + * + * @return int year year of the Truck + * + * @return String make make of the Truck + * + * @return double horsepower horsepower of the Truck + * + * @return double towingCapacity the towing capactiy of the truck + */ + @Override + public String toString() { + return "The towing capacity of the " + super.year + ", " + + super.horsepower + " horsepower " + super.make + " is " + + towingCapacity + " tons."; + } + + /* + * Compares two trucks towing capacities + * + * @return boolean are the trucks towing capacities equal + */ + @Override + public boolean equals(Object otherObj) { + if (otherObj instanceof Truck) { + Truck otherTruck = (Truck) otherObj; + return ((towingCapacity == otherTruck.towingCapacity)); + } else + return false; + } +} \ No newline at end of file diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Vehicle.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Vehicle.java new file mode 100644 index 0000000..142ada3 --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/Vehicle.java @@ -0,0 +1,176 @@ +/** + * Vehicle class with subclasses + * + * @author Jonathan Warning + * @version 10.20.10 + */ + +package com.VehicleExcetionProject; + + +public abstract class Vehicle implements Cloneable, Comparable { + protected String make; + protected int year; + protected double horsepower; + protected double milesPerGal; + + /* + * constructs a vehicle object + */ + public Vehicle() { + make = ""; + year = 0; + horsepower = 0; + + if (make.length() == 0) + throw new InvalidMakeException("Vehicle must parameters."); + if (year <= 0) + throw new InvalidYearException("Vehicle must parameters."); + if (horsepower <= 0) + throw new InvalidHorsepowerException("Vehicle must parameters."); + } + + /* + * constructs a vehicle object + * + * @param String aMake the make of the vehicle + * + * @param int aYear the year of the vehicle + * + * @param double aHorsepower the horsepower of the vehicle + */ + public Vehicle(String aMake, int aYear, double aHorsepower) { + if (aMake.length() == 0) + throw new InvalidMakeException("Vehicle must have a make."); + else + make = aMake; + + if (aYear <= 0) + throw new InvalidYearException("Vehicle must have been made A.D."); + else + year = aYear; + + if (aHorsepower <= 0) + throw new InvalidHorsepowerException( + "Vehicle must have positive horsepower."); + else + horsepower = aHorsepower; + } + + /* + * Sets the make of the vehicle + * + * @param String aMake the make of the vehicle + */ + public void setMake(String aMake) { + if (aMake.length() == 0)// (aMake.equalsIgnoreCase("")) + throw new InvalidMakeException("Vehicle must have a make."); + else + make = aMake; + } + + /* + * Sets the year of the vehicle + * + * @param int aYear the year of the vehicle + */ + public void setYear(int aYear) { + if (aYear <= 0) + throw new InvalidYearException("Vehicle must have been made A.D."); + else + year = aYear; + } + + /* + * Sets the horsepowers of the vehicle + * + * @param double aHorsepower the horsepower of the vehicle + */ + public void setHorsepower(double aHorsepower) { + if (aHorsepower <= 0) + throw new InvalidHorsepowerException( + "Vehicle must have positive horsepower."); + else + horsepower = aHorsepower; + } + + /* + * gets the make of the vehicle + * + * @return String make the make of the vehicle + */ + public String getMake() { + return make; + } + + /* + * gets the year of the vehicle + * + * @return int year the year of the vehicle + */ + public int getYear() { + return year; + } + + /* + * gets the horsepower of the vehicle + * + * @return double horsepower the horsepower of the vehicle + */ + public double getHorsepower() { + return horsepower; + } + + /* + * abstract method to calculate MPG classes that implement Vehicle must the + * calculateMPG method + */ + public abstract double calculateMPG(); + + /* + * String with all of the parameters of the class + * + * @return int year year of the Vehicle + * + * @return String make make of the Vehicle + * + * @return double horsepower horsepower of the Vehicle + */ + public String toString() { + return "The " + year + " " + make + " has " + horsepower + " hp."; + } + + /* + * Compares two Vehicles milesPerGal + * + * @return boolean are the objects milesPerGal equal + */ + public boolean equals(Object otherObj) { + Vehicle otherVehicle = (Vehicle) otherObj; + return (this.milesPerGal == otherVehicle.milesPerGal); + } + + /* + * makes a deep copy of a Vehicle object + * + * @return Object a deep copy of the object + */ + @Override + public Object clone() throws CloneNotSupportedException { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + return null; + } + } + + /** + * compares vehicle by make + * (non-Javadoc) + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(Vehicle vehicle){ + return this.make.compareTo( vehicle.make ); + } +} diff --git a/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/VehicleDB.java b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/VehicleDB.java new file mode 100644 index 0000000..3de112a --- /dev/null +++ b/Java/Vehicle Exception Project/src/com/VehicleExcetionProject/VehicleDB.java @@ -0,0 +1,109 @@ +package com.VehicleExcetionProject; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +/** + * This class will be a vehicle database + */ +public class VehicleDB{ + + private ArrayList array; + + /** + * Creates a new VehicleDB + */ + public VehicleDB(){ + array = new ArrayList(0); + } + + /** + * returns a human readable string + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString(){ + StringBuffer sb = new StringBuffer(); + for(Vehicle item : array) + sb.append(item.toString() +"\n"); + return sb.toString(); + } + + /** + * added the vehicle to the database + * @param aVehicle + */ + public void addVehicle(Vehicle aVehicle){ + array.add(aVehicle); + Collections.sort(array); + } + + /** + * finds the all occurrences of a vehicle with the make + * @param make + * @return ta list containing all the vehicles with the provided make + */ + public ArrayList findVehicle(String make){ + ArrayList temp = new ArrayList(0); + for(Vehicle item : array) + if(item.getMake().equals(make)) + temp.add(item); + return temp; + } + + /** + * removes the all occurrences of a vehicle with the make + * @param make + */ + public void deleteVehicle(String make){ + Object[] temp = array.toArray(); + for(int index = 0; index < temp.length; index++) + if(((Vehicle)temp[index]).getMake().equals(make)){ + temp[index] = null; + } + + array.removeAll(array); + + for(Object item : temp) + if(item != null) + array.add((Vehicle)item); + } + + /** + * process the file into the VehicleDB + * @param selectedFile + */ + public void processFile(File selectedFile) { + Scanner scan = null; + try { + scan = new Scanner(selectedFile); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } + + if(scan != null){ + String model; + while(scan.hasNextLine()){ + model = scan.next(); + if(model.toCharArray()[0] != '#'){ + try { + if(model.equals("truck")){ + addVehicle(new Truck(scan.next(), scan.nextInt(), scan.nextDouble(), scan.nextDouble())); + } + if(model.equals("bus")){ + addVehicle(new Bus(scan.next(), scan.nextInt(), scan.nextDouble(), scan.nextInt())); + } + } catch (Exception e) { +// e.printStackTrace(); + } + } + } + } + + } + +} \ No newline at end of file