Masalaning qo’yilish: Click tizimini loyhalsh : Project ni tasnifi
Download 29.46 Kb.
|
7 - ish
8- TAJRIBA ISHI Mavzu: Click tizimin loyhalash Tayyorladi: Fayziboyev Abbos Tekshirdi: Nilufar Mirzayeva Toshkent – 2020 Masalaning qo’yilish: Click tizimini loyhalsh : Project ni tasnifi: Payme tizimini loyhalash Proyektsa Account, Actions, Card va Main classlari bo’ladi. Va shuningdek unda CardType enum va ActionInterface interface bor. Account classida user larning accounti turadi. Yani Account biror bir phone numberga ochiladi. Accountning password va cards field lari mavjud. Bitta accoutda bir necha cartalar mavjud bo’lishi mumkin. Shuning uchun Account ning cartalarini map orqali saqlash mumkin. Chunki bitta cardNumber da bitta carta bo’lishi mumkin. Ya’ni cardnumber bir dona bo’lishi kerak. Actions Interface bu bajariladigan ammalarning aniqlab beruvchi interface. Unda open(), enter(), allAccountsShow() metodlari mavjud. open() - yangi account ochish uchun enter() - parol orqali accountga kirish allAccountsShow() – barcha accounlari ko’rish unchun Actions class ActionsInterface interfaceidan implementatsiya olgan. Bu klass orqali biz yangi account ochishimiz accountdan foydalanishimiz mumkin. Card classini yaratib oishish orqali biz turli hildagi accountlarni yaratishimiz mumkin. Card class ida CardNumber, Expire, CardType , histories, money va password field lari mavjud. Biz kartani qaysi turdaligini aniqlash uchun cardType enum ochishimiz lozim. Unda Turkiston, Kapitalbank va yana bir qancha banklar nomi mavjud. Biz CardType enum orqali kart tipini aniqlab olishimiz mumkin. Main classida esa user dasturn I boshqarishi mumkin. package OOP.Card; import Collections.Lists.Car; import java.util.*;
public class Account { private String number; private String password; private Map public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Map return cards; } public void setCards(Map this.cards = cards; } public void addCard() { Scanner scanner = new Scanner(System.in); if (cards.size() != 0) System.out.println("You have " + cards.size() + " cards."); else System.out.println("You do not have any card."); int n = -1; while (true) {
if (n == 1 || n == 2) { break; } } if (n == 1) { Card card = new Card(); while (true) { System.out.println("Enter a card" + " number:\n ---- ---- ---- ----"); String number = scanner.next(); if (Pattern.matches("[0-9]{16}", number)) { card.setCardNumber(number); System.out.println("Card number " + "" + number.substring(0, 4) + " " + number.substring(4, 8) + " " + "" + number.substring(8, 12) + " " + number.substring(12, 16)); break; } } while (true) { System.out.println("Enter a expire : mm/yy"); String expire = scanner.next(); if (Pattern.matches("[0-9]{2}/[0-9]{2}", expire)) { card.setExpire(expire); break; } } boolean b = true; while (b) { System.out.println("Choose one card type. "); int co = 1; for (CardType cardType : CardType.values()) { System.out.println((co++) + " : " + cardType); } String cardTypeString = scanner.next(); for (CardType cardType : CardType.values()) {
System.out.println("Your Card Type : " + cardType); b = false; break; } } } while (true) { System.out.println("Enter a password: ---- "); String password = scanner.next(); System.out.println("Reenter your password "); String rePassword = scanner.next(); if (rePassword.equalsIgnoreCase(password) && Pattern.matches("[0-9]{4}", password)) { card.setPassword(password); break; } } if (cards.keySet().contains(card.getCardNumber())) System.out.println("This card number is exist" + " already ! Adding this card is not possible !!!"); else cards.put(card.getCardNumber(), card); } } @Override public String toString() { return "Account{" + "number='" + number + '\'' + ", password='" + password + '\'' + "\n Cards - > \n" + cards ; } } package OOP.Card; public interface ActionInterface { void open(); void enter(); void allAccountsShow(); } package OOP.Card; import Collections.Lists.Car; import OOP.Interface.MAin; import java.util.*; import java.util.regex.Pattern; public class Actions implements ActionInterface { Map @Override public void open() { Account account = new Account(); Scanner scanner = new Scanner(System.in); while (true) {
if (Pattern.matches("[+][0-9]{12}", phoneNumber)) { account.setNumber(phoneNumber); System.out.println("Your number is :" + " +998 (9" + phoneNumber.charAt(5) + ") " + phoneNumber.substring(6, 9) + " " + "" + phoneNumber.substring(9, 11) + " " + "" + phoneNumber.substring(11, 13)); break; } } while (true) { System.out.println("Enter password : "); String password = scanner.next(); System.out.println("Reenter your password : "); String rePassword = scanner.next(); if (rePassword.equals(password) && Pattern.matches("[a-zA-Z0-9]{6,}" + "", password)) { account.setPassword(password); break; } } account.addCard(); System.out.println("Card is added successfully !!! "); while (true) { System.out.println("\nDo you want to add another card ! "); System.out.println(" 1 - > yes "); System.out.println(" 2 - > no"); int n = scanner.nextInt(); if (n == 1) { account.addCard(); } else if (n == 2) { System.out.println("Your account has been" + "created successfully ! Thank you ! "); accountHashMap.put(account.getNumber(), account); break;
} } @Override public void allAccountsShow() { for (String key : accountHashMap.keySet()) { System.out.println(accountHashMap.get(key)); } } @Override public void enter() { Scanner scanner = new Scanner(System.in); Account myAccount = null; Boolean bool2 = true; while (bool2) { System.out.println("Enter your phone " + "number !!! +998 9. ... .. .. "); String phoneNumber = scanner.next(); System.out.println("Enter your password !!! "); String password = scanner.next(); if (accountHashMap.keySet().contains(phoneNumber)) { myAccount = accountHashMap.get(phoneNumber); break; } else { System.out.println("The Account" + " is not exist "); } } System.out.println("Welcome ... "); boolean bool = true; while (bool) { System.out.println(" 0 - > Exit\n 1 - >" + " Balance \n 2 - > Payment " + "\n 3 - > Add Card \n 4 - > History" + " \n 5 - > Card Replenish "); int n = scanner.nextInt(); Map switch (n) { case 0: bool = false; break; case 1: Boolean bool1 = true; while (bool1) { System.out.println(" 0 - > Exit \n 1 - > Check balance "); int t = scanner.nextInt(); if (t == 1) { System.out.println("choose one of your card !"); for (String key : cardMap.keySet()) System.out.println(cardMap.get(key)); Card myCard = null; while (true) {
if (sendMoney * 1.01 <= sendMoneyCard.getMoney()) { boolean bool0 = true;
for (Account account : accountHashMap.values()) { if (account.getCards().keySet().contains(tillWho)) { takeMoneyCard = account.getCards().get(tillWho); if (!takeMoneyCard.getCardNumber().equalsIgnoreCase( sendMoneyCard.getCardNumber())) { takeMoneyCard.setMoney(sendMoney + takeMoneyCard.getMoney()); sendMoneyCard.setMoney(sendMoneyCard.getMoney() - 1.01 * sendMoney); Card.History newHistory = new Card.History(); newHistory.setSentMoney(sendMoney); newHistory.setTillWho(takeMoneyCard.getCardNumber()); newHistory.setFromWho(sendMoneyCard.getCardNumber()); takeMoneyCard.addHistory(newHistory); newHistory.setFromWho(sendMoneyCard.getCardNumber());
sendMoneyCard.addHistory(newHistory); cardMap.put(sendMoneyCard.getCardNumber(), sendMoneyCard);
Map temCardMapImport.put(takeMoneyCard.getCardNumber(), takeMoneyCard); account.setCards(temCardMapImport); accountHashMap.put(account.getNumber(), account); System.out.println("PROSES IS FINISHED !"); bool0 = false; break; } } }
} break;
myAccount.addCard(); String key = myAccount.getNumber(); accountHashMap.remove(key); accountHashMap.put(key, myAccount); System.out.println(accountHashMap.get(key)); break;
System.out.println("Choose one of your card !"); for (String k : cardMap.keySet()) System.out.println(cardMap.get(k)); System.out.println("Enter card number "); String numberCard = scanner.next(); if (cardMap.keySet().contains(numberCard)) { Card historyCard = cardMap.get(numberCard); System.out.println(historyCard.getHistories()); } break; case 5:
Card replenishedCard = null; for (String key1 : cardMap.keySet()) System.out.println(cardMap.get(key1)); System.out.println("Enter a card number ! "); String key1 = scanner.next(); if (cardMap.keySet().contains(key1)) replenishedCard = cardMap.get(key1); if (replenishedCard != null) { System.out.println("Enter the amount of money !"); double enteredMoney = scanner.nextDouble(); replenishedCard.setMoney(replenishedCard.getMoney() + enteredMoney); Card.History cardhistory = new Card.History(); cardhistory.setFromWho("0000000000000001"); cardhistory.setTillWho(replenishedCard.getCardNumber()); cardhistory.setSentMoney(enteredMoney); replenishedCard.addHistory(cardhistory); cardMap.put(replenishedCard.getCardNumber(), replenishedCard); myAccount.setCards(cardMap); accountHashMap.put(myAccount.getNumber(), myAccount); System.out.println(myAccount.getCards().get(replenishedCard.getCardNumber())); System.out.println("THANK YOU FOR BANKING WITH US !!! "); }
} } } package OOP.Card; import java.util.LinkedList;
public class Card { private String cardNumber; private String expire; private CardType cardType; private List private double money; private String password; public Card() { }
public String getCardNumber() { return cardNumber; } public void setCardNumber(String cardNumber) { this.cardNumber = cardNumber; } public String getExpire() { return expire; } public void setExpire(String expire) { this.expire = expire; } public CardType getCardType() { return cardType; } public void setCardType(CardType cardType) { this.cardType = cardType; } public List return histories; } public void setHistories(List this.histories = histories; } public double getMoney() { return money; } public void setMoney(double money) { this.money = money; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public void CardReplenish() { Scanner scanner = new Scanner(System.in); System.out.println("Money : "); Double EnteredMoney = scanner.nextDouble(); EnteredMoney = EnteredMoney + money; setMoney(EnteredMoney); } public void addHistory(History newHistory){ histories.add(newHistory); } public void seeHistory(){ for (int i = 0; i < histories.size(); i++) { System.out.println(histories.get(i)); } } public static class History { private String fromWho ; private String tillWho ; private double sentMoney ; public String getFromWho() { return fromWho; } public void setFromWho(String fromWho) { this.fromWho = fromWho; } public String getTillWho() { return tillWho; } public void setTillWho(String tillWho) { this.tillWho = tillWho; } public double getSentMoney() { return sentMoney; } public void setSentMoney(double sentMoney) { this.sentMoney = sentMoney; } @Override public String toString() { return String.format("\n" + fromWho.substring(0,4) +" "+ fromWho.substring(4,8)+ " "+ fromWho.substring(8,12)+ " "+ fromWho.substring(12,16)+ " - > " + tillWho.substring(0,4) + " " + tillWho.substring(4,8) +" " + tillWho.substring(8,12)+ " " + tillWho.substring(12,16)+ " : " + "%-10s"+String.valueOf(sentMoney)); } } @Override public String toString() { return "Card : \n" + "cardNumber = " + cardNumber + "\n" + "expire = " + expire + "\n"+ "cardType = " + cardType +"\n"+ "histories = " + histories +"\n"+ "money = " + money +"\n" + "password='" + password + '\'' + "\n"; } } package OOP.Card; public enum CardType {
Download 29.46 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling