/** * We will learn various methods for doing input. Some of you * (in fact all of you) have used the Console class in CS1. * Here we learn something a little different (and much more fun): * JOptionPane. JOptionPane has several methods we will need: * * showInputDialog(String)- for input * showMessageDialog(String)- for output * showConfirmDialog(String)- for Yes/No dialog * * showInputDialog ALWAYS returns a String!! Thus, for numeric input, * the appropriate method must be called to CONVERT the String to * the appropriate value: * Byte.parseByte(String) * Short.parseShort(String) * Integer.parseInt(String) * Long.parseLong(String) * Float.parseFloat(String) * Double.parseDouble(String) */ import javax.swing.JOptionPane; // IMPORTANT You need this line public class UseStudentIO { public static void main(String[] args) { String first,last,tempID; int ID; int i; Student s; while(true) { first=JOptionPane.showInputDialog("Enter first name "); last=JOptionPane.showInputDialog("Enter last name "); tempID=JOptionPane.showInputDialog("Enter ID "); ID=Integer.parseInt(tempID); s=new Student(first,last,ID); System.out.println(s); System.out.println("Count is "+Student.getCount()); } } }