마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

학점계산기 만들고 있는데 질문 드립니다.

0 추천

학점계산기를 만들고 있는데 버튼으로 onclick 하면 스피너의 값과 에딧텍스트에 있는 숫자값 그리고 전공체크여부에 따라서 총 평점, 전공 평점, 이수학점, 전공이수학점으로 출력하도록 만들고 있습니다.

아래가 핵심 코드 인데요

 

onCheckBoxClicked() 함수에서 스위치문을 통해 체크박스를 선택할시 전공과목학점으로 판단하게 합니다.

근데 문제는 첫번째 과목, 학점, 학점, 전공여부에 대해서는 실행이 되는데

두번째 전공과목을 선택하면 이전 전공과목 값만 나오고 첫번쨰+두번째의 합으로 나오지가 않습니다.

세번째, 네번째, 다섯번쨰를 입력해도 그렇네요 어떻게해야 할까요?

    public void onCheckBoxClicked(View view) {


        switch (view.getId()) {
            case R.id.checkbox01:
                if (true)
                    jhsc1 = hsc1;
                else jhsc1=0;
                break;
            case R.id.checkbox02:
                if (true)
                    jhsc2 = hsc2;
                else jhsc2=0;
                break;
            case R.id.checkbox03:
                if (true)
                    jhsc3 = hsc3;
                else jhsc3=0;
                break;
            case R.id.checkbox04:
                if (true)
                    jhsc4 = hsc4;
                else jhsc4=0;
                break;
            case R.id.checkbox05:
                if (true)
                    jhsc5 = hsc5;
                else jhsc5=0;
                break;
        }
    }
    @Override
    public void onClick(View v) {

        edt01 = (EditText) findViewById(R.id.editText01);
        edt02 = (EditText) findViewById(R.id.editText02);
        edt03 = (EditText) findViewById(R.id.editText03);
        edt04 = (EditText) findViewById(R.id.editText04);
        edt05 = (EditText) findViewById(R.id.editText05);

        ctx = (TextView) findViewById(R.id.calctext);
        ctx1 = (TextView) findViewById(R.id.calctext1);
        ctx2 = (TextView) findViewById(R.id.calctext2);
        ctx3 = (TextView) findViewById(R.id.calctext3);

        tx = (TextView) findViewById(R.id.tex);
        tx1 = (TextView) findViewById(R.id.tex1);
        tx2 = (TextView) findViewById(R.id.tex2);
        tx3 = (TextView) findViewById(R.id.tex3);

        switch (v.getId()) {
            case R.id.Calc:
                if (edt05.getText().length() == 0
                        && edt04.getText().length() != 0) {
                    hsc1 = Float.parseFloat(edt01.getText().toString());
                    hsc2 = Float.parseFloat(edt02.getText().toString());
                    hsc3 = Float.parseFloat(edt03.getText().toString());
                    hsc4 = Float.parseFloat(edt04.getText().toString());

                    onCheckBoxClicked(v);

                    sum = (sc1 * hsc1) + (sc2 * hsc2) + (sc3 * hsc3) + (sc4 * hsc4);
                    hsum = hsc1 + hsc2 + hsc3 + hsc4;
                    jsum = (sc1*jhsc1) + (sc2*jhsc2) + (sc3*jhsc3) + (sc4*jhsc4);
                    jhsum = jhsc1+jhsc2+jhsc3+jhsc4;}

                else if (edt04.getText().length() == 0
                        && edt03.getText().length() != 0) {
                    hsc1 = Float.parseFloat(edt01.getText().toString());
                    hsc2 = Float.parseFloat(edt02.getText().toString());
                    hsc3 = Float.parseFloat(edt03.getText().toString());

                    onCheckBoxClicked(v);

                    sum = (sc1 * hsc1) + (sc2 * hsc2) + (sc3 * hsc3);
                    hsum = hsc1 + hsc2 + hsc3;
                    jsum = (sc1*jhsc1) + (sc2*jhsc2) + (sc3*jhsc3);
                    jhsum = jhsc1+jhsc2+jhsc3;}

                else if (edt03.getText().length() == 0
                        && edt02.getText().length() != 0) {
                    hsc1 = Float.parseFloat(edt01.getText().toString());
                    hsc2 = Float.parseFloat(edt02.getText().toString());

                    onCheckBoxClicked(v);

                    sum = (sc1 * hsc1) + (sc2 * hsc2);
                    hsum = hsc1 + hsc2;
                    jsum = (sc1*jhsc1) + (sc2*jhsc2);
                    jhsum = jhsc1 + jhsc2;}

                else if (edt02.getText().length() == 0
                        && edt01.getText().length() != 0) {
                    hsc1 = Float.parseFloat(edt01.getText().toString());

                    onCheckBoxClicked(v);

                    sum = (sc1 * hsc1);
                    hsum = hsc1;
                    jsum = sc1*jhsc1;
                    jhsum = jhsc1;}

                else if (edt01.getText().length() == 0)
                    Toast.makeText(this, "학점좀 입력해주세요.", Toast.LENGTH_SHORT).show();

                else {
                    hsc1 = Float.parseFloat(edt01.getText().toString());
                    hsc2 = Float.parseFloat(edt02.getText().toString());
                    hsc3 = Float.parseFloat(edt03.getText().toString());
                    hsc4 = Float.parseFloat(edt04.getText().toString());
                    hsc5 = Float.parseFloat(edt05.getText().toString());

                    onCheckBoxClicked(v);

                    sum = (sc1 * hsc1) + (sc2 * hsc2) + (sc3 * hsc3) + (sc4 * hsc4) + (sc5 * hsc5);
                    hsum = hsc1 + hsc2 + hsc3 + hsc4 + hsc5;

                    jsum = (sc1*jhsc1) + (sc2*jhsc2) + (sc3*jhsc3) + (sc4*jhsc4) + (sc5*jhsc5);
                    jhsum = jhsc1 + jhsc2 + jhsc3 + jhsc4 + jhsc5;
                }

                total = sum / hsum;
                jhtotal = jsum / jhsum;

                DecimalFormat fmt = new DecimalFormat("0.##");
                DecimalFormat fma = new DecimalFormat("000.#");

                tx.setText("총 평점 ");
                ctx.setText("" +total);
                tx1.setText("전공평점 ");
                ctx1.setText("" +jhtotal);
                tx2.setText("이수학점 ");
                ctx2.setText("" +hsum);
                tx3.setText("전공이수학점");
                ctx3.setText("" + jhsum);

                total=0;
                jhtotal=0;
                hsum=0;
                jhsum=0;
                break;

            case R.id.reset:
                edt01.setText("");
                edt02.setText("");
                edt03.setText("");
                edt04.setText("");
                edt05.setText("");
                tx.setText("");
                ctx.setText("");
                tx1.setText("");
                ctx1.setText("");
                tx2.setText("");
                ctx2.setText("");
                tx3.setText("");
                ctx3.setText("");

                total=0;
                jhtotal=0;
                hsum=0;
                jhsum=0;

                break;
        }
    }

 

나르티스 (120 포인트) 님이 2016년 5월 23일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...