// Lab 11 Exercise 4 // Programmer: Daniel Hunt // Editor(s) used: Win 7 JNotePad // Compiler(s) used: Java SE 6 // Description: This program builds a class with different types of data variables. It // prompts the user to import java.io.*; class Student { String name; String address; String city; String state; int zip; char gender; int id; float gpa; } public class Students { static void printResults(Student a[]) { // echo the results for(int i = 0; i < 3; i++) { System.out.println("Student's name: " + a[i].name); System.out.println("Student's address: " + a[i].address); System.out.println("Student's city: " + a[i].city); System.out.println("Student's state: " + a[i].state); System.out.println("Student's zip: " + a[i].zip); System.out.println("Student's gender: " + a[i].gender); System.out.println("Student's id: " + a[i].id); System.out.println("Student's gpa: " + a[i].gpa); } // for } static void askForInput(Student a[]) { BufferedReader cin; cin = new BufferedReader(new InputStreamReader(System.in)); int i; for(i = 0; i < 3; i++) { System.out.print("Student 1's name: "); a[0].name = cin.readLine(); System.out.print("Student 1's address: "); a[0].address = cin.readLine(); System.out.print("Student 1's city: "); a[0].city = cin.readLine(); System.out.print("Student 1's state: "); a[0].state = cin.readLine(); System.out.print("Student 1's zip: "); a[0].zip = new Double(cin.readLine()).intValue(); System.out.print("Student 1's gender [M/F]: "); a[0].gender = cin.readLine().charAt(0); System.out.print("Student 1's id: "); a[0].id = new Double(cin.readLine()).intValue(); System.out.print("Student 1's gpa: "); a[0].gpa = new Double(cin.readLine()).floatValue(); } // for } // askForInput public static void main(String[] argv) throws Exception { // stuff from exercise 2 // a[0].name = "Ann"; // a[1].name = "Bob"; // a[2].name = "Carl"; // declare and initialize array for Student class Student[] a = new Student[2]; for(int i = 0; i < a.length; i++) a[i] = new Student(); for(int i = 1; i < 4; i++) { askForInput(a[i]); printResults(a[i]); } } }