diff --git a/FinalExam1.1.xcodeproj/project.pbxproj b/FinalExam1.1.xcodeproj/project.pbxproj index f09407e..8c1c91f 100644 --- a/FinalExam1.1.xcodeproj/project.pbxproj +++ b/FinalExam1.1.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 8A92494E21C17F8000E3552A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8A92494C21C17F8000E3552A /* Main.storyboard */; }; 8A92495021C17F8100E3552A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8A92494F21C17F8100E3552A /* Assets.xcassets */; }; 8A92495321C17F8100E3552A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8A92495121C17F8100E3552A /* LaunchScreen.storyboard */; }; + 8AF540E821C1889E0022B072 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8AF540E721C1889E0022B072 /* Assets.xcassets */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -22,6 +23,7 @@ 8A92494F21C17F8100E3552A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8A92495221C17F8100E3552A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 8A92495421C17F8100E3552A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8AF540E721C1889E0022B072 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ../../Elements/Assets.xcassets; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,6 +56,7 @@ 8A92494721C17F8000E3552A /* FinalExam1.1 */ = { isa = PBXGroup; children = ( + 8AF540E721C1889E0022B072 /* Assets.xcassets */, 8A92494821C17F8000E3552A /* AppDelegate.swift */, 8A92494A21C17F8000E3552A /* ViewController.swift */, 8A92494C21C17F8000E3552A /* Main.storyboard */, @@ -124,6 +127,7 @@ files = ( 8A92495321C17F8100E3552A /* LaunchScreen.storyboard in Resources */, 8A92495021C17F8100E3552A /* Assets.xcassets in Resources */, + 8AF540E821C1889E0022B072 /* Assets.xcassets in Resources */, 8A92494E21C17F8000E3552A /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/FinalExam1.1/Base.lproj/Main.storyboard b/FinalExam1.1/Base.lproj/Main.storyboard index f1bcf38..f7da7eb 100644 --- a/FinalExam1.1/Base.lproj/Main.storyboard +++ b/FinalExam1.1/Base.lproj/Main.storyboard @@ -1,7 +1,11 @@ - + + + + - + + @@ -9,13 +13,81 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FinalExam1.1/ViewController.swift b/FinalExam1.1/ViewController.swift index f55857e..4c7ae2b 100644 --- a/FinalExam1.1/ViewController.swift +++ b/FinalExam1.1/ViewController.swift @@ -9,12 +9,70 @@ import UIKit class ViewController: UIViewController { - + + // Setup results label + @IBOutlet weak var resultsLabel: UILabel! + + // Setup data entry fields + @IBOutlet weak var gradeFieldOne: UITextField! + @IBOutlet weak var gradeFieldTwo: UITextField! + @IBOutlet weak var gradeFieldThree: UITextField! + + // Setup "Calculate Grade Average" button + @IBAction func calculateButton(_ sender: Any) { + + // Convert data entry strings to itegers + let grade1 = Int(gradeFieldOne.text!) + let grade2 = Int(gradeFieldTwo.text!) + let grade3 = Int(gradeFieldThree.text!) + + // Verify fields contain data + let gradeString1 = (gradeFieldOne.text!) + let gradeString2 = (gradeFieldTwo.text!) + let gradeString3 = (gradeFieldThree.text!) + + if(gradeString1.isEmpty) || (gradeString2.isEmpty) || (gradeString3.isEmpty) { + let myAlert = UIAlertController(title: "Alert", message: "All fields are required.", preferredStyle: UIAlertController.Style.alert) + + let okAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil) + + myAlert.addAction(okAction) + + self.present(myAlert, animated: true, completion: nil) + return + + } + + // Declare gradeList array + var gradesList: [Int] = [] + + // Append grades entered on the acreen to the gradesList array + gradesList.append(grade1!) + gradesList.append(grade2!) + gradesList.append(grade3!) + + // Calculate sum of grades + var total = 0 + for grade in gradesList { + total += grade + } + + // Calculate average + let average = total / gradesList.count + + // Display results to device screen + if average >= 70 { + resultsLabel.text = "Your average is \(average). \nYou Passed!" + } else { + resultsLabel.text = "Your average is \(average). \nBetter luck next time." + } + //gradeFieldOne.becomeFirstResponder() + } + override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + } - - }