Skip to content

Commit

Permalink
object orientation introduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnman67112 committed Mar 28, 2022
0 parents commit c05d5c5
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.metadata/
10 changes: 10 additions & 0 deletions bytebank/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions bytebank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions bytebank/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>bytebank</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>
14 changes: 14 additions & 0 deletions bytebank/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
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.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
8 changes: 8 additions & 0 deletions bytebank/src/bytebank/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package bytebank;

public class Account {
double balance;
int agency = 42;
int number;
String owner;
}
33 changes: 33 additions & 0 deletions bytebank/src/bytebank/CreateAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package bytebank;

public class CreateAccount {
public static void main(String[] args) {
Account firstAccount = new Account();
firstAccount.balance = 200;
firstAccount.balance += 100;

Account secondAccount = new Account();
secondAccount.balance = 50;

System.out.println("first account has: " + firstAccount.balance);
System.out.println("first account is in "
+ "agency " + firstAccount.agency);
System.out.println(firstAccount.number);
System.out.println(firstAccount.owner);

System.out.println("second account has: " + secondAccount.balance);
System.out.println("second account is in "
+ "agency " + secondAccount.agency);
System.out.println(secondAccount.number);
System.out.println(secondAccount.owner);

if (firstAccount == secondAccount) {
System.out.println("they are the same account");
} else {
System.out.println("they are different accounts");
}

System.out.println(firstAccount);
System.out.println(secondAccount);
}
}
23 changes: 23 additions & 0 deletions bytebank/src/bytebank/ReferencesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package bytebank;

public class ReferencesTest {
public static void main(String[] args) {
Account firstAccount = new Account();
firstAccount.balance = 300;
System.out.println("balance of first account: " + firstAccount.balance);

Account secondAccount = firstAccount;
System.out.println("balance of first account: " + secondAccount.balance);

secondAccount.balance += 100;
System.out.println("balance of first account: " + firstAccount.balance);
System.out.println("balance of first account: " + secondAccount.balance);

if(firstAccount == secondAccount) {
System.out.println("they are the same account");
}

System.out.println(firstAccount);
System.out.println(secondAccount);
}
}

0 comments on commit c05d5c5

Please sign in to comment.