SGPA Calculator for Android

package com.example.intent;

import android.R.id;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class IntentClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);


Bundle extras = getIntent().getExtras();
final int Value = extras.getInt("LatValue");
final int boxes=Value*2;
int loopvalue=boxes;



////// dynamic programming of User Interface
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll);

// setting Image header and footer for application

ImageView iv=new ImageView(this);
iv.setImageResource(R.drawable.android_animation);
iv.setBackgroundColor(2322);

// iv.setMaxWidth(BIND_AUTO_CREATE);
// iv.setMaxHeight(BIND_AUTO_CREATE);
ll.addView(iv);


// setting two label at top of second activity
TableLayout tb1=new TableLayout(this);
tb1.setOrientation(LinearLayout.VERTICAL);
TableRow tr1=new TableRow(this);
TextView tvv1=new TextView(this);
tvv1.setTextSize(20);
tvv1.setText(" Enter GPA ");
TextView tvv2=new TextView(this);
tvv2.setTextSize(20);
tvv2.setText(" Credit Hours ");
tr1.addView(tvv1);
tr1.addView(tvv2);
tb1.addView(tr1);
ll.addView(tb1);


final EditText et[] = new EditText[boxes];
Button b = new Button(this);
b.setText("button..");
// ll.addView(b);

// table layout
TableLayout tb=new TableLayout(this);
tb.setOrientation(LinearLayout.VERTICAL);
TableRow tr[]=new TableRow[Value+1];

for(int i = 0; i tr[i]=new TableRow(this);
tb.addView(tr[i]);
}
int y=0;
int x=0;
int z=0;
for(int i = 0; i et[i]=new EditText(this);
et[i].setInputType(InputType.TYPE_CLASS_NUMBER);
// et[i].setText("Allah");
et[i].setWidth(240);

if(z==2)
{
x++;
z=0;
}
tr[x].addView(et[i]);
z++;
y=i;
}
y++;
ll.addView(tb);


//
final TextView tvv=new TextView(this);

tvv.setTextSize(25);
tvv.setText("your GPA is ....");
//
Button bb = new Button(this);
bb.setText("Calculate GPA");
bb.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
gpaData();
}

private void gpaData() {
int s=0;
int c=0;
float data[] =new float[boxes];
float resCredit[]=new float[Value];
float SGPA= 0;
float tCreditHr = 0;

// TODO Auto-generated method stub
for(int i = 0; i data[i]= Float.valueOf(et[i].getText().toString());
if((i%2)==1)
{
//total credit hours
tCreditHr+=data[i];

}

}

/// calculating SGPA
for(int j=0; j {

SGPA+=data[j]*(data[j+1]/tCreditHr);
}
tvv.setText("Your GPA "+SGPA);

}
});

ll.addView(bb);
ll.addView(tvv);

/// setting footer of application
ImageView iv1=new ImageView(this);
iv1.setImageResource(R.drawable.anddroid_logo);

// iv.setMaxWidth(BIND_AUTO_CREATE);
// iv.setMaxHeight(BIND_AUTO_CREATE);
ll.addView(iv1);




///////////////////////////
this.setContentView(sv);
//////////////////


}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

Post a Comment

0 Comments