Advertisement
Guest User

Untitled

a guest
Apr 17th, 2019
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package forni;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author ihab
  14. */
  15. public class Forni {
  16.  
  17. /**
  18. * @param args the command line arguments
  19. */
  20. public static void main(String[] args) {
  21.  
  22. Account a1 = new Account("ihab", 232, 545, new Address(3 , "street", "suburb", "city"));
  23. Account a2 = new Account("moey", 0, 545, new Address(3 , "street", "suburb", "city"));
  24. Account a3 = new Account("gary", 123, 545, new Address(3 , "street", "suburb", "city"));
  25. Account a4 = new Account("gary", 456, 545, new Address(3 , "street", "suburb", "city"));
  26.  
  27.  
  28. Bank b1 = new Bank("username", "password");
  29. //
  30. b1.addAccount(a1);
  31. b1.addAccount(a2);
  32. b1.addAccount(a3);
  33. b1.addAccount(a4);
  34.  
  35. Scanner input = new Scanner(System.in);
  36.  
  37. System.out.println("enter user ID");
  38. int n = input.nextInt();
  39. b1.findAccount(n);
  40.  
  41. System.out.println("enter deposit amount");
  42. int d = input.nextInt();
  43. a2.deposit(d);
  44. a2.print();
  45.  
  46. System.out.println("enter withraw amount");
  47. int W = input.nextInt();
  48. a3.withdraw(d);
  49. a3.print();
  50.  
  51. System.out.println("enter street name");
  52. a4.getAddress().setstreet(input.next());
  53.  
  54. System.out.println("enter street number");//prints the following
  55. a4.getAddress().setstreetNum(input.nextInt());
  56.  
  57. System.out.println("enter suburb");//prints the following
  58. a4.getAddress().setsuburb(input.next());// simalir to streetNum
  59. System.out.println("enter city");//prints the following /
  60. a4.getAddress().setcity(input.next());//simalir to streetNum
  61.  
  62. Address a;
  63.  
  64. a = a4.getAddress();
  65. System.out.println(a);
  66.  
  67. a4.getAddress().printAddress();
  68.  
  69.  
  70. a1.makePurchase(1, "liverpool", "cup", 30);
  71. a1.makePurchase(1, "liverpool", "book", 50);
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. }
  79. }
  80.  
  81. class Account {
  82.  
  83. private String name;
  84. private int ID;
  85. private double balance;
  86. private Address address = new Address(3, "street", "suburb", "city");//obj of class Address
  87.  
  88. ArrayList<Transaction> transactions = new ArrayList<Transaction>();
  89.  
  90. ;
  91.  
  92. public Account(String n, int i, double b, Address address) {
  93.  
  94. this.name = n;
  95. this.ID = i;
  96. this.balance = b;
  97.  
  98. }
  99.  
  100. public void setname(String n) {
  101. name = n;
  102.  
  103. }
  104.  
  105. public String getname() {
  106. return name;
  107.  
  108. }
  109.  
  110. public void setid(int i) {
  111. ID = i;
  112. }
  113.  
  114. public int getid() {
  115. return ID;
  116. }
  117.  
  118. public void setbalance(double b) {
  119. balance = b;
  120. }
  121.  
  122. public double getbalance() {
  123. return balance;
  124. }
  125.  
  126. public boolean withdraw(double amount) {
  127. if (amount == balance || amount > balance) {
  128. System.out.println("successful");
  129. balance -= amount;
  130. return true;
  131. } else {
  132. System.out.println("Balance is not enough");
  133.  
  134. return false;
  135. }
  136.  
  137. }
  138.  
  139. public void deposit(double amount) {
  140. if (amount > 0.0) {
  141. balance += amount;
  142. System.out.println("successful");
  143. } else if (amount < 0.0) {
  144. System.out.println("not successful");
  145.  
  146. }
  147.  
  148. }
  149.  
  150. public Address getAddress() {
  151. return address;
  152. }
  153.  
  154. public void print() {
  155. System.out.println( " " + this.ID + " " + this.balance + " " + this.name);
  156.  
  157. }
  158.  
  159. public void addTransaction(Transaction transaction) {
  160. transactions.add(transaction);
  161.  
  162. }
  163.  
  164. boolean makePurchase(int ID, String city, String description, double amount) {
  165.  
  166. if (balance > amount) {
  167. balance -= amount;
  168.  
  169. addTransaction(new Transaction(ID, city, description, amount));
  170.  
  171. return true;
  172. } else {
  173. System.out.println("unsucessful " + " " + amount);
  174. return false;
  175. }
  176.  
  177. }
  178.  
  179. }
  180.  
  181. class Address {
  182.  
  183. private int streetNum;
  184. private String street;
  185. private String suburb;//var
  186. private String city;
  187.  
  188. public Address(int streetNum, String street, String suburb, String city) {//con
  189.  
  190. this.streetNum = streetNum;
  191. this.street = street;
  192. this.suburb = suburb;
  193. this.city = city;
  194.  
  195. }
  196.  
  197. public void setstreetNum(int Sn) {//setter
  198. streetNum = Sn;
  199. }
  200.  
  201. public int getstreetNum() {
  202. return streetNum;
  203. }
  204.  
  205. public void setstreet(String S) {
  206. street = S;
  207. }
  208.  
  209. public String getStreet() {//getter
  210. return street;
  211. }
  212.  
  213. public void setsuburb(String sub) {
  214. suburb = sub;
  215. }
  216.  
  217. public String getsuburb() {
  218. return suburb;
  219. }
  220.  
  221. public void setcity(String city) {
  222. city = city;
  223. }
  224.  
  225. public String getcity() {
  226. return city;
  227. }
  228.  
  229. public void printAddress() {//prints address
  230. System.out.println("street Address" + " " + this.streetNum + " " + this.street + " " + this.suburb + " " + this.city);
  231. }
  232.  
  233. }
  234.  
  235. class Transaction {
  236.  
  237. private int ID;
  238. private String city;
  239. private String description;
  240. private double amount;
  241.  
  242. public Transaction(int i, String c, String d, double a) {
  243.  
  244. this.ID = i;
  245. this.city = c;
  246. this.description = d;
  247. this.amount = a;
  248.  
  249. }
  250.  
  251. public void setid(int i) {
  252. ID = i;
  253.  
  254. }
  255.  
  256. public int getid() {
  257. return ID;
  258. }
  259.  
  260. public void setcity(String c) {
  261. city = c;
  262. }
  263.  
  264. public String getcity() {
  265. return city;
  266. }
  267.  
  268. public void setdes(String d) {
  269. description = d;
  270.  
  271. }
  272.  
  273. public String getdes() {
  274. return description;
  275. }
  276.  
  277. public void setamount(double a) {
  278. amount = a;
  279. }
  280.  
  281. public double getamount() {
  282. return amount;
  283. }
  284.  
  285. public void printtrans() {
  286. System.out.println(this.ID);
  287. System.out.println(this.amount);
  288. System.out.println(this.city);
  289. System.out.println(this.description);
  290. }
  291.  
  292. }
  293.  
  294. class Bank {
  295. String username;
  296. String password;
  297.  
  298. public String getusername() {
  299. return username;
  300. }
  301.  
  302. public String getPassword() {
  303. return password;
  304. }
  305. public Bank(String u, String p) {
  306. u = username;
  307. p = password;
  308. }
  309. private ArrayList<Account> accounts = new ArrayList<Account>();
  310.  
  311. private String adminUsername;
  312. private String adminPassword;
  313.  
  314. boolean validateAdmin(String username, String password) {
  315.  
  316. if (this.getusername() == adminUsername && this.getPassword() == adminPassword ) {
  317. return true;
  318. } else {
  319.  
  320. return false;
  321. }
  322.  
  323. // while (username == adminUsername && password == adminPassword) {
  324. }
  325.  
  326. boolean addAccount(Account account) {
  327.  
  328. accounts.add(account);
  329.  
  330. return true;
  331.  
  332. }
  333.  
  334. Account findAccount(int accountID) {
  335.  
  336. for (Account acc : accounts) {
  337.  
  338. if (accountID == acc.getid()) {
  339.  
  340. System.out.println("Account ID = " + acc.getid());
  341.  
  342. return acc;
  343.  
  344. } else {
  345. System.out.println("Account does not exist");
  346. }
  347.  
  348. }
  349. return null;
  350. }
  351.  
  352. public double calcTotalBalance() {
  353. double totalBalance = 0;
  354. for (Account acc : accounts) {
  355. totalBalance = totalBalance +acc.getbalance();
  356. }
  357. return totalBalance;
  358. }
  359.  
  360. public void printAccounts() {
  361. for (Account acc : accounts) {
  362. System.out.println(acc);
  363.  
  364. }
  365.  
  366. }
  367.  
  368. }
  369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement