-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreJava_Assessment1.java
More file actions
84 lines (68 loc) · 2.13 KB
/
CoreJava_Assessment1.java
File metadata and controls
84 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.hughes.handson;
class Account {
String accountId;
String accountName;
String address;
int depositAmount;
Account(String accountId, String accountName, String address) {
this.accountId = accountId;
this.depositAmount = 0;
this.accountName = accountName;
this.address = address;
}
public String getDetails() {
return "Account ID: " + accountId + "\n" + "Account Name: " + accountName + "\n" + "Address: " + address;
}
void showDetails() {
System.out.println("Your Account ID is: " + this.accountId);
System.out.println("Your Account Name is: " + this.accountName);
System.out.println("Your Address is: " + this.address);
}
void depositAmount(int amount) {
this.depositAmount += amount;
}
}
class Loan extends Account {
int loanId;
String loanType;
int loanAmount;
static int counter = 0;
Loan(String accountId, String accountName, String address) {
super(accountId, accountName, address);
}
void getLoan(String loanType, int loanAmount) {
counter++;
this.loanId = counter;
this.loanType = loanType;
this.loanAmount = loanAmount;
}
void showLoanDetails() {
if (this.loanAmount > 0) {
System.out.println("Your Loan ID is: " + this.loanId);
System.out.println("Your Loan Type is: " + this.loanType);
System.out.println("Your Loan Amount is: " + this.loanAmount);
}
}
void withdrawAmount(int amount) {
if (this.loanAmount >= amount) {
this.loanAmount -= amount;
} else {
System.out.println("Not Enough Balance");
}
}
}
public class CoreJava_Assessment1 {
public static void main(String[] args) {
Account[] accounts = new Account[10];
// Adding sample accounts
accounts[0] = new Account("1234567-ASDF", "John Doe", "123 Main St");
accounts[1] = new Loan("2345678-QWER", "Jane Smith", "456 Elm St");
((Loan) accounts[1]).getLoan("home", 100000); // Casting to Loan to access getLoan method
// Sample transactions
accounts[0].depositAmount(500); // Depositing 500 in account 0
((Loan) accounts[1]).withdrawAmount(20000); // Withdrawing 20000 from loan account 1
// Displaying account details
accounts[0].showDetails();
((Loan) accounts[1]).showLoanDetails();
}
}