This tutorial will teach you Student Marks Calculation Project in Android Studio step by step.
Input Student Name, Marks and Calculate the Total,avg,grade.when you calculate the grade you have to follow the Following Conditions.if the avg is greater than 50 grade will be pass other wise grade will be fail.
Design the UI Design
Android studio folder structure there is folder which is res this is the folder will help us to make a UI Design of the App.inside res folder you can see the layout folder if you expand the layout folder there is a file
activity_main.xml
in this file we will design App Layout i have design the registration UI design below.
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" tools:context=".MainActivity" android:orientation="vertical" android:gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="30sp" android:gravity="center" android:text="@string/emptitle" android:textSize="15dp" android:textStyle="bold" android:textColor="@color/colorPrimary" /> <ImageView android:layout_width="200sp" android:layout_height="100sp" android:gravity="center" android:src="@drawable/marks" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:text="@string/stname" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/stname" android:textColor="@color/colorPrimary" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15sp" android:text="@string/marks1" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/mark1" android:textColor="@color/colorPrimary" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15sp" android:text="@string/marks2" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/mark2" android:textColor="@color/colorPrimary" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:text="@string/marks3" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/mark3" android:textColor="@color/colorPrimary" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:text="@string/total" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:id="@+id/total" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textColor="@color/colorPrimary" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:text="@string/avg" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/avg" android:textColor="@color/colorPrimary" android:gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20sp" android:text="@string/grade" android:textSize="15sp" android:textStyle="italic" android:textColor="@color/colorAccent" /> <EditText android:id="@+id/grade" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textColor="@color/colorPrimary" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="right" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnok" android:textColor="#ffffff" android:background="@color/colorPrimary" android:id="@+id/btn1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnclear" android:textColor="#ffffff" android:background="@color/colorAccent" android:id="@+id/btn2" /> </LinearLayout> </LinearLayout> </LinearLayout> |
colors.xml
1 2 3 4 5 6 | <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#008577</color> <color name="colorPrimaryDark">#00574B</color> <color name="colorAccent">#D81B60</color> </resources> |
strings.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <resources> <string name="app_name">Student Marks Calculation System</string> <string name="emptitle">Student Marks Calculation System</string> <string name="stname">Student Name</string> <string name="marks1">Marks 1</string> <string name="marks2">Marks 2</string> <string name="marks3">Marks 3</string> <string name="total">Total</string> <string name="avg">Average</string> <string name="grade">Grade</string> <string name="btnok">Ok</string> <string name="btnclear">Clear</string> </resources> |
style.xml
1 2 3 4 5 6 7 8 9 10 11 | <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> |
MainActitity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | package com.example.kobinath.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity { EditText ed1,ed2,ed3,ed4,ed5,ed6,ed7; Button btn1,btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ed1 = findViewById(R.id.stname); ed2 = findViewById(R.id.mark1); ed3 = findViewById(R.id.mark2); ed4 = findViewById(R.id.mark3); ed5 = findViewById(R.id.total); ed6 = findViewById(R.id.avg); ed7 = findViewById(R.id.grade); btn1 = findViewById(R.id.btn1); btn2 = findViewById(R.id.btn2); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { stmarks(); } }); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clear(); } }); } public void stmarks() { int m1,m2,m3,tot; double avg; String grade; m1 = Integer.parseInt(ed2.getText().toString()); m2 = Integer.parseInt(ed3.getText().toString()); m3 = Integer.parseInt(ed4.getText().toString()); tot = m1 + m2 + m3; ed5.setText(String.valueOf(tot)); avg = tot/3; ed6.setText(String.valueOf(avg)); if(avg > 75) { ed7.setText("A"); } else if(avg > 65) { ed7.setText("B"); } else if(avg > 55) { ed7.setText("C"); } else if(avg > 40) { ed7.setText("S"); } else { ed7.setText("Fail"); } } public void clear() { ed1.setText(""); ed2.setText(""); ed3.setText(""); ed4.setText(""); ed5.setText(""); ed6.setText(""); ed7.setText(""); ed1.requestFocus(); } } |