// 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 Students { String name; String address; String city; String state; int zip; char gender; int id; float gpa; } public class StudentTest { static void printResults(int record) { // echo the results System.out.println("Student's name: " + a[record].name); System.out.println("Student's address: " + a[record].address); System.out.println("Student's city: " + a[record].city); System.out.println("Student's state: " + a[record].state); System.out.println("Student's zip: " + a[record].zip); System.out.println("Student's gender: " + a[record].gender); System.out.println("Student's id: " + a[record].id); System.out.println("Student's gpa: " + a[record].gpa); } static void askForInput(int record) { BufferedReader cin; cin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Student 1's name: "); a[record].name = cin.readLine(); System.out.print("Student 1's address: "); a[record].address = cin.readLine(); System.out.print("Student 1's city: "); a[record].city = cin.readLine(); System.out.print("Student 1's state: "); a[record].state = cin.readLine(); System.out.print("Student 1's zip: "); a[record].zip = new Double(cin.readLine()).intValue(); System.out.print("Student 1's gender [M/F]: "); a[record].gender = cin.readLine().charAt(0); System.out.print("Student 1's id: "); a[record].id = new Double(cin.readLine()).intValue(); System.out.print("Student 1's gpa: "); a[record].gpa = new Double(cin.readLine()).floatValue(); } // askForInput public static void main(String[] argv) throws Exception { // declare and initialize array for Student class Student[] a = new Student[3]; for(int i = 0; i < a.length; i++) a[i] = new Student(); for(int i = 0; i < 3; i++) { askForInput(i); printResults(i); } } }