abdurrahimagca / AtmProject

Undocumented class found JAVA-D1000
Documentation
Minor
a year agoa year old
Consider adding a doc comment for Transactions
  1
  2
  3public class Transactions {  4  5    //hata: eger fonksiyon exception verirse sorun olabilir  6    private static double stringToDouble(String text) {  7        //handle in 5 usages that if catch statement works, return an escape integer  8        double val = 0;  9        try { 10 11            val = Double.parseDouble(text); 12 13        } catch (Exception e) { 14            e.printStackTrace(); 15 16        } 17        return val; 18    } 19 20 21 22    public static boolean withdraw(String id, double amount) { 23        double deposit; 24        if (amount < 10 || amount > 1000) { 25            System.out.println("cekilecek tutar 10'dan kucuk olamaz"); 26            return false; 27        } 28 29        String temp = SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE id=" + id, "deposit"); 30 31 32        try { 33            deposit = Double.parseDouble(temp); 34            System.out.println(deposit); 35        } catch (Exception e) { 36            e.printStackTrace(); 37            return false; 38        } 39 40        if (deposit < amount) { 41            System.out.println("cekilmek istenen tutar bakiyeden fazla.. "); 42            return false; 43        } else if (deposit > amount) { 44            deposit = deposit - amount; 45            temp = String.valueOf(deposit); 46 47            SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + "WHERE id=" + id); 48 49            return true; 50        } 51        return false; 52    } 53 54 55    public static boolean deposit(String id, double amount) { 56        double deposit; 57 58        String temp = SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE id=" + id, "deposit"); 59        if (amount < 1) { 60            System.out.println("yatiralacak tutar sifirdan kucuk olamaz"); 61            return false; 62        } 63 64        deposit = stringToDouble(temp); 65 66        deposit = deposit + amount; 67        temp = String.valueOf(deposit); 68        SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + "WHERE id=" + id); 69 70        return true; 71 72    } 73 74 75 76    public static boolean transfer(String id, String IBAN, double amount) { 77        //todo: iban uzunlugunun kontrol edilmesi gerekli 78        if(IBAN.length()!=24) return false; 79 80        double depositSender, depositReceiver; 81        String temp = SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE id=" + id, "deposit"); 82        depositSender = stringToDouble(temp); 83        depositSender = depositSender - amount; 84        if (amount < 1) { 85            System.out.println("Gondereceginiz tutar 0'dan buyuk olmalıdır. "); 86            return false; 87        } 88        if (depositSender < amount) { 89            System.out.println("Bakiye yetersiz. "); 90            return false; 91        } 92        temp = SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE IBAN LIKE '%" + IBAN + "'", "deposit"); 93        depositReceiver = stringToDouble(temp); 94 95        depositReceiver = depositReceiver + amount; 96 97        temp = String.valueOf(depositReceiver); 98        SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + " WHERE IBAN LIKE '%" + IBAN + "'"); 99100        temp = String.valueOf(depositSender);101        SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + "WHERE id=" + id);102        return true;103104    }105106107    public static boolean payOffDebt(String id, double amount) {108        double deposit, debt;109        String temp = SqlQuery.StringGetSQL("SELECT debt FROM clients WHERE id=" + id, "debt");110        debt = stringToDouble(temp);111        temp = SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE id=" + id, "deposit");112        deposit = stringToDouble(temp);113        if (amount > deposit) {114            System.out.println("Odemek istediginiz tutar bakiyenizden fazla olamaz. ");115            return false;116        } else if (amount > debt) {117118            deposit = deposit - debt;119            debt = 0;120            temp = String.valueOf(deposit);121            SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + "WHERE id=" + id);122            SqlQuery.UpdateData("UPDATE clients SET debt=0 WHERE id=" + id);123            System.out.println("girdiginiz tutar borcunuzdan fazladir, borcunuz: " + debt + " TL ödenmistir. ");124            return true;125126        } else {127            deposit = deposit - amount;128            //todo: handle if temp is not a string129            temp = String.valueOf(deposit);130            SqlQuery.UpdateData("UPDATE clients SET deposit=" + temp + "WHERE id=" + id);131            debt = debt - amount;132            temp = String.valueOf(debt);133            SqlQuery.UpdateData("UPDATE clients SET debt=" + temp + "WHERE id=" + id);134            return true;135        }136    }137138139}
Consider adding a doc comment for SqlQuery
 5import java.sql.ResultSet;
 6import java.sql.Statement;
 7
 8public class SqlQuery { 9    public static ResultSet getResult(String query) {1011        try {12            Class.forName("com.mysql.cj.jdbc.Driver");13            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/atm", "root", "root");14            Statement stmt = con.createStatement();15            return stmt.executeQuery(query);1617        } catch (Exception e) {18            return null;19        }2021    }2223    //todo: fonksiyon bool veri döndürmeli24    public static void UpdateData(String query) {2526        try {27            Class.forName("com.mysql.cj.jdbc.Driver");28            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/atm", "root", "root");29            Statement stmt = con.createStatement();30            stmt.executeUpdate(query);313233        } catch (Exception e) {34            e.printStackTrace();35        }3637    }3839    public static String StringGetSQL(String query, String label) {40        String temp = null;41        try {42            Class.forName("com.mysql.cj.jdbc.Driver");43            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/atm", "root", "root");44            Statement stmt = con.createStatement();45            ResultSet rs = stmt.executeQuery(query);46            while (rs.next()) {47                temp = rs.getString(label);48            }4950        } catch (Exception e) {51            e.printStackTrace();52        }53        return temp;54    }5556}
Consider adding a doc comment for Main
  1import java.sql.*;
  2import java.util.Scanner;
  3
  4public class Main {  5    public static void main(String[] args) throws Exception {  6        Scanner sc = new Scanner(System.in);  7        String CardNum;  8        do {  9            System.out.println("Lutfen Kart Numaranizi giriniz... "); 10            CardNum = sc.next(); 11            Card card = new Card(CardNum); 12 13        } while (!Login.isCardValid()); 14        int attemps = -1; 15        do { 16 17            System.out.println("Hosgeldiniz! lutfen bir pin saglayin"); 18            if (attemps > 3) { 19                SqlQuery.UpdateData("UPDATE clients SET PIN='BLOCKED' WHERE CardNum=" + CardNum); 20                System.out.println("Sifreniz bloke edilmistir lutfen musteri hizmetleri ile gorusun.. "); 21                System.exit(2); 22            } else { 23 24                System.out.println("Lutfen pininizi giriniz... "); 25                String Pin = sc.next(); 26                Card.setPin(Pin); 27                attemps++; 28 29            } 30 31 32        } while (!Login.isPinTrue()); 33 34 35        String currentID = Card.returnID(); 36        int checker = -1; 37 38        do { 39            //terminal her seferinde temizlenmeli 40            System.out.println("Kullanibilir bakiyeniz: " + SqlQuery.StringGetSQL("SELECT deposit FROM clients WHERE id=" + currentID, "deposit")); 41            System.out.println("Lutfen yapmak istediginiz islemi seciniz. "); 42            System.out.println("1: Para Cek     2: Para Yatir"); 43            System.out.println("3: Para Gonder  4: Borc Ode"); 44            System.out.println("      0:Cikis Yap    "); 45            checker = sc.nextInt(); 46            Scanner scd = new Scanner(System.in); 47            double amount; 48            switch (checker) { 49                case 0: 50                    System.out.println("Yine Bekleriz"); 51                    break; 52                case 1: 53                    System.out.println("lutfen cekmek istediginiz tutari giriniz, bu minimum 10 en fazla 1000'dir"); 54                    amount = scd.nextDouble(); 55                    if (Transactions.withdraw(currentID, amount)) { 56                        System.out.println("para cekme basarili"); 57                    } else { 58                        System.out.println("para cekme islemi basarisiz"); 59                    } 60                    break; 61                case 2: 62                    System.out.println("Lutfen yatirmak istediginiz tutari giriniz. "); 63                    amount = scd.nextDouble(); 64                    if (Transactions.deposit(currentID, amount)) { 65                        System.out.println("para yatirma islemi basarili."); 66                    } else { 67                        System.out.println("para yatirma islemi basarisiz."); 68                    } 69                    break; 70                case 3: 71                    System.out.println("Para gondermek istediginiz IBANI giriniz.. "); 72                    System.out.printf("TR "); 73                    String IBAN = sc.next(); 74                    System.out.println("Gondermek istediginiz miktari giriniz.. "); 75                    amount = scd.nextDouble(); 76                    if (Transactions.transfer(currentID, IBAN, amount)) { 77                        System.out.println("para gonderildi"); 78                    } else 79                        System.out.println("para gonderilemedi."); 80                    break; 81                case 4: 82                    System.out.printf("Borcunuz: "); 83                    System.out.printf(SqlQuery.StringGetSQL("SELECT debt FROM clients WHERE id=" + currentID, "debt")); 84                    System.out.printf(" lutfen odemek istediginiz tutari giriniz.. "); 85                    amount = scd.nextDouble(); 86                    if (Transactions.payOffDebt(currentID, amount)) 87                        System.out.println("borcunuz basariyla odendi"); 88                    else 89                        System.out.println("borc odenemedi"); 90                    break; 91                default: 92                    System.out.println("Eksik ya da hatali bir tuslama yaptiniz lutfen tekrar deneyiniz.."); 93 94            } 95 96        } while (checker != 0); 97 98 99    }100}
Consider adding a doc comment for Login
 1import java.sql.ResultSet;
 2import java.sql.SQLException;
 3
 4public class Login extends Card { 5 6 7    public Login(String cardNum) { 8        super(cardNum); 9    }1011    public static boolean isCardValid() throws SQLException {12        ResultSet checkRs = SqlQuery.getResult(("SELECT id FROM clients WHERE CardNum=" + cardNum));1314        while (checkRs.next()) {15            return true;16        }17        System.out.println("hatali bir kart numarasi girdiniz lutfen tekrar deneyiniz.. ");18        return false;192021    }2223    public static boolean isPinTrue() {2425        String cardsPin = SqlQuery.StringGetSQL("SELECT PIN FROM clients WHERE CardNum=" + cardNum, "PIN");2627        if (cardsPin.equals("BLOCKED")) {28            System.out.println("Pininiz bloke");29            System.exit(2);3031        }3233        if (!(pin.length() == 4)) {34            System.out.println("Pininiz Dort Haneden Olusmalidir");35            return false;36        }37        try {38            int x = Integer.parseInt(pin);39        } catch (Exception e) {4041            System.out.println("Pin rakamlardan olusmalidir. ");42            return false;43        }44        if (!(pin.equals(cardsPin))) {45            System.out.println("sifreniz hatalidir. ");46            return false;4748        }49        return true;50    }515253}
Consider adding a doc comment for Card
 1import java.sql.ResultSet;
 2import java.sql.SQLException;
 3
 4public class Card { 5 6    protected static String cardNum; 7 8 9    protected static String pin;1011    public Card(String cardNum) {12        this.cardNum = cardNum;13        this.pin = "0000";14    }1516    public static void setPin(String pin) {17        Card.pin = pin;18    }1920    public static String getCardNum() {21        return cardNum;22    }2324    public static String getPin() {25        return pin;26    }2728    public static String returnID() throws SQLException {29        //todo:sqlden id çekilecek ve ana programa pushlanacak30        ResultSet rs = SqlQuery.getResult(("SELECT id FROM clients WHERE CardNum=" + cardNum));31        while (rs.next()) {32            return rs.getString("id");33        }34        return null;35    }36}