Ферганский филиал ташкентского университета информационных технологий имени мухаммада ал-хоразмий
Download 120.91 Kb.
|
ИП Музаффаров
- Bu sahifa navigatsiya:
- ОТЧЁТЫ
ПРАКТИЧЕСКАЯ ЧАСТЬpackage ATM; import Bank.BankService; import Server.CheckProcessing; import Server.DataProcessing; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.math.BigDecimal; import java.util.Objects; import java.util.Scanner; public class Atm { private static final Scanner scan = new Scanner(System.in); private static BigDecimal check; private static Integer cardnumber; private static void CheckSum(BigDecimal sum) { if (check != null && check.compareTo(sum) < 0) { System.out.println("Insufficient funds in the account."); ReturnMenu(); } } private static void ReturnMenu() { System.out.println(""" Back to main menu? Yes - 1 No - 2 """); System.out.print("Select: "); int J = scan.nextInt(); if (J == 1) { Interaction(); } else { System.out.println("Take your card"); System.exit(0); } } private static void Interaction() { System.out.println(""" Select an action: 1. - Balance check 2. - Card transfer (1%) 3. - Withdraw cash (1%) 4. - Replenish the balance 5. - Cancellation of operations """); System.out.print("Select: "); int i = scan.nextInt(); switch (i) { case 1 -> { System.out.println("Balance: " + "$" + check); ReturnMenu(); } case 2 -> { System.out.print("Enter card number: "); int card = scan.nextInt(); if (card == cardnumber) { System.out.println("You cannot transfer money to your own card"); ReturnMenu(); } System.out.print("Enter amount: "); BigDecimal SUM = scan.nextBigDecimal(); CheckSum(SUM); check = check.subtract(SUM.multiply(new BigDecimal("1.01"))); System.out.println("Transaction completed successfully."); ReturnMenu(); } case 3 -> { System.out.print("Enter the amount to withdraw cash: "); BigDecimal sum = scan.nextBigDecimal(); CheckSum(sum); check = check.subtract(sum.multiply(new BigDecimal("1.01"))); System.out.println("Done."); ReturnMenu(); } case 4 -> { System.out.print("Balance replenishment amount: "); BigDecimal sum = scan.nextBigDecimal(); check = check.add(sum); System.out.println("Done."); ReturnMenu(); } case 5 -> { System.out.println("Take your card"); System.exit(0); } default -> { System.out.println("Error"); Interaction(); } } } private static void Checking() throws ParserConfigurationException, SAXException { DataProcessing dataProcessing = new DataProcessing(); dataProcessing.parseXMLserver(); int cardNumberServer = dataProcessing.getCARD_NUMBER(); Integer pinCodeServer = dataProcessing.getPIN(); CheckProcessing checkProcessingBank = new CheckProcessing(); checkProcessingBank.parseXMLbank(); int cardNumberBank = checkProcessingBank.getCARD_NUMBER(); if (Objects.equals(cardNumberBank, cardNumberServer)) { if (Objects.equals(cardnumber, cardNumberServer)) { System.out.print("Please, enter your PIN code: "); int pinCode = scan.nextInt(); String buff = Integer.toString(pinCode); if (buff.length() == 4) { if (Objects.equals(pinCode, pinCodeServer)) { CheckProcessing checks = new CheckProcessing(); checks.parseXMLbank(); check = checks.getCHECK(); Interaction(); } else { System.out.println("PIN code is incorrect"); } } else { System.out.println("You entered the wrong pin code."); Checking(); } } else { System.out.println("Card number not found."); } } else { System.out.println("Error, contact the bank support service."); } } public static void main(String[] args) throws ParserConfigurationException, SAXException { if (BankService.turning = true) { System.out.print("Enter your card number: "); cardnumber = scan.nextInt(); String buff = Integer.toString(cardnumber); if (buff.length() == 8) { Checking(); } else { System.out.println("You entered the wrong card number."); } } else { System.out.println("ATM is temporarily out of service"); } } } package Bank; import Server.BankDataProcessing;
import javax.xml.parsers.ParserConfigurationException; import java.math.BigDecimal; import java.text.MessageFormat; import java.util.Objects; import java.util.Scanner; public class BankService { private static final Scanner scan = new Scanner(System.in); private static BigDecimal check; public static Boolean turning = true; private static String name; private static String surName; private static int cardNumberServer; private static void checkSum(BigDecimal sum) { if (check != null && check.compareTo(sum) < 0) { System.out.println("Insufficient funds in the account."); } } private static void bankService() throws ParserConfigurationException, SAXException { System.out.println(""" Select service: 1. - Replenish the balance 2. - Withdraw cash (1%) 3. - Create an account 4. - To change the data 5. - Disable all ATMs (root) 6. - Get bank card details 7. - Cancellation of operations """); System.out.print("Select: "); int i = scan.nextInt(); switch (i) { case 1 -> { System.out.print("Balance replenishment amount: "); BigDecimal sum = scan.nextBigDecimal(); check = check.add(sum); System.out.println("Done."); } case 2 -> { System.out.print("Enter the amount to withdraw cash: "); BigDecimal sum = scan.nextBigDecimal(); checkSum(sum); check = check.subtract(sum.multiply(new BigDecimal("1.01"))); System.out.println("Done."); } case 3 -> { //создание счёта } case 4 -> { //изменить данные } case 5 -> { System.out.println("Enter password for root access: "); int root = scan.nextInt(); BankDataProcessing bankDataProcessing = new BankDataProcessing(); bankDataProcessing.parseXMLbank(); int rootServer = bankDataProcessing.getRoot(); if (Objects.equals(root, rootServer)) { turning = false; bankService(); } else { System.out.println("You entered the wrong root password."); } } case 6 -> { BankDataProcessing bankDataProcessing = new BankDataProcessing(); bankDataProcessing.parseXMLbank(); String bankName = bankDataProcessing.getName(); String bankInn = bankDataProcessing.getInn(); System.out.println(MessageFormat.format("Name: {0}\nSurname: {1}\nCard number: {2}\nBank name: {3}\nBank INN: {4}", name, surName, cardNumberServer, bankName, bankInn)); } case 7 -> { System.out.println("Take your card"); System.exit(0); } default -> { System.out.println("Error"); bankService(); } } } private static void bankCheck() throws ParserConfigurationException, SAXException { DataProcessing dataProcessing = new DataProcessing(); dataProcessing.parseXMLserver(); cardNumberServer = dataProcessing.getCARD_NUMBER(); Integer pinCodeServer = dataProcessing.getPIN(); CheckProcessing checkProcessingBank = new CheckProcessing(); checkProcessingBank.parseXMLbank(); int cardNumberBank = checkProcessingBank.getCARD_NUMBER(); if (Objects.equals(cardNumberBank, cardNumberServer)) { name = DataProcessing.getNAME(); surName = DataProcessing.getSurName(); if (Objects.equals(cardNumberBank, cardNumberServer)) { System.out.print("Enter PIN code: "); int pinCode = scan.nextInt(); String buff = Integer.toString(pinCode); if (buff.length() == 4) { if (Objects.equals(pinCode, pinCodeServer)) { CheckProcessing checks = new CheckProcessing(); checks.parseXMLbank(); check = checks.getCHECK(); bankService(); } } } } else { System.out.println("Error, contact the bank support service."); } } public static void main(String[] args) throws ParserConfigurationException, SAXException { System.out.print("Enter card number: "); int cardNumberBank = scan.nextInt(); String buff = Integer.toString(cardNumberBank); if (buff.length() == 8) { bankCheck(); } else { System.out.println("You entered the wrong card number."); } } } package Server; import org.xml.sax.Attributes;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class DataProcessing extends DefaultHandler { private String elementName; private int CARD_NUMBER; public int getCARD_NUMBER() { return CARD_NUMBER; } private int PIN; public int getPIN() { return PIN; } private static String NAME; public static String getNAME() { return NAME; } protected static String SUR_NAME; public static String getSurName() { return SUR_NAME; } public void parseXMLserver() throws ParserConfigurationException, SAXException { String filePath = "C:\\Project\\Java\\ATM_SYSTEM\\src\\Bank\\Clients.xml"; SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); try (InputStream xmlInput = new FileInputStream(filePath)) { parser.parse(xmlInput, this); } catch (IOException e) { e.printStackTrace(); } } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) { elementName = qName; } @Override public void endElement(String uri, String localName, String qName) { elementName = ""; } @Override public void characters(char[] ch, int start, int length) { String trim = new String(ch, start, length).trim(); switch (elementName) { case "card_number" -> CARD_NUMBER = (int) Long.parseLong(trim); case "pin"-> PIN = Integer.parseInt(trim); case "name"-> NAME = String.copyValueOf(trim.toCharArray()); case "sur_name"-> SUR_NAME = String.copyValueOf(trim.toCharArray()); } } } package Server; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; public class CheckProcessing extends DefaultHandler { private String elementName; private BigDecimal CHECK; public BigDecimal getCHECK() { return CHECK; } private int CARD_NUMBER; public int getCARD_NUMBER() { return CARD_NUMBER; } public void parseXMLbank() throws ParserConfigurationException, SAXException { String filePath = "C:\\Project\\Java\\ATM_SYSTEM\\src\\Bank\\CustomerAccount.xml"; SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); try (InputStream xmlInput = new FileInputStream(filePath)) { parser.parse(xmlInput, this); } catch (IOException e) { e.printStackTrace(); } } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) { elementName = qName; } @Override public void endElement(String uri, String localName, String qName) { elementName = ""; } @Override public void characters(char[] ch, int start, int length) { String trim = new String(ch, start, length).trim(); switch (elementName) { case "check" -> CHECK = BigDecimal.valueOf(Double.parseDouble(trim)); case "card_number" -> CARD_NUMBER = Integer.parseInt(trim); } } } package Server; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class BankDataProcessing extends DefaultHandler { private String elementName; private String name; public String getName() { return name; } private String inn; public String getInn() { return inn; } private int root; public int getRoot() { return root; } public void parseXMLbank() throws ParserConfigurationException, SAXException { String filePath = "C:\\Project\\Java\\ATM_SYSTEM\\src\\Bank\\Data_Bank.xml"; SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); try (InputStream xmlInput = new FileInputStream(filePath)) { parser.parse(xmlInput, this); } catch (IOException e) { e.printStackTrace(); } } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) { elementName = qName; } @Override public void endElement(String uri, String localName, String qName) { elementName = ""; } @Override public void characters(char[] ch, int start, int length) { String trim = new String(ch, start, length).trim(); switch (elementName) { case "name" -> name = String.copyValueOf(trim.toCharArray()); case "inn" -> inn = String.copyValueOf(trim.toCharArray()); case "root" -> root = Integer.parseInt(trim); } } } ОТЧЁТЫВводим номер карты и ПИН-код, открывается меню операций. Нам нужно снять наличные и посмотреть баланс. Download 120.91 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling