Advertisement
Guest User

activity

a guest
Mar 1st, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.14 KB | None | 0 0
  1. package com.package.calc;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.view.*;
  8. import android.widget.*;
  9.  
  10.  
  11.  
  12. public class Gpa extends Activity {
  13.  
  14.     Button b;
  15.     EditText cre[] = new EditText[14];
  16.     EditText sub[] = new EditText[14];
  17.     TableRow tab[] = new TableRow[14];
  18.     float num=0,den=0,gpa;
  19.     int f=0,i;
  20.     float c[] = new float[14];
  21.     float g[] = new float[14];
  22.     String j,dept;
  23.     String s[] = new String[14];
  24.     final Context con = this;
  25.     final Activity acti = this;
  26.  
  27.     @Override
  28.     protected void onCreate(Bundle savedInstanceState) {
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.main);
  31.  
  32.         Intent intent1 = getIntent();
  33.  
  34.         dept = intent1.getStringExtra("dept");
  35.  
  36.         b = (Button) findViewById(R.id.button2);
  37.  
  38.         tab[0] = (TableRow) findViewById(R.id.tableRow2);
  39.         tab[1] = (TableRow) findViewById(R.id.tableRow3);
  40.         tab[2] = (TableRow) findViewById(R.id.tableRow4);
  41.         tab[3] = (TableRow) findViewById(R.id.tableRow5);
  42.         tab[4] = (TableRow) findViewById(R.id.tableRow6);
  43.         tab[5] = (TableRow) findViewById(R.id.tableRow7);
  44.         tab[6] = (TableRow) findViewById(R.id.tableRow8);
  45.         tab[7] = (TableRow) findViewById(R.id.tableRow9);
  46.         tab[8] = (TableRow) findViewById(R.id.tableRow10);
  47.         tab[9] = (TableRow) findViewById(R.id.tableRow11);
  48.         tab[10] = (TableRow) findViewById(R.id.tableRow12);
  49.         tab[11] = (TableRow) findViewById(R.id.tableRow13);
  50.         tab[12] = (TableRow) findViewById(R.id.tableRow14);
  51.         tab[13] = (TableRow) findViewById(R.id.tableRow15);
  52.          
  53.         sub[0] = (EditText) findViewById(R.id.subject1);
  54.         sub[1] = (EditText) findViewById(R.id.subject2);
  55.         sub[2] = (EditText) findViewById(R.id.subject3);
  56.         sub[3] = (EditText) findViewById(R.id.subject4);
  57.         sub[4] = (EditText) findViewById(R.id.subject5);
  58.         sub[5] = (EditText) findViewById(R.id.subject6);
  59.         sub[6] = (EditText) findViewById(R.id.subject7);
  60.         sub[7] = (EditText) findViewById(R.id.subject8);
  61.         sub[8] = (EditText) findViewById(R.id.subject9);
  62.         sub[9] = (EditText) findViewById(R.id.subject10);
  63.         sub[10] = (EditText) findViewById(R.id.subject11);
  64.         sub[11] = (EditText) findViewById(R.id.subject12);
  65.         sub[12] = (EditText) findViewById(R.id.subject13);
  66.         sub[13] = (EditText) findViewById(R.id.subject14);
  67.          
  68.         cre[0] = (EditText) findViewById(R.id.credits1);
  69.         cre[1] = (EditText) findViewById(R.id.credits2);
  70.         cre[2] = (EditText) findViewById(R.id.credits3);
  71.         cre[3] = (EditText) findViewById(R.id.credits4);
  72.         cre[4] = (EditText) findViewById(R.id.credits5);
  73.         cre[5] = (EditText) findViewById(R.id.credits6);
  74.         cre[6] = (EditText) findViewById(R.id.credits7);
  75.         cre[7] = (EditText) findViewById(R.id.credits8);
  76.         cre[8] = (EditText) findViewById(R.id.credits9);
  77.         cre[9] = (EditText) findViewById(R.id.credits10);
  78.         cre[10] = (EditText) findViewById(R.id.credits11);
  79.         cre[11] = (EditText) findViewById(R.id.credits12);
  80.         cre[12] = (EditText) findViewById(R.id.credits13);
  81.         cre[13] = (EditText) findViewById(R.id.credits14);
  82.        
  83.         if (dept.equalsIgnoreCase("cse")||dept.equalsIgnoreCase("mechtronics")||dept.equalsIgnoreCase("genetics")) {
  84.             for(i=12;i<14;i++) {
  85.                 tab[i].setVisibility(View.GONE);
  86.             }
  87.         }
  88.         else if (dept.equalsIgnoreCase("mech")||dept.equalsIgnoreCase("auto")) {
  89.             for(i=10;i<14;i++) {
  90.                 tab[i].setVisibility(View.GONE);
  91.             }
  92.         }
  93.         else if (dept.equalsIgnoreCase("ece")) {
  94.             for(i=13;i<14;i++) {
  95.                 tab[i].setVisibility(View.GONE);
  96.             }
  97.         }
  98.         else if (dept.equalsIgnoreCase("eee")||dept.equalsIgnoreCase("itc")) {
  99.             for(i=11;i<14;i++) {
  100.                 tab[i].setVisibility(View.GONE);
  101.             }
  102.         }
  103.         else if (dept.equalsIgnoreCase("it")) {
  104.             for(i=9;i<14;i++) {
  105.                 tab[i].setVisibility(View.GONE);
  106.             }
  107.         }
  108.        
  109.         b.setOnClickListener(new View.OnClickListener() {
  110.  
  111.             @Override
  112.             public void onClick(View arg0) {
  113.                 // TODO Auto-generated method stub
  114.                 TextView tv = (TextView) findViewById(R.id.gpa);
  115.                 num=0;
  116.                 den=0;
  117.                 f=0;
  118.  
  119.                 if(dept.equalsIgnoreCase("cse")||dept.equalsIgnoreCase("mechtronics")||dept.equalsIgnoreCase("genetics")) {
  120.                     for(int i=0;i<12;i++) {
  121.                         s[i]=sub[i].getText().toString();
  122.                         g[i]=SetGP.setGP(s[i]);
  123.                         c[i]=Float.parseFloat(cre[i].getText().toString());
  124.                         if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
  125.                             j=String.valueOf(i+1);
  126.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
  127.                             f=1;
  128.                             break;
  129.                         }  
  130.                         else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
  131.                             j=String.valueOf(i+1);
  132.                             Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
  133.                             f=1;
  134.                             break;
  135.                         }
  136.                         else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
  137.                             j=String.valueOf(i+1);
  138.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
  139.                             f=1;
  140.                             break;
  141.                         }
  142.                     }
  143.  
  144.                     for(i=0;i<12;i++) {
  145.                         num = CalcGPA.calcnum(g[i], c[i], num);
  146.                         den = CalcGPA.calcden(c[i], den);
  147.                     }
  148.                 }
  149.  
  150.                 else if(dept.equalsIgnoreCase("mech")||dept.equalsIgnoreCase("auto")) {
  151.                     for(int i=0;i<10;i++) {
  152.                         s[i]=sub[i].getText().toString();
  153.                         g[i]=SetGP.setGP(s[i]);
  154.                         c[i]=Float.parseFloat(cre[i].getText().toString());
  155.                         if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
  156.                             j=String.valueOf(i+1);
  157.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
  158.                             f=1;
  159.                             break;
  160.                         }  
  161.                         else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
  162.                             j=String.valueOf(i+1);
  163.                             Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
  164.                             f=1;
  165.                             break;
  166.                         }
  167.                         else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
  168.                             j=String.valueOf(i+1);
  169.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
  170.                             f=1;
  171.                             break;
  172.                         }
  173.                     }
  174.  
  175.                     for(i=0;i<10;i++) {
  176.                         num = CalcGPA.calcnum(g[i], c[i], num);
  177.                         den = CalcGPA.calcden(c[i], den);
  178.                     }
  179.                 }
  180.  
  181.                 else if(dept.equalsIgnoreCase("ece")) {
  182.                     for(int i=0;i<13;i++) {
  183.                         s[i]=sub[i].getText().toString();
  184.                         g[i]=SetGP.setGP(s[i]);
  185.                         c[i]=Float.parseFloat(cre[i].getText().toString());
  186.                         if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
  187.                             j=String.valueOf(i+1);
  188.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
  189.                             f=1;
  190.                             break;
  191.                         }  
  192.                         else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
  193.                             j=String.valueOf(i+1);
  194.                             Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
  195.                             f=1;
  196.                             break;
  197.                         }
  198.                         else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
  199.                             j=String.valueOf(i+1);
  200.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
  201.                             f=1;
  202.                             break;
  203.                         }
  204.                     }
  205.  
  206.                     for(i=0;i<13;i++) {
  207.                         num = CalcGPA.calcnum(g[i], c[i], num);
  208.                         den = CalcGPA.calcden(c[i], den);
  209.                     }
  210.                 }
  211.  
  212.                 else if(dept.equalsIgnoreCase("eee")||dept.equalsIgnoreCase("itc")) {
  213.                     for(int i=0;i<11;i++) {
  214.                         s[i]=sub[i].getText().toString();
  215.                         g[i]=SetGP.setGP(s[i]);
  216.                         c[i]=Float.parseFloat(cre[i].getText().toString());
  217.                         if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
  218.                             j=String.valueOf(i+1);
  219.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
  220.                             f=1;
  221.                             break;
  222.                         }  
  223.                         else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
  224.                             j=String.valueOf(i+1);
  225.                             Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
  226.                             f=1;
  227.                             break;
  228.                         }
  229.                         else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
  230.                             j=String.valueOf(i+1);
  231.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
  232.                             f=1;
  233.                             break;
  234.                         }
  235.                     }
  236.  
  237.                     for(i=0;i<11;i++) {
  238.                         num = CalcGPA.calcnum(g[i], c[i], num);
  239.                         den = CalcGPA.calcden(c[i], den);
  240.                     }
  241.                 }
  242.  
  243.                 else if(dept.equalsIgnoreCase("it")) {
  244.                     for(int i=0;i<9;i++) {
  245.                         s[i]=sub[i].getText().toString();
  246.                         g[i]=SetGP.setGP(s[i]);
  247.                         c[i]=Float.parseFloat(cre[i].getText().toString());
  248.                         if((g[i]==-1)&&((c[i]>=1)&&(c[i]<=4))) {
  249.                             j=String.valueOf(i+1);
  250.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade For Subject "+j, Toast.LENGTH_LONG).show();
  251.                             f=1;
  252.                             break;
  253.                         }  
  254.                         else if((g[i]!=-1)&&((c[i]<1)||(c[i]>4))) {
  255.                             j=String.valueOf(i+1);
  256.                             Toast.makeText(Gpa.this, "Please Enter Valid Credits For Subject "+j, Toast.LENGTH_LONG).show();
  257.                             f=1;
  258.                             break;
  259.                         }
  260.                         else if((g[i]==-1)&&((c[i]<1)||(c[i]>4))) {
  261.                             j=String.valueOf(i+1);
  262.                             Toast.makeText(Gpa.this, "Please Enter Valid Grade and Credits For Subject "+j, Toast.LENGTH_LONG).show();
  263.                             f=1;
  264.                             break;
  265.                         }
  266.                     }
  267.  
  268.                     for(i=0;i<9;i++) {
  269.                         num = CalcGPA.calcnum(g[i], c[i], num);
  270.                         den = CalcGPA.calcden(c[i], den);
  271.                     }
  272.                 }
  273.  
  274.                 if(f==0) {
  275.                     gpa = CalcGPA.calc(num, den);
  276.                     tv.setText("Your GPA:- "+String.valueOf(gpa).toString());
  277.                 }
  278.             }
  279.         });
  280.        
  281.     }
  282.  
  283.     @Override
  284.     public boolean onCreateOptionsMenu(Menu menu) {
  285.         // Inflate the menu; this adds items to the action bar if it is present.
  286.         getMenuInflater().inflate(R.menu.main, menu);
  287.         return true;
  288.     }
  289.  
  290.     @Override
  291.     public boolean onOptionsItemSelected(MenuItem item) {
  292.         // TODO Auto-generated method stub
  293.  
  294.         if(item.getItemId()==R.id.cgpa) {
  295.             DialogCre.dialogCreate(con,acti);
  296.         }
  297.  
  298.         return true;
  299.     }
  300.  
  301. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement