-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollegeInfo_menu.py
More file actions
160 lines (143 loc) · 6.94 KB
/
collegeInfo_menu.py
File metadata and controls
160 lines (143 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#Kylie Drawdy
#4 / 21 / 2024
# You will write a program that allows the user to keep track of college locations and details about each location.
#To begin you will create a College python class that keeps track of the college's unique id number, name, address,
#phone number, maximum students, and average tuition cost. Once you have built the College class, you will write a
#program that stores College objects in a dictionary while using the College's unique id number as the key.
#The program should display a menu in this order that lets the user:
#1) Add a new College
#2) Look up a College
#4) Delete an existing College
#5) Change an existing College's name, address, phone number, maximum guests, and average tuition cost.
#6) Exit the program
#Create college class
class College:
def __init__(self, idNumber, collegeName, collegeAddress, phoneNum, maxStudents, avgTuition):
#Initialize all objects
self.idNumber = idNumber
self.collegeName = collegeName
self.collegeAddress = collegeAddress
self.phoneNum = phoneNum
self.maxStudents = maxStudents
self.avgTuition = avgTuition
def __str__(self):
#Create string of objects in college class
return f"College ID: {self.idNumber}\nName: {self.collegeName}\nAddress: {self.collegeAddress}" \
f"\nPhone number: {self.phoneNum}\nMax Students: {self.maxStudents}\nAverage Tuition: {self.avgTuition}"
class infoSearch:
def __init__(self):
#create dictionary for storing college information
self.infoDict = {}
#Function to add colleges to dictionary
def addCollege(self, college):
#Add college to dictioary using college ID as key
self.infoDict[college.idNumber] = college
#Function to look up a college from dictionary
def collegeLookup(self, idNumber):
#Search for college id in dictionary
if idNumber in self.infoDict:
#Return info for that college ID
return self.infoDict[idNumber]
else:
print("ID number not found!")
#Function to delete collages
def delCollege(self, idNumber):
#Search for college id in dictionary
if idNumber in self.infoDict:
#Delete college if found
del self.infoDict[idNumber]
print("The college has been deleted.")
else:
print("College not found!")
#Function to update college information (set details with no info to "=None" to allow user to choose info to update)
def collegeUpdate(self, idNumber, collegeName=None, collegeAddress=None, phoneNum=None, maxStudents=None, avgTuition=None):
#Search for information number in dictionary
if idNumber in self.infoDict:
theCollege = self.infoDict[idNumber]
if collegeName is not None:
theCollege.collegeName = collegeName
if collegeAddress is not None:
theCollege.collegeAddress = collegeAddress
if phoneNum is not None:
theCollege.phoneNum = phoneNum
if maxStudents is not None:
theCollege.maxStudents = maxStudents
if avgTuition is not None:
theCollege.avgTuition = avgTuition
print("College Information Successfully updated.")
else:
print("College not found!")
#Function to show the menu
def showMenu(self):
#Print out menu options
print("1) Add a new College")
print("2) Look up a College")
print("3) Delete an existing College")
print("4) Change an existing College's Information")
print("5) Exit the program")
#Define main function
def main():
#call infoSearch to use info from class
collegeInfoSearch = infoSearch()
while True:
#Display menu
collegeInfoSearch.showMenu()
#Create input for user menu choice
userChoice = input("Please Enter Your Choice: ")
#Add a new college choice 1
if userChoice == '1':
#Display options for info to add new college
idNumber = input("Enter College ID: ")
collegeName = input("Enter Name of College: ")
collegeAddress = input("Enter College Address: ")
phoneNum = input("Enter College Phone Number: ")
maxStudents = input("Enter Max Number of Students: ")
avgTuition = input("Enter Average Tuition: ")
#Add info for the new college through the college class
newCollege = College(idNumber, collegeName, collegeAddress, phoneNum, maxStudents, avgTuition)
#Add new college using addcollege function in infoSearch class
collegeInfoSearch.addCollege(newCollege)
print("College added successfully!")
#Add college lookup choice 2
elif userChoice == '2':
#Get user input of college id
idNumber = input("Please Enter College ID to look up: ")
#Lookup id number using the collegeLookup function in the infoSearch class
theCollege = collegeInfoSearch.collegeLookup(idNumber)
#Verify if college is in dictionary to user
if theCollege:
print(theCollege)
else:
print("College not found!")
#Add college delete choice 3
elif userChoice == '3':
#Get user input for which college to delete
idNumber = input("Enter ID of College To Delete: ")
#Delete college using delCollege function in infoSearch class
collegeInfoSearch.delCollege(idNumber)
print("College deleted successfully!")
#Add college update choice 4
elif userChoice == '4':
#Get user input of college ID
idNumber = input("Please Enter College ID to Update: ")
collegeName = input("Enter New Name (If information does not need updating, please leave blank): ")
collegeAddress = input("Enter New Address (If information does not need updating, please leave blank): ")
phoneNum = input("Enter New Phone Number (If information does not need updating, please leave blank): ")
maxStudents = input("Enter New Max Students (If information does not need updating, please leave blank): ")
#Change max student to integer to avoid error
if maxStudents:
maxStudents = int(maxStudents)
avgTuition = input("Enter New Average Tuition (If information does not need updating, please leave blank): ")
#Change average tuition to float to avoid error
if avgTuition:
avgTuition = float(avgTuition)
collegeInfoSearch.collegeUpdate(idNumber, collegeName, collegeAddress, phoneNum, maxStudents, avgTuition)
#Add exit program choice 5
elif userChoice == '5':
print("Exiting Program.")
#use break to exit program
break
else:
print("Invalid Choice. Please Try Again!")
#Call main
main()