Skip to content

Commit bd83088

Browse files
committed
updated
1 parent 3e57364 commit bd83088

29 files changed

+769
-17
lines changed

README.md

+122-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,129 @@
11
# Application Programming in Java
22

3-
Rustam Zokirov, 9.10.2020
3+
Rustam_Z🚀, 9.10.2020
44

5-
## References:
5+
## Java Core Concepts
66
- Java full tutorial:
77
- https://www.javatpoint.com/java-tutorial
8+
- https://www.tutorialspoint.com/Pass-by-reference-vs-Pass-by-Value-in-java
9+
- https://www.geeksforgeeks.org/g-fact-31-java-is-strictly-pass-by-value/
10+
811
- Java OOPs:
912
- https://www.javatpoint.com/java-oops-concepts
10-
- Java exceptions:
11-
- https://www.javatpoint.com/exception-handling-in-java
13+
- Object casting - https://youtu.be/Qpz2MA4KE9U
14+
15+
- Java Exceptions:
16+
- https://www.javatpoint.com/exception-handling-in-java
17+
18+
- Design Patterns, SOLID Principles- https://youtu.be/A1PWJB98qcw
19+
20+
## Java GUI
21+
22+
### GUI Basics
23+
- [Lecture Notes](lecture-notes/GUI_Basics.ppt)
24+
25+
- [Swing Notes](lecture-notes/Creating_User_Interfaces_Swing.ppt)
26+
27+
- Swing (interface) vs. AWT (event handling)
28+
29+
- ```java
30+
import javax.swing.*;
31+
32+
public class MyFrame {
33+
public static void main(String[] args) {
34+
JFrame frame = new JFrame("Test Frame");
35+
frame.setSize(400, 300);
36+
frame.setLocationRelativeTo(null);
37+
frame.setVisible(true);
38+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
39+
}
40+
}
41+
```
42+
43+
- ```java
44+
import javax.swing.*;
45+
46+
public class MyFrameWithComponents {
47+
public static void main(String[] args) {
48+
JFrame frame = new JFrame( "MyFrameWithComponen")
49+
50+
JButton jbtOK = new JButton("OK"); // Add a button into the frame
51+
frame.add(jbtOK);
52+
53+
frame.setSize(400, 300);
54+
frame.setDefau1tC10seOperation(JFrame.EXIT_ON_CLOSE);
55+
frame.setLocationRe1ativeTo(nu11); // Center the frame
56+
frame.setVisib1e(true);
57+
}
58+
}
59+
```
60+
- [JFrame with inheritence](programs/MyFrame1.java)
61+
62+
### Layout Manager
63+
- For arraning a position into containers
64+
65+
- [FlowLayout](programs/ShowFlowLayout.java)
66+
67+
- [GridLayout](programs/ShowGridLayout.java)
68+
69+
- [BorderLayout](programs/ShowBorderLayout.java)
70+
71+
- `Color` class
72+
- ```java
73+
Color mycolor = new Color(228, 100, 50);
74+
// how to set for button
75+
mybutton.setBackground(Color.mycolor);
76+
mybutton.setForeground(Color.mycolor);
77+
```
78+
79+
### JPanel
80+
- In `JFrame` we add a component `JPanel`
81+
82+
- [TestPanels](programs/TestPanels.java)
83+
84+
### Event-Handling in Java (Event-Driven Programming)
85+
86+
- [Lecture Notes](lecture-notes/Event-Driven_Programming.ppt)
87+
88+
- Event-driven programming (depends of action) <-> procedural programming (step by step)
89+
90+
- [HandleEvent](programs/HandleEvent.java)
91+
92+
- [HandleEvent1](programs/HandleEvent1.java) with the use of Inner Classes
93+
94+
- ```
95+
User Action Object Generated
96+
97+
Click a button JButton ActionEvent
98+
Click a check box JCheckBox ItemEvent, ActionEvent
99+
Click a radio button JRadioButton ItemEvent, ActionEvent
100+
Press return on a text field JTextField ActionEvent
101+
Select a new item JComboBox ItemEvent, ActionEvent
102+
Window opened, closed, etc. Window WindowEvent
103+
Mouse pressed, released, etc. Component MouseEvent
104+
Key released, pressed, etc. Component KeyEvent
105+
```
106+
107+
- ```
108+
Event Class Listener Interface Listener Methods (Handlers)
109+
ActionEvent ActionListener actionPerformed(ActionEvent)
110+
ItemEvent ItemListener itemStateChanged(ItemEvent)
111+
WindowEvent WindowListener windowClosing(WindowEvent)
112+
windowOpened(WindowEvent)
113+
windowIconified(WindowEvent)
114+
windowDeiconified(WindowEvent)
115+
windowClosed(WindowEvent)
116+
windowActivated(WindowEvent)
117+
windowDeactivated(WindowEvent)
118+
ContainerEvent ContainerListener componentAdded(ContainerEvent)
119+
componentRemoved(ContainerEvent)
120+
MouseEvent MouseListener mousePressed(MouseEvent)
121+
mouseReleased(MouseEvent)
122+
mouseClicked(MouseEvent)
123+
mouseExited(MouseEvent)
124+
mouseEntered(MouseEvent)
125+
KeyEvent KeyListener keyPressed(KeyEvent)
126+
keyReleased(KeyEvent)
127+
keyTypeed(KeyEvent)
128+
129+
```

lab-05/.idea/.gitignore

-3
This file was deleted.

lab-05/.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lab-05/.idea/workspace.xml

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Binary file not shown.

lecture-notes/Design_Pattern.pdf

3.9 MB
Binary file not shown.
282 KB
Binary file not shown.

lecture-notes/GUI_Basics.ppt

526 KB
Binary file not shown.
File renamed without changes.

lecture-notes/SOLID_principles.docx

28.6 KB
Binary file not shown.

midterm-exam/Account.java

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.util.Date;
2+
3+
public class Account {
4+
private int id = 0;
5+
private double balance = 0.0;
6+
private double annualInterestRate = 0.0;
7+
private Date dateCreated;
8+
9+
10+
public Account() {}
11+
12+
public Account(int id, int balance) {
13+
this.id = id;
14+
this.balance = balance;
15+
}
16+
17+
public int getId() {
18+
return id;
19+
}
20+
21+
public void setId(int id) {
22+
this.id = id;
23+
}
24+
25+
public double getBalance() {
26+
return balance;
27+
}
28+
29+
public void setBalance(double balance) {
30+
this.balance = balance;
31+
}
32+
33+
public double getAnnualInterestRate() {
34+
return annualInterestRate;
35+
}
36+
37+
public void setAnnualInterestRate(double annualInterestRate) {
38+
this.annualInterestRate = annualInterestRate;
39+
}
40+
41+
public Date getDateCreated() {
42+
return dateCreated;
43+
}
44+
45+
void withdraw(double amount) {
46+
balance -= amount;
47+
}
48+
49+
void deposit(double amount) {
50+
balance += amount;
51+
}
52+
53+
double getMonthlyInterestRate() {
54+
return annualInterestRate/12;
55+
}
56+
57+
double getMonthlyInterest() {
58+
return (annualInterestRate/12)*balance;
59+
}
60+
61+
}
62+
63+
interface Visitor {
64+
double visit(Account account);
65+
}
66+
67+
class TaxCalculator implements Visitor {
68+
69+
@Override
70+
public double visit(Account account) {
71+
return null;
72+
}
73+
}
74+
75+
class DailyInterestCalculator implements Visitor {
76+
77+
@Override
78+
public double visit(Account account) {
79+
return null;
80+
}
81+
}

midterm-exam/BankAccount.java

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import java.util.Date;
2+
3+
public class Account {
4+
private int id;
5+
private double balance;
6+
private double annualInterestRate;
7+
private Date dateCreated;
8+
9+
public Account() {
10+
this.id = 0;
11+
this.balance = 0;
12+
this.annualInterestRate = 1.2;
13+
this.dateCreated = new Date();
14+
}
15+
16+
public Account(int id, double balance) {
17+
this.id = id;
18+
this.balance = balance;
19+
this.annualInterestRate = 1.2;
20+
this.dateCreated = new Date();
21+
}
22+
23+
public int getId() {
24+
return this.id;
25+
}
26+
27+
public void setId(int id) {
28+
this.id = id;
29+
}
30+
31+
public double getBalance() {
32+
return this.balance;
33+
}
34+
35+
public void setBalance(double balance) {
36+
this.balance = balance;
37+
}
38+
39+
public double getAnnualInterestRate() {
40+
return this.annualInterestRate;
41+
}
42+
43+
public void setAnnualInterestRate(double annualInterestRate) {
44+
this.annualInterestRate = annualInterestRate;
45+
}
46+
47+
public Date getDateCreated() {
48+
return this.dateCreated;
49+
}
50+
51+
public void withdraw(double amount){
52+
if (amount<=0) {
53+
throw new RuntimeException("Invalid amount.");
54+
}
55+
if (amount<=this.balance) {
56+
this.setBalance(this.balance-amount);
57+
} else {
58+
throw new RuntimeException("Not enough funds");
59+
}
60+
}
61+
62+
public void deposit(double amount){
63+
if (amount<=0) {
64+
throw new RuntimeException("Invalid amount.");
65+
}
66+
this.setBalance(this.balance+amount);
67+
}
68+
69+
public double getMonthlyInterestRate(){
70+
return this.annualInterestRate / 12;
71+
}
72+
73+
public double getMonthlyInterest(){
74+
return (this.annualInterestRate / 12) * this.balance;
75+
}
76+
77+
public double accept(Visitor visitor){
78+
return visitor.visit(this);
79+
}
80+
}
81+
82+
83+
public interface Visitor {
84+
double visit(Account account);
85+
}
86+
87+
public class TaxCalculator implements Visitor {
88+
@Override
89+
public double visit(Account account) {
90+
return 0.05 * account.getAnnualInterestRate() * account.getBalance();
91+
}
92+
}
93+
94+
public class DailyInterestCalculator implements Visitor {
95+
@Override
96+
public double visit(Account account) {
97+
return (account.getMonthlyInterestRate() / 30) * account.getBalance();
98+
}
99+
}
100+
101+
// Problem 3 optional part
102+
public class AccountTest {
103+
public static void main(String[] args) {
104+
Visitor v1 = new TaxCalculator();
105+
106+
Account account = new Account(123, 100);
107+
108+
double tax = account.accept(v1);
109+
System.out.printf("Annual tax: %.2f$%n", tax);
110+
111+
v1 = new DailyInterestCalculator();
112+
double dailyInterest = account.accept(v1);
113+
114+
System.out.printf("Daily interest: %.2f$%n", dailyInterest);
115+
}
116+
}

0 commit comments

Comments
 (0)