I would like to use some variables that I created in my MainActivity class in my CollegeList class. I tried looking through the Internet for an answer but I still am not sure what to do.
MainActivity class:
double scoreDouble;
TextView score;
EditText gpa;
EditText sat;
EditText act;
Button calc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gpa = (EditText) findViewById(R.id.gpa);
sat = (EditText) findViewById(R.id.sat);
act = (EditText) findViewById(R.id.act);
score = (TextView) findViewById(R.id.score);
calc = (Button) findViewById(R.id.calc);
calc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String gpaString = gpa.getText().toString();
if (gpaString.equals("")) {
gpaString = "0";
}
double gpaDouble = Double.parseDouble(gpaString);
String satString = sat.getText().toString();
if (satString.equals("")) {
satString = "0";
}
int satInt = Integer.parseInt(satString);
String actString = act.getText().toString();
if (actString.equals("")) {
actString = "0";
}
int actInt = Integer.parseInt(actString);
if (actInt / 36.0 < satInt / 2400.0) {
scoreDouble = (0.6 * gpaDouble * 25)
+ (0.4 * ((double) satInt / 2400.0) * 100.0);
} else {
scoreDouble = (0.6 * gpaDouble * 25)
+ (0.4 * ((double) actInt / 36.0) * 100.0);
}
}
}
);
}
}
CollegeList class:
public class CollegeList extends ListActivity {
String[] colleges = new String[100];
private double gpa;
private int act;
private int sat;
private String name;
private String location;
private double score;
public CollegeList(double gpa, int act, int sat, String name, String location){
this.gpa = gpa;
this.act = act;
this.sat = sat;
this.name = name;
this.location = location;
if(act/36.0>sat/2400.0){
score = 0.6*gpa*25.0+0.4*(act/36.0)*100.0;
}else{
score = 0.6*gpa*25.0+0.4*(sat/2400.0)*100.0;
}
}
public double getGpa(){
return this.gpa;
}
public int getAct(){
return this.act;
}
public int getSat(){
return this.sat;
}
public String getName(){
return this.name;
}
public String getLocation(){
return this.location;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(CollegeList.this, android.R.layout.simple_list_item_1, colleges));
}
}
For example, I would like to use the scoreDouble from the first class in the second class, but I am unsure how to do this.