added all past projects

This commit is contained in:
Hannes
2017-11-10 00:13:57 +01:00
parent 5f63f0c599
commit 8c94608805
1391 changed files with 109456 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Programmieren_Assignment03_WS_2015" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
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.8

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="jdk" jdkName="JavaSE-1.8" jdkType="JavaSDK" />
</component>
</module>

View File

@@ -0,0 +1,112 @@
package edu.kit.informatik;
/**
* The Class Account.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class Account {
/** The account number. */
private int accountNumber;
/** The bank code. */
private int bankCode;
/** The balance. */
private int balance;
/**
* Instantiates a new account.
*
* @param bnkCode
* the bank code
* @param accNumber
* the account number
*/
public Account(int bnkCode, int accNumber) {
this.bankCode = bnkCode;
this.accountNumber = accNumber;
this.balance = 0;
}
/**
* Withdraw money.
*
* @param amount
* the amount
* @return true, if successful
*/
public boolean withdraw(int amount) {
if ((this.balance - amount) < 0)
return false;
else {
this.balance -= amount;
return true;
}
}
/**
* Deposit money.
*
* @param amount
* the amount
*/
public void deposit(int amount) {
this.balance += amount;
}
/**
* Gets the account number.
*
* @return the account number
*/
public int getAccountNumber() {
return accountNumber;
}
/**
* Gets the bank code.
*
* @return the bank code
*/
public int getBankCode() {
return bankCode;
}
/**
* Gets the balance.
*
* @return the balance
*/
public int getBalance() {
return balance;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof Account) {
return (this.accountNumber == ((Account) obj).getAccountNumber());
} else
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String str = "\t" + "accountNumber: " + accountNumber + "\n";
str += "\t\t" + "bankCode" + bankCode + "\n";
str += "\t\t" + "balance: " + balance;
return str;
}
}

View File

@@ -0,0 +1,235 @@
package edu.kit.informatik;
/**
* The Class Account.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class Bank {
/** The bank code. */
private int bankCode;
/** The accounts. */
private Account[] accounts;
/**
* Instantiates a new bank.
*
* @param bnkCode
* the bankCode
*/
public Bank(Integer bnkCode) {
this.bankCode = bnkCode;
accounts = new Account[4];
}
/**
* Creates an account.
*
* @param accountNumber
* the account number
* @return position of the created account inside the accounts
*/
public int createAccount(int accountNumber) {
if (this.size() == this.length()) {
// If account is half way filled: double the amount of elements
// accounts can hold
Account[] tmpArr = accounts;
accounts = new Account[tmpArr.length * 2];
System.arraycopy(tmpArr, 0, accounts, 0, tmpArr.length);
}
// Return index of newly added element
int index = this.size();
accounts[index] = new Account(this.bankCode, accountNumber);
return index;
}
/**
* Removes the account.
*
* @param accountNumber
* the account number for the account that should be removed
* @return true, if successful
*/
public boolean removeAccount(int accountNumber) {
if (!this.containsAccount(accountNumber)) { // if account is not in that
// bank it cannot be removed
return false;
} else {
/*
* Loop through each account until account is found that should be
* removed. After that close the 'gap' -> change index of all
* accounts (after the removed one) by -1
*/
for (int i = 0; i < accounts.length; i++) {
if (accounts[i] == null) {
if (accounts[i + 1] == null) { // break if end of existing
// accounts is reached
break;
} else if (i + 1 < accounts.length && accounts[i + 1] != null) { // fill
// in
// the
// gap
accounts[i] = accounts[i + 1];
accounts[i + 1] = null;
}
} else if (accounts[i].getAccountNumber() == accountNumber) { // remove
// account
accounts[i] = accounts[i + 1];
accounts[i + 1] = null;
}
}
// If the number of accounts gets smaller than 1/4 of the arraysize
// it will be halfed in size
if (this.size() * 4 < this.length() && this.length() > 4) { // Make
// array
// smaller
// if
// necessary
Account[] tmpAcc = this.accounts;
int length = this.size();
this.accounts = new Account[this.length() / 2];
System.arraycopy(tmpAcc, 0, this.accounts, 0, length);
}
return true;
}
}
/**
* Contains account.
*
* @param accountNumber
* the account number
* @return true, if successful
*/
public boolean containsAccount(int accountNumber) {
for (int i = 0; i < accounts.length; i++) {
if (accounts[i].getAccountNumber() == accountNumber)
return true;
}
return false;
}
/**
* Internal bank transfer.
*
* @param fromAccountNumber
* the account number of the account money should be withdrawn
* from
* @param toAccountNumber
* the account number of the account the money should be
* transfered to
* @param amount
* the amount
* @return true, if successful
*/
public boolean internalBankTransfer(int fromAccountNumber, int toAccountNumber, int amount) {
if (getAccountID(fromAccountNumber) < 0 && getAccountID(toAccountNumber) < 0)
return false;
Account fromAcc = this.getAccount(this.getAccountID(fromAccountNumber));
Account toAcc = this.getAccount(this.getAccountID(toAccountNumber));
if (fromAcc.withdraw(amount))
toAcc.deposit(amount);
return false;
}
/**
* Length.
*
* @return the the length of the internal array used to store all accounts
*/
public int length() {
return accounts.length;
}
/**
* Number of accounts.
*
* @return the number of accounts inside the bank
*/
public int size() {
if (accounts[0] == null)
return 0;
for (int i = 1; i < accounts.length; i++) {
if (accounts[i] == null)
return (i);
}
return accounts.length; // This should never be called
}
/**
* Gets the bank code.
*
* @return the bank code
*/
public int getBankCode() {
return bankCode;
}
/**
* Gets an account.
*
* @param index
* the index of the account that should be returned
* @return the account
*/
public Account getAccount(int index) {
if (size() <= index || index < 0)
return null;
else {
return accounts[index];
}
}
/**
* Gets the account id.
*
* @param accountNumber
* the account number
* @return the account id
*/
private int getAccountID(int accountNumber) {
for (int i = 0; i < accounts.length; i++) {
if (accounts[i].getAccountNumber() == accountNumber)
return i;
}
return -1;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
String str = "BankCode: " + bankCode + "\n";
str += "size: " + size() + "\n";
str += "length: " + length() + "\n";
for (Account account : accounts) {
if (account != null)
str += "\t" + account + "\n\n";
}
return str.trim();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof Bank && ((Bank) obj).getBankCode() == this.bankCode)
return true;
return false;
}
}

View File

@@ -0,0 +1,15 @@
package edu.kit.informatik;
public final class Main {
public static void main(final String[] args) {
final Bank bank = new Bank(0);
for (int i = 0; i < 10; i++) {
bank.createAccount(i);
}
System.out.println(bank);
}
private Main() {
}
}