Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- //: Playground - noun: a place where people can play
- import UIKit
- public class Users{
- public let username: String
- public var password: String
- public var name: String?
- public var surname : String?
- public var city: String?
- public let email: String
- public init(username:String,password:String,email:String){
- self.username = username
- self.password = password
- self.email = email
- }
- public func setUsername(newUsername: String){
- //You can't change username of already exist user.
- }
- public func getUsername()->String {
- return username
- }
- public func setPassw(newPassword: String){
- self.password = newPassword
- }
- public func getPassw()->String{
- return password
- }
- public func changePassword(usernam: String,oldPw: String,newPw: String){
- self.password = newPw
- }
- public func printAll(){
- print("Name : \(name!) \nSurname : \(surname!) \nCity : \(city!)")
- }
- }
- public class Databases {
- public var users : [Users] = []
- public var events: [Event] = []
- public var versione: Float = 1.0
- public func signup(user: String,pw : String , eMail: String){
- users.append(Users(username: user,password: pw,email : eMail))
- print("Utente registrato con successo")
- }
- public func login(usernam: String,password : String)->Users{
- var flag : Users? = nil
- for user in users {
- if usernam == user.getUsername() && password == user.getPassw() {
- print("Utente Loggato")
- flag = user
- }
- }
- return flag!
- }
- public func changePassword(usernam: String,oldPw: String,newPw: String){
- for user in users {
- if usernam == user.getUsername() {
- if oldPw == user.getPassw(){
- user.setPassw(newPassword: newPw)
- print("Password Changed!")
- }
- else{
- print("Actual Password Is Wrong!")
- }
- }
- }
- }
- }
- public class Event {
- public var name: String
- public var date: String
- public var position: String
- public var type: String
- public var duration: Int?
- public init(name: String,date:String,position:String,type: String){
- self.name = name
- self.date = date
- self.position = position
- self.type = type
- }
- public func changePlace (position: String){
- self.position = position
- }
- public func changeName (name: String){
- self.name = name
- }
- }
- public class Film:Event {
- public var event: [Event] = []
- public init(){
- super.init(name: "", date: "", position: "", type: "")
- }
- public func addEvent(name: String,date: String,position: String,type:String,duration: Int){
- event.append(Event(name: name, date: date, position: position,type: type))
- changeDuration(name: name, duration: duration)
- }
- public func changeDuration(name:String,duration: Int){
- for nome in event {
- if name == nome.name {
- nome.duration = duration
- }
- }
- }
- public func printAllEvent(){
- print("\nFilm Events :\n")
- for eventi in event{
- if eventi.duration != nil {
- print("Film : \(eventi.name) at \(eventi.position) on date : \(eventi.date) duration : \(eventi.duration!)")
- }
- else {
- print("Film : \(eventi.name) at \(eventi.position) on date : \(eventi.date) duration : not specified")
- }
- }
- }
- }
- var myDatabase = Databases()
- myDatabase.signup(user: "Francisco", pw: "ligh21@asd", eMail: "francisco.franco@ty.com")
- var user1 = myDatabase.login(usernam: "Francisco", password: "ligh21@asd")
- user1.name = "Francisco"
- user1.surname = "Franco"
- user1.city = "Napoli"
- user1.printAll()
- var cinemaEvents = Film()
- cinemaEvents.addEvent(name: "Pit the clown",date: "11-11-2017",position: "Med Maxi Cinema",type:"Horror",duration: 103)
- cinemaEvents.addEvent(name: "I Love Unicorn", date: "12-11-2017", position: "Modernissimo", type: "Animation",duration: 112)
- cinemaEvents.printAllEvent()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement