Skip to content

Instantly share code, notes, and snippets.

@saintmedusa
Last active January 31, 2020 03:46
Show Gist options
  • Save saintmedusa/f72331d034234026fb40f45d5ce61a29 to your computer and use it in GitHub Desktop.
Save saintmedusa/f72331d034234026fb40f45d5ce61a29 to your computer and use it in GitHub Desktop.
input_choice = nil
full_names = Array.new
id_nums = Array.new
emails = Array.new
# Introduce Program to user, select manual or file mode, and
# initiate the array of full_names accordingly.
puts "Welcome to Ada's Student Account Generator."
puts "Would you like to enter student names manually or by file?
Enter 'M' for manually or 'F' for file:"
input_choice = gets.chomp.upcase()
if input_choice == "F"
puts "What is the name of your text file, extension included?
Note: make sure your text file has no trailing empty lines."
file_name = gets.chomp
full_names = File.readlines(file_name)
end
if input_choice == "M"
puts "How many names will you enter?"
full_names = Array.new(gets.chomp.to_i)
end
# Times loop to get student names (if entering manually), create
# ID numbers, and generate student emails
(full_names.length).times do |i|
# finalize full_names
if input_choice == "M"
puts "enter student name:"
full_names[i] = gets.chomp.upcase()
else
full_names[i] = full_names[i].chomp.upcase()
end
# generate ID #
id_nums[i] = rand(111111..999999)
until id_nums.length == id_nums.uniq.length
id_nums[i] = rand(111111..999999)
end
# generate email
fnl_names = full_names[i].split(" ")
f_initial = fnl_names[0][0,1]
if fnl_names.length > 2
f_initial << fnl_names[1][0,1]
end
emails[i] = f_initial + fnl_names.last + id_nums[i].to_s[3,5] + "@adadevelopersacademy.org"
end
# Print all students' generated account info
(full_names.length).times do |i|
puts full_names[i] + ": ID - " + id_nums[i].to_s + ", email - " + emails[i] + "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment