Projekt arkusz w javie

0

Witam wszystkich. Akurat mam do napisania projekt arkusz kalkulacyjny i myślałem, że pójdzie łatwo, ale teraz napotykam same problemy. A czasu mało :/
Pierwszym problemem jest sprawdzanie poprawności wyrażenia/formuły. Próbuje to rozbijać na liczby,adresy i funkcje. No, ale jak myślę, żeby sprawdzać każdy warunek, to może to mnie przerosnąć. Jak za bardzo nikt nie będzie miał czasu to trudno jakoś będę musiał sobie poradzić :/
Napisałem coś takiego:

 package arkusz;

import java.util.ArrayList;


public class Arkusz 
{
    Komorka [][] array = new Komorka[1000][100];
    public static final int Int = 0, Double = 1, Str = 2, Data = 3;
    Arkusz()
    {
        for(int i = 0; i<1000; i++)
            for(int j = 0; j<100; j++)
                array[i][j] = new Komorka();
    }
    String getWyswietlana(int x, int y)
    {
        return array[x][y].getWyswietlana();
    }
    String getFormula(int x, int y)
    {
        return array[x][y].getFormula();
    }
    String getWartosc(int x, int y)
    {
        return array[x][y].getWartosc();
    }
    int getTyp(int x, int y)
    {
        return array[x][y].getTyp();
    }
    void setFormula(int x, int y, String formula)
    {
        array[x][y].setFormula(formula);
    }
    void setWartosc(int x, int y, String wartosc)
    {
        array[x][y].setWartosc(wartosc);
    }
    void setTyp(int x, int y, int a)
    {
       array[x][y].setTyp(a); 
    }
    void wykonajFormula()
    {
        
    }
}

class Komorka
{
    private String wartosc, formula, wyswietlana;
    private int typ;
    public static final int Int = 0, Double = 1, Str = 2, Data = 3;
    Komorka()
    {
        wartosc = "";
        wyswietlana = "";
        typ = Double;
    }
    String getWyswietlana()
    {
        return wyswietlana;
    }
    String getFormula()
    {
        return formula;
    }
    String getWartosc()
    {
        return wartosc;
    }
    int getTyp()
    {
        return typ;
    }
    void setFormula(String formula)
    {
        this.formula = formula;
    }
    void setWartosc(String wartosc)
    {
        this.wartosc = wartosc;
    }
    void setTyp(int a)
    {
       typ = a; 
    }/*
    boolean checkFormula()
    {
        int k = 0;
        for(int i = 0; i<formula.length(); i++) {
            if(formula.charAt(i) == '+' || formula.charAt(i) == '-' 
                    || formula.charAt(i) == '*' || formula.charAt(i) == '/')
            {
                if(!checkAdres(formula.substring(k, i)) )
                    if(!checkLiczba(formula.substring(k, i)))
            }
            k=i+1;
        }
    }*/
    boolean checkAdres(String formula)
    {
        if(formula.charAt(0) >= 65 && formula.charAt(0) <=90 )
        {
            if(formula.charAt(1) >= 65 && formula.charAt(1) <=90 ) {
                try {
                    Integer.parseInt(formula.substring(2));
                }
                catch(NumberFormatException ex) {
                    return false;
                }
            }
            try {
                    Integer.parseInt(formula.substring(1));
                }
                catch(NumberFormatException ex) {
                    return false;
                }
            return true;
        }
        return false;
    }
    boolean checkLiczba(String formula)
    {
        try {
            Integer.parseInt(formula);
        }
        catch(NumberFormatException ex){
            return false;
        }
        return true;
    }/*
    boolean checkWyrazenie(String formula)
    {
        /// SUMA(A1:B2)
        
    }*/
}

abstract class Formula
{
    abstract double getI();
}

class Adres extends Formula
{
    double a;
    Adres(String ad, ArrayList<ArrayList<Double>> tab)
    {
        int y = Integer.parseInt(ad.substring(1))-1;
        int x = ad.charAt(0) - 64;
        a = tab.get(x).get(y);
    }
    @Override
    double getI()
    {
        return a;
    }
}
class Liczba extends Formula
{
    double a;
    Liczba(double a)
    {
        this.a = a;
    }
    @Override
    double getI()
    {
        return a;
    }
}

class Suma extends Formula
{
    Formula a,b;
    Suma(Formula a, Formula b)
    {
        this.a = a;
        this.b = b;
    }
    @Override
    double getI()
    {
        return a.getI() + b.getI();
    }
}
class Roznica extends Formula
{
    Formula a,b;
    Roznica(Formula a, Formula b)
    {
        this.a = a;
        this.b = b;
    }
    @Override
    double getI()
    {
        return a.getI() - b.getI();
    }
}
class Iloczyn extends Formula
{
    Formula a,b;
    Iloczyn(Formula a, Formula b)
    {
        this.a = a;
        this.b = b;
    }
    @Override
    double getI()
    {
        return a.getI() * b.getI();
    }
}
class Iloraz extends Formula
{
    Formula a,b;
    Iloraz(Formula a, Formula b)
    {
        this.a = a;
        this.b = b;
    }
    @Override
    double getI()
    {
        return a.getI() / b.getI();
    }
}
0

I wszystko robisz w jednym pliku..? rozbij to na sensowne klasy, będzie czytelniej i stawiam, że łatwiej.
co do samego problemu, pisząc, że chcesz sprawdzić poprawność wyrażenia/formuły chodzi Ci o to, czy zawiera dozwolone znaki, czy że np. jest poprawnym wyrażeniem arytmetycznym?
jeśli to drugie to jest trochę sposobów: http://tinyurl.com/parseexpressionjava
jest chyba nawet gotowa biblioteka do takich rzeczy (ale z niej nie korzystałem).
a do sprawdzania samych adresów komórek wystarczy prosta pętla z kilkoma ifami.

(btw. pochwal się jeszcze dla którego prowadzącego ten projekt :P)

1 użytkowników online, w tym zalogowanych: 0, gości: 1