diff --git a/oop/code/oop/pom.xml b/oop/code/oop/pom.xml new file mode 100644 index 0000000..e231f94 --- /dev/null +++ b/oop/code/oop/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + com.scaler.lld + oop + 1.0-SNAPSHOT + + oop + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/oop/code/oop/src/main/java/com/scaler/lld/App.java b/oop/code/oop/src/main/java/com/scaler/lld/App.java new file mode 100644 index 0000000..58c2e48 --- /dev/null +++ b/oop/code/oop/src/main/java/com/scaler/lld/App.java @@ -0,0 +1,27 @@ +package com.scaler.lld; + +import com.scaler.lld.basics.OopBankAccount; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + // Create accounts for Alice and Bob + OopBankAccount accountAlice = new OopBankAccount(1, 1000, "Alice"); + OopBankAccount accountBob = new OopBankAccount(2, 2000, "Bob"); + + System.out.println("\nAlice's balance: " + accountAlice.getBalance()); + System.out.println("Bob's balance: " + accountBob.getBalance()); + + System.out.println("\nTransferring $100 from Alice to Bob"); + // Transfer $100 from Alice to Bob + accountAlice.transfer(accountBob, 100); + + System.out.println("\nAlice's balance: " + accountAlice.getBalance()); + System.out.println("Bob's balance: " + accountBob.getBalance()); + } +} diff --git a/oop/code/oop/src/main/java/com/scaler/lld/basics/OopBankAccount.java b/oop/code/oop/src/main/java/com/scaler/lld/basics/OopBankAccount.java new file mode 100644 index 0000000..6bad19a --- /dev/null +++ b/oop/code/oop/src/main/java/com/scaler/lld/basics/OopBankAccount.java @@ -0,0 +1,56 @@ +package com.scaler.lld.basics; + +public class OopBankAccount { + private Integer number; + private String name; + private Integer balance; + + public OopBankAccount(Integer number, Integer balance, String name) { + this.number = number; + this.balance = balance; + this.name = name; + } + + // GETTERS AND SETTERS START + public Integer getNumber() { + return this.number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getBalance() { + return this.balance; + } + + public void setBalance(Integer balance) { + this.balance = balance; + } + + // GETTERS AND SETTERS END + + + public void deposit(Integer amount) { + this.balance += amount; + } + + public void withdraw(Integer amount) { + this.balance -= amount; + } + + public void transfer(OopBankAccount destination, Integer amount) { + this.withdraw(amount); + destination.deposit(amount); + } + +} + diff --git a/oop/code/oop/src/test/java/com/scaler/lld/AppTest.java b/oop/code/oop/src/test/java/com/scaler/lld/AppTest.java new file mode 100644 index 0000000..887cb04 --- /dev/null +++ b/oop/code/oop/src/test/java/com/scaler/lld/AppTest.java @@ -0,0 +1,20 @@ +package com.scaler.lld; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +}