Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- import static com.company.Branches.customers;
- public class Main {
- static Scanner scanner=new Scanner(System.in);
- public static void main(String[] args) {
- menu();
- }
- public static void menu(){
- System.out.println("Please enter your choice");
- System.out.println("1.Branch\n2.Customers\n3.Exit");
- int choice=scanner.nextInt();
- Bank bank=new Bank("A");
- switch (choice){
- case 1:{
- boolean bool_branch=true;
- while(bool_branch){
- 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");
- int choice_branch=scanner.nextInt();
- switch (choice_branch)
- {
- case 1:{
- bank.add_Branch();
- break;
- }
- case 2:{
- bank.delete_branch();
- break;
- }
- case 3:{
- bank.search_branch();
- break;
- }
- case 4:{
- bank.print_branch();
- break;
- }
- case 5:{
- menu();
- break;
- }
- case 6:{
- bool_branch=false;
- break;
- }
- default:{
- System.out.println("Sorry invalid input ");
- }
- }
- }break;
- }
- case 2:{
- boolean bool_customer=true;
- Branches branche=new Branches("branch1",customers);
- while (bool_customer){
- System.out.println("1.Create a new customer\n2.delete a customer\n3.Search customer\n4.Print customers\n5.Exit");
- int choice_customer=scanner.nextInt();
- switch (choice_customer){
- case 1:{
- branche.new_Customer();
- break;
- }
- case 2:{
- branche.delete_Customer();
- break;
- }
- case 3:{
- branche.search_customer();
- break;
- }
- case 4:{
- branche.print_customers();
- break;
- }
- case 5:{
- bool_customer=false;
- break;
- }
- default:{
- System.out.println("Sorry invalid input ");
- }
- }
- }break;}
- case 3:{
- return;
- } default:{
- System.out.println("Sorry invalid input");
- }
- }
- }
- }
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- import static com.company.Branches.customers;
- public class Bank {
- private String name;
- public static ArrayList<Branches> branches=new ArrayList<>();
- static Scanner scanner=new Scanner(System.in);
- public Bank(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public ArrayList<Branches> getBranches() {
- return branches;
- }
- public void setBranches(ArrayList<Branches> branches) {
- this.branches = branches;
- }
- public Branches add_Branch(){
- System.out.println("Enter branch name");
- String branch_name=scanner.next();
- Branches branches=new Branches(branch_name,customers);
- this.branches.add(branches);
- return branches;
- }
- public static void delete_branch(){
- System.out.println("Enter the name of the branch you want to delete");
- String searched_name=scanner.next();
- for (Branches branchess: branches) {
- if(branchess.getName().equals(searched_name)){
- branches.remove(branchess);
- System.out.println("branch was deleted");
- }
- else{
- System.out.println("The object was mot found");
- }
- }
- }
- public static void print_branch(){
- for(Branches branches:branches){
- int i=0;
- i++;
- System.out.println("Name."+branches.getName()+"\nCustomers"+branches.getCustomers());
- }
- }
- public static void search_branch(){
- System.out.println("Enter the name of the branch you want to search");
- String searched_name=scanner.next();
- for (Branches branchess:branches) {
- if(branchess.getName().equals(searched_name)){
- System.out.println("Name: "+branchess.getName());
- }else{
- System.out.println("Was not found");
- }
- }
- }
- }
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Branches {
- static Scanner scanner=new Scanner(System.in);
- private String name;
- public static ArrayList<Customers> customers=new ArrayList<>();
- public Branches(String name, ArrayList<Customers> customers) {
- this.name = name;
- this.customers = customers;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public ArrayList<Customers> getCustomers() {
- return customers;
- }
- public void setCustomers(ArrayList<Customers> customers) {
- this.customers = customers;
- }
- public static Customers new_Customer(){//review it to make it better later
- System.out.println("Enter customer name");
- String customer_name=scanner.next();
- scanner.nextLine();
- System.out.println("Enter Customer balance");
- ArrayList<Double> customer_balance=new ArrayList<>();
- Double customer_amount=scanner.nextDouble();
- customer_balance.add(customer_amount);
- scanner.nextLine();
- Customers customerss=new Customers(customer_name,customer_balance);
- customers.add(customerss);
- return customerss;
- }
- public static void delete_Customer(){
- System.out.println("Enter the name of the customers you want to delete");
- String searched_name=scanner.next();
- for (Customers c: customers) {
- if(c.getName().equals(searched_name)){
- customers.remove(c);
- System.out.println("customer deleted");
- }
- else{
- System.out.println("The object was mot found");
- }
- }
- }
- public static void print_customers(){
- for(Customers customers:customers){
- int i=0;
- i++;
- System.out.println( "Name "+customers.getName()+" Balance: "+customers.getTransactions());
- }
- }
- public static void search_customer(){
- System.out.println("Enter the name of the customers you want to search");
- String searched_name=scanner.next();
- for (Customers c: customers) {
- if(c.getName().equals(searched_name)){
- System.out.println("Name: "+c.getName()+" Balance: "+c.getTransactions());
- }else{
- System.out.println("Was not found");
- }
- }
- }
- }
- package com.company;
- import java.util.ArrayList;
- public class Customers {
- private String name;
- public static ArrayList<Double> transactions=new ArrayList<>();
- public Customers(String name, ArrayList<Double> transactions) {
- this.name = name;
- this.transactions = transactions;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public ArrayList<Double> getTransactions() {
- return transactions;
- }
- public void setTransactions(ArrayList<Double> transactions) {
- this.transactions = transactions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement