public static void createNewAdvertiser creating new advertiser option c in

Public static void createnewadvertiser creating new

This preview shows page 8 - 12 out of 17 pages.

*/ public static void createNewAdvertiser() // creating new advertiser (option c in assignemnt) { String name, username = null, password, advert; char gender, partGender; int age, minAge, maxAge; double income = 0.0, minInc = 0.0, maxInc = 0.0; String regex = "^[^-\\s][a-zA-Z]+$"; System.out.println("Creating new Advertiser. Please fill in the following information."); do
Image of page 8
{ System.out.print("Name: "); //user's name name = kb.next(); if(!name.matches(regex)) // ensure no numbers and special characters in name { System.out.println("Invalid name!"); } else { break; } }while(true); boolean b = true; while(b) { System.out.print("Username: "); // user enters username = kb.next(); if(!checkDuplicateUsername(username)) // check if username is duplicated and prompt for error { b = false; } if(!b) { kb.nextLine(); break; } } System.out.print("Password: "); // user enters password for account password = kb.nextLine(); System.out.println("Enter your advert: "); // user's advert advert = kb.nextLine(); do { System.out.print("Gender(M/F): "); // user enters own gender gender = kb.next().charAt(0); gender = Character.toUpperCase(gender); if(gender != 'M' && gender !='F') //condition for gender male or female { System.out.println("Invalid gender! Please re-enter!"); } else break; }while(true); do { System.out.print("Age: "); // user enter's own age while(!kb.hasNextInt()) { System.out.println("Invalid age! Please re-enter!"); System.out.print("Age: "); kb.next(); } age = kb.nextInt(); if(age < 10 || age > 99) // condition for age
Image of page 9
{ System.out.println("Invalid age! Please re-enter!"); } else break; }while(true); do { System.out.print("Income: "); // user enter own income while(!kb.hasNextDouble()) { System.out.println("Invalid income! Please re-enter!"); System.out.print("Income: "); kb.next(); } income = kb.nextDouble(); if(income < 0 ) { System.out.println("Invalid income! Please re-enter!"); } else break; }while(true); do { System.out.print("Partner's gender(M/F): "); partGender = kb.next().charAt(0); partGender = Character.toUpperCase(partGender); if(partGender != 'M' && partGender !='F') //condition for gender { System.out.println("Invalid gender! Please re-enter!"); } else break; }while(true); do { System.out.print("Partner's preferred minimum age: "); // user enter partner's min age while(!kb.hasNextInt()) { System.out.println("Invalid age! Please re-enter!"); System.out.print("Partner's preferred minimum age: "); kb.next(); } minAge = kb.nextInt(); if(minAge < 10 || minAge > 99) // condition for partner's age { System.out.println("Invalid age! Please re-enter a valid age!"); } else break; }while(true); do { System.out.print("Partner's preferred maximum age: "); // user enter partner's max age while(!kb.hasNextInt())
Image of page 10
{ System.out.println("Invalid age! Please re-enter!"); System.out.print("Partner's preferred maximum age: "); kb.next(); } maxAge = kb.nextInt(); if(maxAge < minAge || maxAge > 99) // condition for partner's max age { System.out.println("Invalid age! Please re-enter a valid age!"); } else break; }while(true); do { System.out.print("Partner's preferred minumum income: "); // user enter partner's min income while(!kb.hasNextDouble()) { System.out.println("Invalid income! Please re-enter!"); System.out.print("Partner's preferred minumum income: "); kb.next(); } minInc = kb.nextDouble(); if(minInc < 0 ) { System.out.println("Invalid income! Please re-enter!"); } else break; }while(true); do { System.out.print("Partner's preferred maximum income: "); // user enter partner's max income if(!kb.hasNextDouble()) { System.out.println("Invalid income! Please re-enter!"); System.out.print("Partner's preferred maximum income: ");
Image of page 11
Image of page 12

You've reached the end of your free preview.

Want to read all 17 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture