Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public static Scanner scanner = new Scanner(System.in);
  2. public static Bank newBank = new Bank("BMCE");
  3.  
  4. public static void addNewCostumer(){
  5. System.out.println("Choose a branch :");
  6. String branchChoosed = scanner.nextLine();
  7. Branches branches = newBank.queryBranch(branchChoosed);
  8. if(branches == null){
  9. System.out.println("There are a problem, or you are entered a wrong name of branch");
  10.  
  11. }
  12. else{
  13. System.out.println("Enter the name costumer :");
  14. String nameOfCostumer = scanner.nextLine();
  15. System.out.println("Enter the transaction number :");
  16. double transactions = scanner.nextDouble();
  17. scanner.nextLine();
  18. if(newBank.addNewCostumer(branches,nameOfCostumer,transactions)){
  19. System.out.println("The costumer was created in branch name :"+branches.getNameOfBranch());
  20.  
  21.  
  22. }else{
  23.  
  24. System.out.println("Sorry you dindn't create a costumer in "+branches.getNameOfBranch()+" Try again please :)");
  25.  
  26. }
  27.  
  28. }
  29.  
  30. private String name;
  31. private ArrayList<Branches> branchesArrayList = new ArrayList<>();
  32.  
  33. public boolean addNewCostumer(Branches nameOfExistingBranch,String nameOfNewCostumer,double newTransaction){
  34. int position = findBranch(nameOfExistingBranch);
  35.  
  36.  
  37. if(position<0){
  38. System.out.println("There is not branch with this name");
  39. return false;
  40. }
  41. else{
  42. if(this.branchesArrayList.get(position).findCostumer(nameOfNewCostumer)>=0){
  43. System.out.println("You have already an existing costumer with that name");
  44. return false;
  45. }
  46. else{
  47.  
  48. this.branchesArrayList.get(position).addNewCostumer(nameOfNewCostumer,newTransaction);
  49. return true;
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57. public int findBranch(Branches branches){
  58. int position = this.branchesArrayList.indexOf(branches);
  59. if(position>=0){
  60.  
  61. return position;
  62.  
  63. }
  64. else
  65. return -1;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement