Ok, let me be more specific. The loop iterations must be five only and end
without a sentinel even though right now I have included a sentinel. Plus, I
cannot use a break.

So I was not able to see a syntax that would accomplish this (that's why I
threw in the sentinel)

Synopsis of the app (I have also included the source of the class with the
loop):

* prompt for each of 7 different inputs
* once they are input, display the results including a product of two of the
inputs
* return and begin a new prompt all over.

 public class AddBook // Modified to include requirement of positive num
entry for donations (amount of and number of)
 {
    // main method begins execution of java application

    public static void main( String args[] )
    {
      ArrayList persons = new ArrayList(); // Array to handle multiple
entries of persons
   boolean stop = false; // This flag will control whether we exit the loop
below
   // Loop until user types "stop" as the person's name:
   while (!stop)
       {
       // create scanner to obtain input from command window
       Scanner input = new Scanner ( System.in );
       System.out.println();  // a blank line
       System.out.print( "Please enter the persons name (First Last) or
'stop' to end program: " ); // prompt
       String perName = input.nextLine(); // read persons name

   if ( perName.compareTo("stop") == 0) // Check whether user indicated to
stop program
       {
       System.out.println( "Program ended." );
       stop = true;
       }
   else
       {
       // User did not indicate to stop, so continue reading info
       PersonData person;
       float donationNum; // first number, number of donations for the year
       float donationAmount; // second number, amount per donation (yeah I
know it doesn't allow for different amounts).
       String Address;
       String City;
       String State;

    System.out.print ( "Please enter the person's Address: " );
    Address = input.nextLine(); // Address validation and exception catch
needed

    System.out.print ( "Please enter the person's City: " );
    City = input.nextLine(); // City validation needed

    System.out.print ( "Please enter the person's State: " );
    State = input.nextLine(); // Validation for State needed

    String zip = "12345";

    //String zipCodePattern = "\\d{5}";
    System.out.print ( "Please enter the person's Zip in five number format
(88388): " );
    zip = input.nextLine();
    //while (zip != zipCodePattern) // my attempt at a zip validation, gave
me an infinite loop, will try again later
    //    {
    //    System.out.print( "The Zip code must be entered in the correct
format. " +
    //            "Please enter the Zip Code again: "); // Ask for correct
Zip entry
    //    System.out.println(zip.
matches(zipCodePattern));
    //    }

    System.out.print( "Please enter number of donations: " ); // prompt for
donation number
    donationNum = input.nextFloat();
    while (donationNum <= 0) // validate for positive number
        {
        System.out.print( "The number of donations must be a positive value.
" +
                "Please enter the number of donations again: " ); // prompt
for positive value for donations
        donationNum = input.nextFloat();
        }
    System.out.print( "Please enter donation amount: $" ); // prompt for
donation amount
    donationAmount = input.nextFloat();
    while (donationAmount <= 0) // validate for positive amount
        {
        System.out.print( "The donation amount must be a positive value. " +
                "Please enter the donation amount again: " ); // Prompt
again after invalid entry
        donationAmount = input.nextFloat();
        }

    person = new PersonData(perName, donationNum, donationAmount, Address,
City, State, zip); // fields included in our person entries
        //yearlyDonations = donationNum * donationAmount; // multiply
        System.out.print( person.getName() ); // display person's name
        System.out.println(); // my way (until I learn better) of formatting
the output to single lines from here down ->
        System.out.print( person.getAddress() );
        System.out.println();
        System.out.print( person.getCity() );
        System.out.println();
        System.out.print( person.getState() );
        System.out.printf( ", "); // prob a better way to get a comma
between the state and zip... I'm learning
        System.out.print( person.getZip() );
        System.out.println();
        System.out.print( person.getName() );
        System.out.printf( "'s yearly donations is: $%,.2f\n",
person.getYearlyDonations() );  // display yearly donations
        persons.add(person);
        }
       }
   } // end method main
} // end class AddBook
-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to