/*
========================================================================================
Filename: 02_MarksCalculate.txt
Program 02: Create an app that takes marks of any three subjects from the user and displays its sum and average.
Files Included: MainActivity.java
========================================================================================

WHAT ALL TO DO / SETUP INSTRUCTIONS:
----------------------------------------------------------------------------------------
1. UI Components to Add (in res/layout/activity_main.xml):
   Add 3 EditText (TextBox):
     - etEnglishMarks (Hint: 'Enter the marks of English', inputType='number')
     - etMathMarks (Hint: 'Enter the marks of Mathematics', inputType='number')
     - etScienceMarks (Hint: 'Enter the marks of Science', inputType='number')
   Add 1 Button:
     - Text: 'Calculate', onClick: 'calculateMarks'
   Add 2 TextView:
     - tvTitle: 'Marks Calculator'
     - tvResult: To display Total marks and Average percentage

2. Layout Configuration:
   - LinearLayout (vertical orientation, android:gravity='center', padding 20dp)

3. Menu Configuration:
   - None required.

4. Themes Configuration (res/values/themes.xml):
   - Default theme. No changes needed.

5. AndroidManifest.xml:
   No special permissions required.
   Standard launcher activity declaration:
   <activity android:name=".MainActivity" android:exported="true" />

6. Additional Files & Resources Required:
   - None.
========================================================================================
*/

// ======================================================================================
// File: MainActivity.java
// ======================================================================================
package com.example.markscalculate;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle b) {
        super.onCreate(b);
        setContentView(R.layout.activity_main);
    }

    public void calculateMarks(View v) {
        EditText a=findViewById(R.id.etEnglishMarks),m=findViewById(R.id.etMathMarks),s=findViewById(R.id.etScienceMarks);
        TextView r=findViewById(R.id.tvResult);
        String x=a.getText().toString().trim(),y=m.getText().toString().trim(),z=s.getText().toString().trim();
        if(!x.isEmpty()&&!y.isEmpty()&&!z.isEmpty()) {
            int total=Integer.parseInt(x)+Integer.parseInt(y)+Integer.parseInt(z);
            double avg=total/3.0;
            r.setText("Total Marks : "+total+"\nAverage Marks : "+avg);
        }

        else r.setText("Please enter the marks of all subjects.");
    }
}
