You are on page 1of 2

/* * To change this template, choose Tools * and open the template in the editor.

*/ package radiotuner; import java.util.Scanner; /** * * @author tp016092 */ public class Main {

Templates

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Tuning tune = new Tuning(); ThreadRadio r = new ThreadRadio (tune); r.start(); } } class ThreadRadio extends Thread{ Tuning tu; ThreadRadio(Tuning tune){ tu = tune; } @Override public void run(){ try { tu.controller(); Thread.sleep(1000); } catch (Exception e) { } } } class Tuning{ static int chnl_freq = 108; static int option = 0; static int onoff = 0; Scanner keyboard = new Scanner (System.in); public void reset(){ chnl_freq = 108; } public void scan(){ for(int i = 88; i<=108; i++){ System.out.println("Channel scanning: " + i); System.out.print("Save this channel (1:yes 2:no)->"); option = keyboard.nextInt(); if(option != 2){

controller(). switch(option){ case 1: onoff().out.print("(1:on/off 0:off) ->:"). case 2: this. break.out. controller(). this.reset(). } System.nextInt().lock(chnl_freq). System. } else break. } public void controller(){ System. option = keyboard. default: System. } } } .out.println("Invalid input.println("/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/"). chnl_freq = 108.nextInt().out.controller(). } public void lock(int save_chnl){ System.out. case 3: this. } public void onoff(){ System.out.println("---Radio now is (1:on 0:off) " + onoff +"---").println("Channel scanning end!")."). System.print("(1:on/off 2:reset 3:scan) ->:").scan().out. onoff = keyboard.println("Now you are listening: " + save_chnl).