title: Calculating GPA in android studio
body: <p>I have a small project to create an application that calculates the students GPAs. </p>
  
  <p>So far, I'm using a spinner to have the students select their grades. Please note that I only created one slot for one course, once it is working fine I will modify the formula to calculate all the courses. </p>
  
  <p>once I click the button which should do the claculation nothing happened.</p>
  
  <p>XML</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.example.abdulelah.mygpa.GPA_51"
      tools:showIn="@layout/activity_gpa_51"&gt;
  
      &lt;TextView
          android:id="@+id/Result5_1"
          android:layout_width="77dp"
          android:layout_height="28dp"
          android:layout_marginBottom="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:text="TextView"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.501"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.443" /&gt;
  
      &lt;Spinner
          android:id="@+id/spinner5_1"
          android:text="Spinner"
          android:layout_width="93dp"
          android:layout_height="28dp"
          android:layout_marginBottom="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.029"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.036" /&gt;
  
      &lt;EditText
          android:id="@+id/creditNum"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_marginBottom="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:ems="10"
          android:inputType="number"
          app:layout_constraintBottom_toTopOf="@+id/Result5_1"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintHorizontal_bias="0.232"
          app:layout_constraintStart_toEndOf="@+id/spinner5_1"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintVertical_bias="0.021" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="48dp"
          android:layout_marginBottom="8dp"
          android:layout_marginEnd="8dp"
          android:layout_marginStart="8dp"
          android:layout_marginTop="8dp"
          android:text="Button"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/Result5_1" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Java code </p>
  
  <pre><code>package com.example.abdulelah.mygpa;
  
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Spinner;
  import android.widget.TextView;
  
  public class GPA_51 extends AppCompatActivity {
  
  Spinner spinner;
  double gradesValue;
  double result;
  EditText creditNum;
  TextView result511;
  Button ButtonResult;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_gpa_51);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
  
      creditNum = (EditText)findViewById(R.id.creditNum);
      ButtonResult = (Button)findViewById(R.id.button1);
      result511 = (TextView)findViewById(R.id.Result5_1);
  
  
  
  
      spinner = (Spinner) findViewById(R.id.spinner5_1);
      final String[] grades = {"A+", "A", "B+", "B", "C+", "C", "D+", "D", "F"};
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, grades);
      spinner.setAdapter(adapter);
  
      spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int i, long id) {
              parent.getItemAtPosition(i);
  
              if (grades.equals("A+"))
                  gradesValue=4.00;
              else if (grades.equals("A"))
                  gradesValue=3.75;
              else if (grades.equals("B+"))
                  gradesValue=3.50;
              else if (grades.equals("B"))
                  gradesValue=3.00;
              else if (grades.equals("C+"))
                  gradesValue=2.50;
              else if (grades.equals("C"))
                  gradesValue=2.00;
              else if (grades.equals("D+"))
                  gradesValue=1.50;
              else if (grades.equals("D"))
                  gradesValue=1.00;
              else if (grades.equals("F"))
                  gradesValue=0;
  
  
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  
  
  
  
      ButtonResult.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              String creditNumber1 = creditNum.getText().toString();
              int numberOfCredit = Integer.parseInt(creditNumber1);
  
  
              result = gradesValue * numberOfCredit;
  
              result511.setText(String.valueOf(result));
               }
      });
  
  
  }
  </code></pre>
  
  <p>}</p>