Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

John Squier Submission #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ATM_Lab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions Reusing_Classes_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Rotate Array

## Objectives

1. To demonstrate your understanding of objects and functions
2. To demonstrate your understanding of controlling execution
3. To demonstrate your understanding of access control
4. To demonstrate your understanding of reusing classes


## Overview

Create a class that subclasses the built-in List class. Write a function that rotates a list by k elements. For example [1,2,3,4,5,6] rotated by two becomes [3,4,5,6,1,2]. Try solving this without creating a copy of the list. How many swap or move operations do you need?


## Unit Test

No Unit Test

## Instructions

1. In your main class, initialize your custom List with values
2. In your main class call the method that rotates your array
3. Print original and rotated List values to screen
25 changes: 25 additions & 0 deletions Reusing_Classes_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Rotate Array

## Humans and Superhumans

## Objectives

1. To demonstrate your understanding of objects and functions
2. To demonstrate your understanding of controlling execution
3. To demonstrate your understanding of access control
4. To demonstrate your understanding of reusing classes


## Overview

Create a 'Human' class that has fields for: name, age, gender, occupation, and address. Also create methods for retreiving and outputing this data to screen.Then create a SuperHuman class that subclasses the first with fields for good or bad, hero name, super ability. As before, create methods for retrieving field data and printing to screen.

## Unit Test

No Unit Test

## Instructions

1. In your main class initialize a few human and superhuman instances
2. Demonstrate calling methods inherited from Human on your SuperHuman instances
3. Print all output to screen
26 changes: 26 additions & 0 deletions Reusing_Classes_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Class Manager

## Product Inventory Project

## Objectives

1. To demonstrate your understanding of objects and functions
2. To demonstrate your understanding of controlling execution
3. To demonstrate your understanding of access control
4. To demonstrate your understanding of reusing classes


## Overview

Create an application which manages an inventory of products. Create a product class which has a price, id, and quantity on hand. Then create an inventory class which keeps track of various products and can sum up the inventory value.

## Unit Test

UML is required
Unit test in place before proceeding with code

## Instructions

1. In your main class initialize your manager and populate your inventory
2. Demonstrate calling methods on your manager
3. Print all output to screen
26 changes: 26 additions & 0 deletions Reusing_Classes_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Abstract Class

## Bank Account Manager

## Objectives

1. To demonstrate your understanding of objects and functions
2. To demonstrate your understanding of controlling execution
3. To demonstrate your understanding of access control
4. To demonstrate your understanding of reusing classes


## Overview

Create a class called “Account” which will be an abstract class for three other classes called “CheckingAccount”, “SavingsAccount” and “BusinessAccount”. Manage credits and debits from these accounts through an ATM style program.

## Unit Test

UML is required
Unit test in place before proceeding with code

## Instructions

1. In your main class initialize your ATM
2. Demonstrate calling methods on your ATM with creating, deleting and managing account data
3. Print all output to screen
Binary file added Reusing_Classes_Class_Manager.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>squier.john.reusingClasses</groupId>
<artifactId>reusingClassesLab</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>


<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>

</project>
57 changes: 57 additions & 0 deletions src/main/java/squier/john/reusingClasses/ATM/ATM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package squier.john.reusingClasses.ATM;

import java.util.ArrayList;

/**
* Created by johnsquier on 1/18/17.
*/
public class ATM {

private ArrayList<ATM.Account> accounts;

public ATM() {
accounts = new ArrayList<ATM.Account>();
}

public ATM(ArrayList<ATM.Account> accounts) {
this.accounts = accounts;
}

public ArrayList<ATM.Account> getAccounts() { return accounts; }

public String displayAccountNamesAndBalances() {
StringBuilder stringBuilder = new StringBuilder(500);

for ( ATM.Account a : accounts ) {
stringBuilder.append("Name: ");
stringBuilder.append(a.getAccountHoldersName());
stringBuilder.append(" Balance: ");
stringBuilder.append(a.getBalance() + "\n");
}

return stringBuilder.toString();
}

public void addAccountToAccounts(ATM.Account account) {
accounts.add(account);
return;
}

public void removeAccountWithNameAndBalance(String accountHoldersName, Double balance) {
ATM.Account toRemove = null;

for ( ATM.Account a : accounts ) {
if ( a.getAccountHoldersName().equalsIgnoreCase(accountHoldersName)
&& a.getBalance().equals(balance) ) {
toRemove = a;
break;
// can we have multiple accts with the same name and balance?
// probably...
}
}

if ( !toRemove.equals(null) ) {
accounts.remove(toRemove);
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/squier/john/reusingClasses/ATM/ATMMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package squier.john.reusingClasses.ATM;

import java.util.ArrayList;

/**
* Created by johnsquier on 1/18/17.
*/
public class ATMMain {
public static void main(String[] args) {

// Create some accounts
ATM.Account savings = new SavingsAccount(BankAccountType.SAVINGS, 100.0, "Alice", 1.0,
BankAccountStatus.OPEN, OverdraftProtection.ENABLED);

ATM.Account checking = new CheckingAccount(BankAccountType.CHECKING, 50.0, "Bob", 0.0,
BankAccountStatus.OPEN, OverdraftProtection.ENABLED);

ATM.Account investment = new InvestmentAccount(BankAccountType.INVESTMENT, 10000.0, "Eve", 10.0,
BankAccountStatus.OPEN, OverdraftProtection.ENABLED);

// Put em in an array list
ArrayList<ATM.Account> accounts = new ArrayList<>();
accounts.add(savings);
accounts.add(checking);
accounts.add(investment);

// Create the atm with the accounts
ATM atm = new ATM(accounts);

// Loop through and display everyone's balance and name
System.out.println(atm.displayAccountNamesAndBalances());

// Add a new account to the atm
ATM.Account newAccount = new InvestmentAccount(BankAccountType.INVESTMENT, 0.0, "Steve", 10.0,
BankAccountStatus.OPEN, OverdraftProtection.ENABLED);

atm.addAccountToAccounts(newAccount);

// Display the new accounts
System.out.println(atm.displayAccountNamesAndBalances());

// Delete an account
System.out.println("Removing steve");
atm.removeAccountWithNameAndBalance("Steve", 0.0);

// And print again
System.out.println(atm.displayAccountNamesAndBalances());

// Delete another account
System.out.println("Removing Bob");
atm.removeAccountWithNameAndBalance("Bob", 50.0);
System.out.println(atm.displayAccountNamesAndBalances());

// Change Alice's balance
System.out.println("Change Alice's balance");
atm.getAccounts().get(0).updateBalanceWithCreditOrDebit(-100.0);
System.out.println(atm.displayAccountNamesAndBalances());
}
}
Loading