outprintPartners preferred maximum income kbnext maxInc kbnextDouble ifmaxInc 0

Outprintpartners preferred maximum income kbnext

This preview shows page 11 - 15 out of 17 pages.

System.out.print("Partner's preferred maximum income: "); kb.next(); } maxInc = kb.nextDouble(); if(maxInc < 0 ) { System.out.println("Invalid income! Please re-enter!"); } else break; }while(true); Advertiser newAdv = new Advertiser(name, username, password, age, income, gender, advert, partGender, minAge, maxAge, minInc, maxInc); advList.add(newAdv); System.out.println("Account created successfully!\n"); checkAdvLogin(username, password); } /** * Method to create a new responder. It will prompt users to enter the relevant
Image of page 11
* information and prompt if an error occurs. For values like age, assumption is made * that users under age 10 and above 99 are unable to sign up. */ public static void createNewResponder() { String name, username = null, password; char gender; int age; double income = 0.0; String regex = "^[^-\\s][a-zA-Z\\s]+$"; System.out.println("Creating new Responder. Please fill in the following information."); do { 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!"); name = kb.nextLine(); } else { break; } }while(true); boolean b = true; while(b) { System.out.print("Username: "); // user enters username for account username = kb.next(); if(!checkDuplicateUsername(username)) { b = false; } } // check if username is duplicated and prompt for error System.out.print("Password: "); // user enters password for account password = kb.next(); 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()) {
Image of page 12
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 { System.out.println("Invalid age! Please re-enter a valid age!"); } else break; }while(true); do { System.out.print("Income: "); // user enter own income if(!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); Responder newRes = new Responder(name, username, password, age, income, gender); resList.add(newRes); System.out.println("Account created successfully!\n"); menu(); } /** * Method to match certain values from the responder to the advertiser in order to * be able to select an appropriate advertiser. It compares the gender, age and income. */ public static void getMatches() { boolean empty = true; if(!advList.isEmpty()) { int count = 1; for(int i=0; i<advList.size(); i++) { if(respondeR.getGender()== advList.get(i).getPartGender()) { if(respondeR.getAge() >= advList.get(i).getMinAge() && respondeR.getAge() <= advList.get(i).getMaxAge()) { if(respondeR.getIncome() >= advList.get(i).getMinInc() && respondeR.getIncome() <= advList.get(i).getMaxInc()) { System.out.println(count+ "." + "Username: " + advList.get(i).getUserName() + "\nDescription: " + advList.get(i).getTextAdv() +"\n");
Image of page 13
count ++; } } } } } else { System.out.println("No matches!\n"); } if(!empty) { System.out.println("No matches!\n"); } } /** * Method to allow responder to reply advertiser.
Image of page 14
Image of page 15

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