// Class deifintion
public class College{
// Variable definitions, necessary to then call this.location etc. We define the strings as private, meaning things outside of the class cannot access them
private String location;
private String acceptRate;
private String avgGPA;
private String avgSAT;
// constructor, method first run when the object is created. Defines all of the variables. It also must be the same name as the class or you'll get an error for not having a return type.
public College(String location, String acceptRate, String avgGPA, String avgSAT){
this.location = location;
this.acceptRate = acceptRate;
this.avgGPA = avgGPA;
this.avgSAT = avgSAT;
}
// Various getter methods. Necessary since we defined the strings as private
public String getLocation(){
return this.location;
}
public String getAcceptRate(){
return this.acceptRate;
}
public String getAvgGPA(){
return this.avgGPA;
}
public String getAvgSAT(){
return this.avgSAT;
}
}
// main class
public class Main {
// main method
public static void main(String[] args) {
// object initialization. Uses the format : ClassName varName = new ConstructorName
College college1 = new College("Boston", "4.1%", "4.17", "1535");
College college2 = new College("California", "3.9%", "4.19", "1545");
System.out.println(college1.getLocation());
System.out.println(college2.getAvgGPA());
}
}
//Ijava running main class and method
Main.main(null);