----- CAPITULO 7 -------

Ejercicio numero 3

Codigo de Ejercicio:

  • Validar rangos y mostrar mensaje de error en aplicacion radio estacio
  • 
    //
    //  ViewController.swift
    //  RadioStations
    
    //Jehovani de Jesus Chavez Segovia 2561842011
    
    //Radio estacion agregar boton am fm y mostrar diferentes frecuencias, validar fuera de frecuencia
    
    import UIKit
    
    class ViewController: UIViewController {
    
        var myStation: RadioStation
        var myStation2: RadioStation
        
        @IBOutlet var stationName : UILabel!
             @IBOutlet var stationFrequency : UILabel!
        @IBOutlet var stationBand : UILabel!
        
        required init(coder aDecoder: NSCoder) {
            
            myStation = RadioStation()
            myStation.frequency=109.6
            myStation.name = "Knix"
            myStation2 = RadioStation()
            myStation2.frequency=1500.5
            myStation2.name = "Knix2"
            
            super.init(coder: aDecoder)
        }
            override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
        @IBAction func buttonClick(sender: AnyObject) {
            stationName.text = myStation.name
            stationFrequency.text = String(format:"%f", myStation.frequency)
            
            if myStation.frequency >= RadioStation.minFMFrequency() && myStation.frequency <= RadioStation.maxFMFrequency() {
                stationBand.text = "FM"
                
                
                
            } else {
                stationBand.text = "FUERA DE FRECUENCIA"
            }
            
        }
    
            @IBAction func buttonClick2(sender: AnyObject) {
            stationName.text = myStation2.name
            stationFrequency.text = String(format:"%f", myStation2.frequency)
            
            if myStation2.frequency <= RadioStation.minAMFrequency() && myStation2.frequency >= RadioStation.maxAMFrequency() {
                stationBand.text = "FUERA DE FRECUENCIA"
            } else {
                stationBand.text = "AM"
            }
            
        }
    
       
        
    }
                                

Seleccionamos boton fm y como esta fuera de rango muestra mensaje

Seleccionamos boton am y como esta dentro de rango muestra resultado