Tutorial 7

This commit is contained in:
Marcus Vinicius de Carvalho 2025-03-27 14:49:42 +08:00
parent 42c22c106b
commit d50223dc4d
10 changed files with 116 additions and 0 deletions

11
T7Q1-2/T7Q1-2.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

23
T7Q1-2/src/Bank.java Normal file
View File

@ -0,0 +1,23 @@
public class Bank {
private CheckingAccount account;
public Bank() {
account = new CheckingAccount();
}
public double cashCheck(Check check) {
double amount = check.getAmount();
double balance = account.getBalance();
if (balance < amount) {
account.addInsuficientFundFee();
account.noteReturnedCheck(check);
return -1;
}
int checkNumber = check.getCheckNumber();
account.addDebitTransaction(checkNumber, amount);
account.storePhotoOfCheck(check);
return amount;
}
private void returnCheck(Check check) {}
}

9
T7Q1-2/src/Check.java Normal file
View File

@ -0,0 +1,9 @@
public class Check {
public double getAmount() {
return 100.0; // any valid double
}
public int getCheckNumber() {
return 1234; // any valid int
}
}

View File

@ -0,0 +1,14 @@
public class CheckingAccount {
public double getBalance() {
return 100.0; // any valid double
}
public void addInsuficientFundFee() {}
public void noteReturnedCheck(Check check) {}
public void addDebitTransaction(int checknumber, double amount) {}
public void storePhotoOfCheck(Check check) {}
}

9
T7Q1-2/src/Main.java Normal file
View File

@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
Bank bank = new Bank();
Check check = new Check();
bank.cashCheck(check);
System.out.println("Compiled successfully!");
}
}

11
T7Q1/T7Q1.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
T7Q1/src/Bank.java Normal file
View File

@ -0,0 +1,7 @@
public class Bank {
public double cashCheck(Check check) {
return 0.0;
}
private void returnCheck(Check check) {}
}

9
T7Q1/src/Check.java Normal file
View File

@ -0,0 +1,9 @@
public class Check {
public double getAmount() {
return 100.0; // any valid double
}
public int getCheckNumber() {
return 1234; // any valid int
}
}

View File

@ -0,0 +1,14 @@
public class CheckingAccount {
public double getBalance() {
return 100.0; // any valid double
}
public void addInsuficientFundFee() {}
public void noteReturnedCheck(Check check) {}
public void addDebitTransaction(int checknumber, double amount) {}
public void storePhotoOfCheck(Check check) {}
}

9
T7Q1/src/Main.java Normal file
View File

@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
Bank bank = new Bank();
Check check = new Check();
bank.cashCheck(check);
System.out.println("Compiled successfully!");
}
}