Skip to content

Instantly share code, notes, and snippets.

@Sabrejq
Created May 5, 2017 02:05
Show Gist options
  • Save Sabrejq/3ba651a3f6bf561ecc665dd87e9c7d18 to your computer and use it in GitHub Desktop.
Save Sabrejq/3ba651a3f6bf561ecc665dd87e9c7d18 to your computer and use it in GitHub Desktop.
Last HW. Three parallel arrays that hold 10 elements each
*Julio Quintero
* 5/4/2017
* Array project
*/
import java.util.*; // using util like always allows for the use of dialog boxes
import javax.swing.*; // Swing allows me to use frames and more app options
class ArrayExample
{
int studentID, averageGrade;
String lastName;
ArrayExample(int studentID,String lastName, int averageGrade){ // trying to use object oriented programing, still don't grasp the concept of it
this.studentID=studentID;
this.lastName=lastName;
this.averageGrade=averageGrade;
}
public int getstudentID(){
return studentID;
}
public String getlastName(){
return lastName;
}
public int getaverageGrade(){
return averageGrade;
}
/*I was trying to use more object programing but it got confusing, i understand how to create methods, but the used of "this" still confusing. I used examples from the web
*/
public static void main(String[] args)
{
ArrayList<ArrayExample> lista = new ArrayList<ArrayExample>(); // I'm calling the main method here
int idNumber[]=new int[10], averageGrade[]=new int[10];
String lastName[]=new String[10];
for(int j=0;j<idNumber.length;j++){
idNumber[j]=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter ID :")); // loops
}
for(int j=0;j<lastName.length;j++){
lastName[j]=JOptionPane.showInputDialog(null,"Enter Name :"); // loops
}
for(int j=0;j<averageGrade.length;j++){
averageGrade[j]=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Average :"));
}
for(int j=0;j<10;j++){
lista.add(new ArrayExample(idNumber[j],lastName[j],averageGrade[j]));
}
int inputID=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter ID to search:")); // new dialog box to search for any ID number
for(ArrayExample metodo:lista){
if (metodo.getstudentID()==inputID){
JOptionPane.showMessageDialog(null,"Name is: "+metodo.getlastName()+" and Average is: "+metodo.getaverageGrade());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment