Sprawdzenie kodu.

0

Czesc

potrzebuje pomocy, z kodem
uzywany byl java, hibernate i javafx czy tam swing

https://pastebin.com/7nVjPFwY

otoz mial to byc typowy CRUD pisany na szybko na zaliczenie.
chcialbym wiedziec czego tu mozna uzyc zeby nauczyc sie czegos nowego i jednoczesnie zeby to nie bylo takie spagetti.

w ogole to jakies rady by sie przydaly co by tu robic zeby jakos sie na staz zalapac =)

Pozdrawiam

8
            new Object [][] {

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null},

                {null, null, null, null, null, null}

            },

:D

na staz zalapac

No chyba nie.

0

ups =| mialem to zmienic

2

Przeklejanie całych porcji kodu tylko po to, by zmienić parę linijek, też nie wygląda obiecująco.

   public static void insertGh(Greenhouse e) {
       
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            session.save(e);
            tx.commit();
            System.out.println("INSERTED TO GH");
        }
        catch (Exception x) {
            if (tx!=null) tx.rollback();
        }finally {
            session.close();
        }
    }

    public static void deleteGh(Greenhouse e) {
       
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            session.delete(e);
            tx.commit();
            System.out.println("DELETED FROM GH");
        }
        catch (Exception x) {
            if (tx!=null) tx.rollback();
        }finally {
            session.close();
        }
       
    }

(I to osiem razy).

Powinieneś zachować cały szkielet głównej metody w jednym miejscu (zasada DRY), a do osobnych metod wyekstrahować tylko to, co się w tych implementacjach różni.

1

javafx czy tam swing

aha, nie wiesz czego uzywasz?

0

Komentarze to wymóg prowadzącego zajęcia?

0

I kolejne zaklecie niewybaczalne czyli użycie double do operacji monetarnych:

double sum = 0;
        DecimalFormat df = new DecimalFormat("#.##");
        df.setRoundingMode(RoundingMode.CEILING);
 
        for(int i = 0; i < orderedProductList.size(); i++) {
            double price = Double.parseDouble(df.format(orderedProductList.get(i).getUnitprice() * orderedProductList.get(i).getQuantity()));
            sum+=price;
        }

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.