129 lines
3.7 KiB
Python
129 lines
3.7 KiB
Python
# Allow for generic person --
|
|
# add student class --
|
|
# be able to save results to a file
|
|
# write the display to a file, use append instead of write
|
|
|
|
|
|
def write_file(line):
|
|
#add write block
|
|
with open("data.txt", 'a') as output_file:
|
|
output_file.write(line)
|
|
output_file.write("\n")
|
|
|
|
class Person:
|
|
def __init__(self, firstName, lastName, email):
|
|
self.firstName = firstName
|
|
self.lastName = lastName
|
|
self.email = email
|
|
|
|
def getFullName(self):
|
|
return self.firstName + " " + self.lastName
|
|
|
|
class Customer(Person):
|
|
def __init__(self, firstName, lastName, email, number):
|
|
Person.__init__(self, firstName, lastName, email)
|
|
self.number = number
|
|
|
|
class Employee(Person):
|
|
def __init__(self, firstName, lastName, email, ssn):
|
|
Person.__init__(self, firstName, lastName, email)
|
|
self.ssn = ssn
|
|
#Adding Student
|
|
class Student(Person):
|
|
def __init__(self, firstName, lastName, email, gpa):
|
|
Person.__init__(self, firstName, email, gpa)
|
|
self.gpa = gpa
|
|
|
|
def main():
|
|
print("Customer/Employee Data Entry")
|
|
print()
|
|
|
|
while True:
|
|
choice = input("Customer, Employee, Student, or Other? (c/e/s/o): ")
|
|
print()
|
|
|
|
if choice == 'c':
|
|
customer = get_input(choice)
|
|
print()
|
|
display(customer)
|
|
elif choice == 'e':
|
|
employee = get_input(choice)
|
|
print()
|
|
display(employee)
|
|
elif choice == 's':
|
|
student = get_input(choice)
|
|
print()
|
|
display(student)
|
|
elif choice == 'o':
|
|
other = get_input(choice)
|
|
print()
|
|
display(other)
|
|
else:
|
|
print("Invalid choice. Please try again.")
|
|
continue
|
|
|
|
again = input("Continue? (y/n): ").lower()
|
|
print()
|
|
if again != "y":
|
|
break
|
|
|
|
print("Bye!")
|
|
|
|
def get_input(choice):
|
|
print("DATA ENTRY")
|
|
first_name = input("First name: ")
|
|
last_name = input("Last name: ")
|
|
email = input("Email: ")
|
|
if choice == 'c':
|
|
number = input("Number: ")
|
|
customer = Customer(first_name, last_name, email, number)
|
|
return customer
|
|
elif choice == 'e':
|
|
ssn = input("SSN: ")
|
|
employee = Employee(first_name, last_name, email, ssn)
|
|
return employee
|
|
elif choice == 's':
|
|
gpa = input("GPA: ")
|
|
student = Student(first_name, last_name, email, gpa)
|
|
return student
|
|
elif choice == 'o':
|
|
other = Person(first_name, last_name, email)
|
|
return other
|
|
|
|
def display(person):
|
|
if isinstance(person, Customer):
|
|
print("CUSTOMER")
|
|
write_file("CUSTOMER")
|
|
elif isinstance(person, Employee):
|
|
print("EMPLOYEE")
|
|
write_file("EMPLOYEE")
|
|
elif isinstance(person, Student):
|
|
print("STUDENT")
|
|
write_file("STUDENT")
|
|
else:
|
|
print("Other")
|
|
write_file("Other")
|
|
|
|
print("First name: " + person.firstName)
|
|
print("Last name: " + person.lastName)
|
|
print("Email: " + person.email)
|
|
|
|
#Write generic contents to file
|
|
write_file("First name: " + person.firstName)
|
|
write_file("Last name: " + person.lastName)
|
|
write_file("Email: " + person.email)
|
|
|
|
if isinstance(person, Customer):
|
|
print("Number: " + person.number)
|
|
write_file("Number: " + person.number)
|
|
|
|
elif isinstance(person, Employee):
|
|
print("SSN: " + person.ssn)
|
|
write_file("SSN: " + person.ssn)
|
|
elif isinstance(person, Student):
|
|
print("GPA: " + person.gpa)
|
|
write_file("GPA: " + person.gpa)
|
|
write_file("")
|
|
|
|
print()
|