View Single Post
  #16 (permalink)  
Old 05-06-2008, 04:27 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import javax.swing.JOptionPane; public class PC { public static void main(String[] args){ DataAcquisition dataAcqn = new DataAcquisition(); // Create one PersonData: String[] data = dataAcqn.getData(); ProjectDefinition person = new ProjectDefinition(data); System.out.println("person = " + person); } } class DataAcquisition { public String[] getData() { String userInput = JOptionPane.showInputDialog(null, "Please enter the following information with " + "a space inbetween each:\n\n" + "First Name:\n" + "Last Name:\n" + "Phone Number:\n" + "Rolls of Film:\n" + "Number of Prints:"); String[] data = userInput.split("\\s"); validateData(data); return data; } /** * a. The name of the customer is not blank * b. The phone number of the customer is not blank and * doesn’t exceed 10 characters and is an integer * with positive number only * c. The number of rolls is between 1 and 100 and is an * positive integer * d. The number of prints can only be (1,2,8,10, 25,30,50), * positive integer */ private void validateData(String[] data) { String first = data[0]; String last = data[1]; String phone = data[2]; String film = data[3]; String prints = data[4]; try { if(first.length() == 0 || last.length() == 0) throw new IllegalArgumentException("names must not be blank"); // validate each of the four things listed above... } catch(IllegalArgumentException e) { System.out.println("Illegal Argument: " + e.getMessage()); System.exit(1); } } } class ProjectDefinition { String userNameFirst; String userNameLast; String userPhone; String userFilm; String userPrints; final int USER_EXPOSURES = 1; public ProjectDefinition(String[] data) { this.userNameFirst = data[0]; this.userNameLast = data[1]; userPhone = data[2]; userFilm = data[3]; userPrints = data[4]; } public String toString() { return "First Name:" + " " + userNameFirst + " " + "Last Name:" + " " + userNameLast + " " + "Phone Number:" + " " + userPhone + " " + "Rolls of Film:" + " " + userFilm + " " + "Number of Prints:" + " " + userPrints; } }
Reply With Quote