Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @SpringBootApplication
- public class PaymentsApplication {
- private static Map<Long, User> userBase = new HashMap<>();
- static Scanner scan = new Scanner(System.in);
- public static long id = 0;
- @SuppressWarnings("unused")
- public static void main(String[] args) {
- ApplicationContext ctx = SpringApplication.run(PaymentsApplication.class, args);
- User mainBean = (User) ctx.getBean("user");
- while (true) {
- System.out.println("Нажмите:");
- System.out.println("1 - для создания пользователя");
- System.out.println("2 - для отображения списка пользователей");
- // System.out.println("3 - для остановки работы программы");
- String s = scan.nextLine();
- int ch = Integer.parseInt(s);
- switch (ch) {
- case 1:
- // Создать пользователей, также клиентов и админа
- insertUser();
- break;
- case 2:
- // Получение объекта клиента по ид юзера.
- getUser(id);
- break;
- default:
- return;
- }
- }
- }
- //Создать пользователей - Клиентов и администраторов
- public static void insertUser() {
- Long id = getLastId();
- String name;
- String password;
- String type;
- User user;
- while (true) {
- id++;
- System.out.println("Нажмите:");
- System.out.println("1 - для создания клиента");
- System.out.println("2 - для создания администратора");
- String s = scan.nextLine();
- int ch = Integer.parseInt(s);
- switch (ch) {
- case 1:
- System.out.println("Введите имя клиента:");
- name = scan.nextLine();
- System.out.println("Введите пароль:");
- password = scan.nextLine();
- type = "Client";
- user = new User(name, password, type);
- user.client = new Client(user);
- userBase.put((long) id, user);
- System.out.println("Введите номер счёта:");
- String accountNumber = scan.nextLine(); //номер
- user.client.createAccount(id, accountNumber); //создаём номер счёта клиента
- user.client.getAccount();
- Account account = user.client.createAccount(id, accountNumber);
- System.out.println("Введите номер карты для счёта:");
- String cardNumber = scan.nextLine();
- account.createCard(cardNumber);
- break;
- case 2:
- System.out.println("Введите имя администратора:");
- name = scan.nextLine();
- System.out.println("Введите пароль:");
- password = scan.nextLine();
- type = "Admin";
- user = new User(name, password, type);
- user.admin = new Admin(user);
- userBase.put((long) id, user);
- break;
- default:
- return;
- }
- break;
- }
- }
- private static void getUser(long id) {
- // Набор элементов
- Set<Map.Entry<Long, User>> set = userBase.entrySet();
- // Отобразим набор
- for (Map.Entry<Long, User> me : set) {
- System.out.println(me.getKey() + ": "+me.getValue().type);
- System.out.println("Name: "+me.getValue().username);
- System.out.println("Password: "+me.getValue().password);
- //System.out.println(me.getValue().username+", "+me.getValue().password+", "+me.getValue().type); //1: AlexS, password, client
- System.out.println();
- }
- }
- // получение наибольшего id из существующих
- // чтобы вставлять новых юзеров с несуществующим id
- public static Long getLastId() {
- Long result = (long) 0;
- for (Entry<Long, User> entry : userBase.entrySet()) {
- Long id = entry.getKey();
- if (id > result) {
- result = id;
- }
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement