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_Assignment04_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>Assignment4B_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,124 @@
package edu.kit.informatik;
/**
* The Class Account.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class Account implements Comparable<Account> {
/** The account number. */
private int accountNumber;
/** The bank code. */
private int bankCode;
/** The balance. */
private int balance;
/**
* Instantiates a new account (balance is initialized with 0).
*
* @param bankCode
* the bank code
* @param accountNumber
* the account number
*/
public Account(int bankCode, int accountNumber) {
if (bankCode < 0 || accountNumber < 0) {
throw new IllegalArgumentException();
}
this.bankCode = bankCode;
this.accountNumber = accountNumber;
balance = 0;
}
/**
* Tries to withdraw money from the account (Fails if this would make
* balance negative).
*
* @param amount
* the amount that should be withdrawn
* @return true, if successful
*/
public boolean withdraw(int amount) {
if (balance - amount < 0 || amount < 0) {
return false;
}
balance -= amount;
return true;
}
/**
* Increases the balance of the account by 'amount'.
*
* @param amount
* the amount
*/
public void deposit(int amount) {
if (amount < 0)
throw new IllegalArgumentException("amount must be positive");
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 && ((Account) obj).accountNumber == this.accountNumber)
return true;
return false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Account o) {
if (o.getAccountNumber() > this.getAccountNumber())
return -1;
else if (o.getAccountNumber() < this.getAccountNumber())
return 1;
return 0;
}
@Override
public String toString() {
return bankCode + "," + accountNumber + "," + balance;
}
}

View File

@@ -0,0 +1,135 @@
package edu.kit.informatik;
/**
* The Class Bank.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class Bank {
private MinimaList accounts;
private int bankCode;
/**
* Instantiates a new bank.
*
* @param bankCode
* the bank code
*/
public Bank(int bankCode) {
accounts = new MinimaList();
this.bankCode = bankCode;
}
/**
* Creates an account.
*
* @param accountNumber
* the account number
* @return the index of the account
*/
public int createAccount(int accountNumber) {
Account acc = new Account(bankCode, accountNumber);
if (accounts.contains(acc)) {
throw new IllegalArgumentException("Account already exists.");
} else {
int index = 0;
for (int i = length() - 1; i >= 0; i--) {
// As soon as acc is bigger than current element
if (acc.compareTo(accounts.get(i)) > 0) {
index = i + 1;
break;
}
}
accounts.add(acc, index);
return index;
}
}
/**
* Removes the account at the index.
*
* @param accountNumber
* the account number
* @return true, if successful
*/
public boolean removeAccount(int accountNumber) {
int index = accounts.getIndex(new Account(bankCode, accountNumber));
if (index < 0)
return false;
return accounts.remove(index);
}
/**
* Checks if account exists in this bank.
*
* @param accountNumber
* the account number
* @return true, if the account exists
*/
public boolean containsAccount(int accountNumber) {
if (accounts.contains(new Account(this.bankCode, accountNumber))) {
return true;
}
return false;
}
/**
* Transfers money from one account to another.
*
* @param fromAccountNumber
* the account number of the account money is withdrawn from
* @param toAccountNumber
* the account number of the account money is deposited to
* @param amount
* the amount
* @return true, if successful
*/
public boolean transfer(int fromAccountNumber, int toAccountNumber, int amount) {
int fromIndex = accounts.getIndex(new Account(bankCode, fromAccountNumber));
int toIndex = accounts.getIndex(new Account(bankCode, toAccountNumber));
if (fromIndex < 0 || toIndex < 0)
return false;
if (accounts.get(fromIndex).withdraw(amount)) {
accounts.get(toIndex).deposit(amount);
return true;
}
return false;
}
/**
* Length.
*
* @return the int
*/
public int length() {
return accounts.size();
}
/**
* Gets the account at the index.
*
* @param index
* the index
* @return the account
*/
public Account getAccount(int index) {
return accounts.get(index);
}
@Override
public String toString() {
return bankCode + "\n" + accounts;
}
/**
* Gets the bank code.
*
* @return the bank code
*/
public int getBankCode() {
return bankCode;
}
}

View File

@@ -0,0 +1,55 @@
package edu.kit.informatik;
/**
* The Class Container.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class Container {
/** The account. */
private Account account;
/** The next element in the list. */
private Container next;
/**
* Instantiates a new container.
*
* @param account
* the account
*/
public Container(Account account) {
this.account = account;
this.next = null;
}
/**
* Sets the next element.
*
* @param next
* the new next element
*/
public void setNext(Container next) {
this.next = next;
}
/**
* Gets the next element.
*
* @return the next element
*/
public Container getNext() {
return next;
}
/**
* Gets the account.
*
* @return the account
*/
public Account getAccount() {
return account;
}
}

View File

@@ -0,0 +1,199 @@
package edu.kit.informatik;
/**
* The Class MinimaList.
*
* @author Hannes Kuchelmeister
* @version 1.0
*/
public class MinimaList {
/** The first container that stores the first element of the list. */
private Container firstContainer;
/** The last container that stores the last element of the list. */
private Container lastContainer;
/** The number of elements of the list. */
private int size;
/**
* Instantiates a new minima list.
*/
public MinimaList() {
size = 0;
firstContainer = null;
lastContainer = null;
}
/**
* Adds an element at the end of the list.
*
* @param account
* the account
*/
public void add(Account account) {
if (firstContainer == null) {
this.firstContainer = new Container(account);
this.lastContainer = this.firstContainer;
} else {
Container tmp = new Container(account);
this.lastContainer.setNext(tmp);
this.lastContainer = tmp;
}
this.size++;
}
/**
* Gets the index of an element.
*
* @param account
* the account
* @return the index
*/
public int getIndex(Account account) {
int pos = -1;
int i = 0;
Container pointer = firstContainer;
while (pointer != null) {
if (pointer.getAccount().equals(account)) {
return i;
}
pointer = pointer.getNext();
i++;
}
return pos;
}
/**
* Adds an element to the list at the given index
*
* @param account
* the account
* @param index
* the index
*/
public void add(Account account, int index) {
if (index >= size || index < 0) {
this.add(account);
} else if (index == 0) {
Container tmpContainer = new Container(account);
tmpContainer.setNext(firstContainer);
firstContainer = tmpContainer;
this.size++;
} else {
Container pointer = getContainer(index - 1);
Container tmpContainer = new Container(account);
tmpContainer.setNext(pointer.getNext());
pointer.setNext(tmpContainer);
this.size++;
}
}
/**
* Removes the element at the index from the list.
*
* @param index
* the index
* @return true, if successful
*/
public boolean remove(int index) {
if (index >= size || index < 0) {
return false;
} else if (index == 0) {
firstContainer = firstContainer.getNext();
this.size--;
return true;
} else if (index == size - 1) {
lastContainer = getContainer(index - 1);
lastContainer.setNext(null);
this.size--;
return true;
} else {
this.size--;
return true;
}
}
/**
* Gets the first element of the list.
*
* @return the first
*/
public Account getFirst() {
return firstContainer.getAccount();
}
/**
* Gets the last element of the list.
*
* @return the last
*/
public Account getLast() {
return lastContainer.getAccount();
}
private Container getContainer(int index) {
if (index < 0 || index >= size) {
return null;
}
Container pointer = firstContainer;
int i = 0;
while (i < index) {
pointer = pointer.getNext();
i++;
}
return pointer;
}
/**
* Gets the account at the index.
*
* @param index
* the index
* @return the account
*/
public Account get(int index) {
if (index < 0 || index >= size) {
return null;
}
return this.getContainer(index).getAccount();
}
/**
* Checks if element is part of the list.
*
* @param account
* the account
* @return true, if element is part of list
*/
public boolean contains(Account account) {
Container pointer = firstContainer;
while (pointer != null) {
if (pointer.getAccount().equals(account)) {
return true;
}
pointer = pointer.getNext();
}
return false;
}
/**
* @return the size of the list
*/
public int size() {
return size;
}
@Override
public String toString() {
String ret = "";
Container pointer = firstContainer;
while (pointer != null) {
ret += "\t" + pointer.getAccount() + "\n";
pointer = pointer.getNext();
}
return "\t" + ret.trim();
}
}