Homework on Ruby Programming - (15Points Spies ,youwanttoassigna\"spy\" samelastname.Youdon'( spying Input Afileyouwil

Homework on Ruby Programming - (15Points Spies...

This preview shows page 1 out of 2 pages.

Unformatted text preview: CS 4700 Program 2 Ruby Programming (15 Points) Spies For each person in your group, you want to assign a "spy" such that no one spies on themselves or someone with the same last name. You don't want a person to spy on someone who is also spying on them (as they may discover the spying). Input: A file you will name "people.txt" of the form: Luke Skywalker <[email protected]> Leia Skywalker <[email protected]> John Wayne <[email protected]> Clark Kent <[email protected]> Lois Ken <[email protected]> Pop Eye <[email protected]> Private Eye <[email protected]> Robotic Eye <[email protected]> Vicki Allan <[email protected]> Joe Allan <[email protected]> Terrance Allan <[email protected]> Philip Allan <[email protected]> Assume all names have one first name and one last name. Verify that the form of the email address follows expected rules. A bad email address will be replaced with "BAD EMAIL", but otherwise used. You are to print out a list of spy assignments Rules for email address: 1. Exactly one '@' sign between local‐part and domain‐part. 2. Character "." may not be first or last character of either local‐part or domain‐part. 3. Character "." cannot appear two or more times consecutively (e.g. [email protected]) 4. Only the following characters are allowed: a. Uppercase and lowercase English letters (a–z, A–Z) b. Digits 0 to 9 c. Characters ! # $ % & ' * + ‐ / = ? ^ _ ` { | } ~ Output of the form: Person Luke Skywalker at <[email protected]> spies on Person Philip Allan at <[email protected]> Person Leia Skywalker at <[email protected]> spies on Person Vicki Allan at <[email protected]> Person John Wayne at <[email protected]> spies on Person Leia Skywalker at <[email protected]> Person Clark Kent at <BAD EMAIL> spies on Person Robotic Eye at <[email protected]> Person Lois Ken at <[email protected]> spies on Person Pop Eye at <[email protected]> Person Pop Eye at <[email protected]> spies on Person Joe Allan at <[email protected]> Person Private Eye at <[email protected]> spies on Person Clark Kent at < BAD EMAIL > Person Robotic Eye at <[email protected]> spies on Person Terrance Allan at <[email protected]> Person Vicki Allan at <[email protected]> spies on Person John Wayne at <[email protected]> Person Joe Allan at <[email protected]> spies on Person Luke Skywalker at <[email protected]> Person Terrance Allan at <[email protected]> spies on Person Private Eye at <[email protected]> Person Philip Allan at <[email protected]> spies on Person Lois Ken at <[email protected]> Things to try: 1. Create a class People. Use to_s to convert a person to a string. 2. Create an array of class People. 3. You can randomly arrange an array by using sort_by { rand} @spy= @persons.sort_by{ rand} 4. @spy = @persons.dup Duplicates an array 5. Use regular expressions 6. You can assign multiple things at a time (and even swap values) def initialize(first, family, mail) @first, @family, @mail = first, family, mail end ...
View Full Document

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture