I face a funny problem : i wrote a code as the tutorial but i found a different result

I'm trying to write a simple code to calculate the students degrees and there assessment but i didn't find the logical output , the output doesn't match with the inputs

this is a beautiful try as an android beginner

Java code

package com.example.m_elshambaky.school;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView txtotal , Prcnt , Grad , HiDeg , LoDeg;
    EditText txtNo , LayDeg;
    Button ok;
double to = 0;
    double max = 0;
    double min = 100;
    String grd = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        txtNo = findViewById(R.id.txtNo);
        ok = findViewById(R.id.ok);
        txtotal = findViewById(R.id.txtotal);
        Prcnt = findViewById(R.id.Prcnt);
        Grad = findViewById(R.id.Grad);
        HiDeg = findViewById(R.id.HiDeg);
        LoDeg = findViewById(R.id.LoDeg);

        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (txtNo.getText().toString().equals(""))
                {
                    txtNo.setFocusable(true);
                    txtNo.setError("please enter subjects no.");
                }
                else {

                final int no = Integer.parseInt(txtNo.getText().toString());

                int y = 1;
                while(y <= no)
                {
                    LayoutInflater s = LayoutInflater.from(MainActivity.this);
                    View e = s.inflate(R.layout.schol_lay,null);
                    AlertDialog.Builder q = new AlertDialog.Builder(MainActivity.this);

                    LayDeg = e.findViewById(R.id.LayDeg);

                    q.setView(e);
                    q.setCancelable(false);
                    q.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

here i receive number of subjects

                            double De = Double.parseDouble(LayDeg.getText().toString());

here i adding degrees so can find the percentage

                            to = to + De;
                            txtotal.setText("Total is " + String.valueOf(to));

*here i dividing total by number of subjects to get the percentage*

the next (no) variable is underlined

                            double per = to / no;
                            Prcnt.setText("Percentage is " + String.valueOf(per) + "%");


                            if (per < 40)
                                grd = "Sorry , you have failed";
                            else if (per <= 50)
                                grd = "D";
                            else if (per <= 60)
                                grd = "C";
                            else if (per <= 70)
                                grd = "B";
                            else if (per <= 80)
                                grd = "A";
                            else grd = "A+";

                            Grad.setText("your grade "+(grd));


                            if(De > max)
                                max = De;

                            HiDeg.setText("Highest degree is "+ String.valueOf(max));


                            if(De < min)
                                min = De;

                            LoDeg.setText("Lowest degree is " + String.valueOf(min));


                        }
                    });
                    q.create();
                    q.show();
                    y++;
                }
                }
            }
        });