Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.48 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. import static com.company.Branches.customers;
  7.  
  8. public class Main {
  9. static Scanner scanner=new Scanner(System.in);
  10.     public static void main(String[] args) {
  11.  
  12.         menu();
  13.  
  14.  
  15.     }
  16.  
  17.  
  18.     public static void menu(){
  19.         System.out.println("Please enter your choice");
  20.         System.out.println("1.Branch\n2.Customers\n3.Exit");
  21.         int choice=scanner.nextInt();
  22.         Bank bank=new Bank("A");
  23.         switch (choice){
  24.             case 1:{
  25.                 boolean bool_branch=true;
  26.                 while(bool_branch){
  27.                 System.out.println("1.Create a new Branch\n2.delete a branch\n3.Search branch\n4.Print branch\n5.Return to the main menu\n6.Exit");
  28.                 int choice_branch=scanner.nextInt();
  29.                 switch (choice_branch)
  30.                 {
  31.                     case 1:{
  32.                         bank.add_Branch();
  33.                         break;
  34.                     }
  35.                     case 2:{
  36.                     bank.delete_branch();
  37.                         break;
  38.                     }
  39.                     case 3:{
  40.                         bank.search_branch();
  41.                         break;
  42.                     }
  43.                     case 4:{
  44.                         bank.print_branch();
  45.                         break;
  46.                     }
  47.                     case 5:{
  48.                      menu();
  49.                         break;
  50.                     }
  51.                     case 6:{
  52.                         bool_branch=false;
  53.                         break;
  54.                     }
  55.                     default:{
  56.                         System.out.println("Sorry invalid input ");
  57.                     }
  58.                 }
  59.  
  60.             }break;
  61.             }
  62.  
  63.             case 2:{
  64.                 boolean bool_customer=true;
  65.                 Branches branche=new Branches("branch1",customers);
  66.                 while (bool_customer){
  67.  
  68.                     System.out.println("1.Create a new customer\n2.delete a customer\n3.Search customer\n4.Print customers\n5.Exit");
  69.                     int choice_customer=scanner.nextInt();
  70.                     switch (choice_customer){
  71.                     case 1:{
  72.                     branche.new_Customer();
  73.                         break;
  74.                     }
  75.                     case 2:{
  76.                     branche.delete_Customer();
  77.                         break;
  78.                     }
  79.                     case 3:{
  80.                         branche.search_customer();
  81.                         break;
  82.  
  83.                     }
  84.                     case 4:{
  85.                         branche.print_customers();
  86.                         break;
  87.                     }
  88.                     case 5:{
  89.                         bool_customer=false;
  90.                         break;
  91.                     }
  92.                     default:{
  93.                         System.out.println("Sorry invalid input ");
  94.                     }
  95.                 }
  96.  
  97.             }break;}
  98.             case 3:{
  99.  
  100.                 return;
  101.             } default:{
  102.                 System.out.println("Sorry invalid input");
  103.             }
  104.  
  105.         }
  106.     }
  107.  
  108. }
  109.  
  110.  
  111. package com.company;
  112.  
  113. import java.util.ArrayList;
  114. import java.util.Scanner;
  115.  
  116. import static com.company.Branches.customers;
  117.  
  118. public class Bank {
  119.     private String name;
  120.     public static ArrayList<Branches> branches=new ArrayList<>();
  121.  
  122.     static Scanner scanner=new Scanner(System.in);
  123.  
  124.     public Bank(String name) {
  125.         this.name = name;
  126.     }
  127.  
  128.     public String getName() {
  129.         return name;
  130.     }
  131.  
  132.     public void setName(String name) {
  133.         this.name = name;
  134.     }
  135.  
  136.     public ArrayList<Branches> getBranches() {
  137.         return branches;
  138.     }
  139.  
  140.     public void setBranches(ArrayList<Branches> branches) {
  141.         this.branches = branches;
  142.     }
  143.  
  144.     public Branches add_Branch(){
  145.         System.out.println("Enter branch name");
  146.         String branch_name=scanner.next();
  147.  
  148.         Branches branches=new Branches(branch_name,customers);
  149.         this.branches.add(branches);
  150.         return branches;
  151.     }
  152.  
  153.     public static void delete_branch(){
  154.         System.out.println("Enter the name of the branch you want to delete");
  155.         String searched_name=scanner.next();
  156.         for (Branches branchess: branches) {
  157.             if(branchess.getName().equals(searched_name)){
  158.                 branches.remove(branchess);
  159.                 System.out.println("branch was deleted");
  160.             }
  161.             else{
  162.                 System.out.println("The object was mot found");
  163.             }
  164.  
  165.         }
  166.     }
  167.  
  168.     public static void print_branch(){
  169.         for(Branches branches:branches){
  170.             int i=0;
  171.             i++;
  172.             System.out.println("Name."+branches.getName()+"\nCustomers"+branches.getCustomers());
  173.  
  174.         }
  175.     }
  176.  
  177.     public static void search_branch(){
  178.         System.out.println("Enter the name of the branch you want to search");
  179.         String searched_name=scanner.next();
  180.         for (Branches branchess:branches) {
  181.             if(branchess.getName().equals(searched_name)){
  182.                 System.out.println("Name: "+branchess.getName());
  183.             }else{
  184.                 System.out.println("Was not found");
  185.             }
  186.         }
  187.     }
  188.  
  189. }
  190.  
  191.  
  192.  
  193. package com.company;
  194.  
  195. import java.util.ArrayList;
  196. import java.util.Scanner;
  197.  
  198. public class Branches {
  199.     static Scanner scanner=new Scanner(System.in);
  200.     private String name;
  201.     public static ArrayList<Customers> customers=new ArrayList<>();
  202.  
  203.     public Branches(String name, ArrayList<Customers> customers) {
  204.         this.name = name;
  205.         this.customers = customers;
  206.     }
  207.  
  208.     public String getName() {
  209.         return name;
  210.     }
  211.  
  212.     public void setName(String name) {
  213.         this.name = name;
  214.     }
  215.  
  216.     public ArrayList<Customers> getCustomers() {
  217.         return customers;
  218.     }
  219.  
  220.     public void setCustomers(ArrayList<Customers> customers) {
  221.         this.customers = customers;
  222.     }
  223.  
  224.     public static Customers new_Customer(){//review it to make it better later
  225.         System.out.println("Enter customer name");
  226.         String customer_name=scanner.next();
  227.         scanner.nextLine();
  228.         System.out.println("Enter Customer balance");
  229.         ArrayList<Double> customer_balance=new ArrayList<>();
  230.         Double customer_amount=scanner.nextDouble();
  231.         customer_balance.add(customer_amount);
  232.         scanner.nextLine();
  233.         Customers customerss=new Customers(customer_name,customer_balance);
  234.         customers.add(customerss);
  235.  
  236.         return customerss;
  237.     }
  238.     public static void delete_Customer(){
  239.  
  240.         System.out.println("Enter the name of the customers you want to delete");
  241.         String searched_name=scanner.next();
  242.         for (Customers c: customers) {
  243.             if(c.getName().equals(searched_name)){
  244.                 customers.remove(c);
  245.                 System.out.println("customer deleted");
  246.             }
  247.             else{
  248.                 System.out.println("The object was mot found");
  249.             }
  250.  
  251.         }
  252.     }
  253.  
  254.     public static void print_customers(){
  255.         for(Customers customers:customers){
  256.         int i=0;
  257.         i++;
  258.             System.out.println( "Name "+customers.getName()+" Balance: "+customers.getTransactions());
  259.  
  260.         }
  261.     }
  262.     public static void search_customer(){
  263.         System.out.println("Enter the name of the customers you want to search");
  264.         String searched_name=scanner.next();
  265.         for (Customers c: customers) {
  266.             if(c.getName().equals(searched_name)){
  267.                 System.out.println("Name: "+c.getName()+" Balance: "+c.getTransactions());
  268.             }else{
  269.                 System.out.println("Was not found");
  270.             }
  271.  
  272.  
  273.         }
  274.  
  275.     }
  276.  
  277. }
  278.  
  279.  
  280. package com.company;
  281.  
  282. import java.util.ArrayList;
  283.  
  284. public class Customers {
  285.     private String name;
  286.     public static ArrayList<Double> transactions=new ArrayList<>();
  287.  
  288.     public Customers(String name, ArrayList<Double> transactions) {
  289.         this.name = name;
  290.         this.transactions = transactions;
  291.     }
  292.  
  293.     public String getName() {
  294.         return name;
  295.     }
  296.  
  297.     public void setName(String name) {
  298.         this.name = name;
  299.     }
  300.  
  301.     public ArrayList<Double> getTransactions() {
  302.         return transactions;
  303.     }
  304.  
  305.     public void setTransactions(ArrayList<Double> transactions) {
  306.         this.transactions = transactions;
  307.     }
  308.  
  309.  
  310.  
  311.  
  312. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement