Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.package.calc;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.*;
- import android.widget.*;
- public class Gpa extends Activity {
- Button b;
- EditText cre[] = new EditText[14];
- EditText sub[] = new EditText[14];
- TableRow tab[] = new TableRow[14];
- float num=0,den=0,gpa;
- int f=0,i;
- float c[] = new float[14];
- float g[] = new float[14];
- String j,dept;
- String s[] = new String[14];
- final Context con = this;
- final Activity acti = this;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Intent intent1 = getIntent();
- dept = intent1.getStringExtra("dept");
- b = (Button) findViewById(R.id.button2);
- tab[0] = (TableRow) findViewById(R.id.tableRow2);
- tab[1] = (TableRow) findViewById(R.id.tableRow3);
- tab[2] = (TableRow) findViewById(R.id.tableRow4);
- tab[3] = (TableRow) findViewById(R.id.tableRow5);
- tab[4] = (TableRow) findViewById(R.id.tableRow6);
- tab[5] = (TableRow) findViewById(R.id.tableRow7);
- tab[6] = (TableRow) findViewById(R.id.tableRow8);
- tab[7] = (TableRow) findViewById(R.id.tableRow9);
- tab[8] = (TableRow) findViewById(R.id.tableRow10);
- tab[9] = (TableRow) findViewById(R.id.tableRow11);
- tab[10] = (TableRow) findViewById(R.id.tableRow12);
- tab[11] = (TableRow) findViewById(R.id.tableRow13);
- tab[12] = (TableRow) findViewById(R.id.tableRow14);
- tab[13] = (TableRow) findViewById(R.id.tableRow15);
- sub[0] = (EditText) findViewById(R.id.subject1);
- sub[1] = (EditText) findViewById(R.id.subject2);
- sub[2] = (EditText) findViewById(R.id.subject3);
- sub[3] = (EditText) findViewById(R.id.subject4);
- sub[4] = (EditText) findViewById(R.id.subject5);
- sub[5] = (EditText) findViewById(R.id.subject6);
- sub[6] = (EditText) findViewById(R.id.subject7);
- sub[7] = (EditText) findViewById(R.id.subject8);
- sub[8] = (EditText) findViewById(R.id.subject9);
- sub[9] = (EditText) findViewById(R.id.subject10);
- sub[10] = (EditText) findViewById(R.id.subject11);
- sub[11] = (EditText) findViewById(R.id.subject12);
- sub[12] = (EditText) findViewById(R.id.subject13);
- sub[13] = (EditText) findViewById(R.id.subject14);
- cre[0] = (EditText) findViewById(R.id.credits1);
- cre[1] = (EditText) findViewById(R.id.credits2);
- cre[2] = (EditText) findViewById(R.id.credits3);
- cre[3] = (EditText) findViewById(R.id.credits4);
- cre[4] = (EditText) findViewById(R.id.credits5);
- cre[5] = (EditText) findViewById(R.id.credits6);
- cre[6] = (EditText) findViewById(R.id.credits7);
- cre[7] = (EditText) findViewById(R.id.credits8);
- cre[8] = (EditText) findViewById(R.id.credits9);
- cre[9] = (EditText) findViewById(R.id.credits10);
- cre[10] = (EditText) findViewById(R.id.credits11);
- cre[11] = (EditText) findViewById(R.id.credits12);
- cre[12] = (EditText) findViewById(R.id.credits13);
- cre[13] = (EditText) findViewById(R.id.credits14);
- if (dept.equalsIgnoreCase("cse")||dept.equalsIgnoreCase("mechtronics")||dept.equalsIgnoreCase("genetics")) {
- for(i=12;i<14;i++) {
- tab[i].setVisibility(View.GONE);
- }
- }
- else if (dept.equalsIgnoreCase("mech")||dept.equalsIgnoreCase("auto")) {
- for(i=10;i<14;i++) {
- tab[i].setVisibility(View.GONE);
- }
- }
- else if (dept.equalsIgnoreCase("ece")) {
- for(i=13;i<14;i++) {
- tab[i].setVisibility(View.GONE);
- }
- }
- else if (dept.equalsIgnoreCase("eee")||dept.equalsIgnoreCase("itc")) {
- for(i=11;i<14;i++) {
- tab[i].setVisibility(View.GONE);
- }
- }
- else if (dept.equalsIgnoreCase("it")) {
- for(i=9;i<14;i++) {
- tab[i].setVisibility(View.GONE);
- }
- }
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- TextView tv = (TextView) findViewById(R.id.gpa);
- num=0;
- den=0;
- f=0;
- if(dept.equalsIgnoreCase("cse")||dept.equalsIgnoreCase("mechtronics")||dept.equalsIgnoreCase("genetics")) {
- for(int i=0;i<12;i++) {
- s[i]=sub[i].getText().toString();
- g[i]=SetGP.setGP(s[i]);
- c[i]=Float.parseFloat(cre[i].getText().toString());
- if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- }
- for(i=0;i<12;i++) {
- num = CalcGPA.calcnum(g[i], c[i], num);
- den = CalcGPA.calcden(c[i], den);
- }
- }
- else if(dept.equalsIgnoreCase("mech")||dept.equalsIgnoreCase("auto")) {
- for(int i=0;i<10;i++) {
- s[i]=sub[i].getText().toString();
- g[i]=SetGP.setGP(s[i]);
- c[i]=Float.parseFloat(cre[i].getText().toString());
- if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- }
- for(i=0;i<10;i++) {
- num = CalcGPA.calcnum(g[i], c[i], num);
- den = CalcGPA.calcden(c[i], den);
- }
- }
- else if(dept.equalsIgnoreCase("ece")) {
- for(int i=0;i<13;i++) {
- s[i]=sub[i].getText().toString();
- g[i]=SetGP.setGP(s[i]);
- c[i]=Float.parseFloat(cre[i].getText().toString());
- if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- }
- for(i=0;i<13;i++) {
- num = CalcGPA.calcnum(g[i], c[i], num);
- den = CalcGPA.calcden(c[i], den);
- }
- }
- else if(dept.equalsIgnoreCase("eee")||dept.equalsIgnoreCase("itc")) {
- for(int i=0;i<11;i++) {
- s[i]=sub[i].getText().toString();
- g[i]=SetGP.setGP(s[i]);
- c[i]=Float.parseFloat(cre[i].getText().toString());
- if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- }
- for(i=0;i<11;i++) {
- num = CalcGPA.calcnum(g[i], c[i], num);
- den = CalcGPA.calcden(c[i], den);
- }
- }
- else if(dept.equalsIgnoreCase("it")) {
- for(int i=0;i<9;i++) {
- s[i]=sub[i].getText().toString();
- g[i]=SetGP.setGP(s[i]);
- c[i]=Float.parseFloat(cre[i].getText().toString());
- if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
- j=String.valueOf(i+1);
- Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
- f=1;
- break;
- }
- }
- for(i=0;i<9;i++) {
- num = CalcGPA.calcnum(g[i], c[i], num);
- den = CalcGPA.calcden(c[i], den);
- }
- }
- if(f==0) {
- gpa = CalcGPA.calc(num, den);
- tv.setText("Your GPA:- "+String.valueOf(gpa).toString());
- }
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- if(item.getItemId()==R.id.cgpa) {
- DialogCre.dialogCreate(con,acti);
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement