By GokiSoft.com| 13:51 03/07/2023|
Java Basic

Java basic- Overview - viết chương trình điều khiển TIVI bằng java

1.    Tạo lớp cTivi 

Khai báo trường private

string[] channelList : chứa danh sách các kênh có của Tivi

bool isOn: Trạng thái xác định Tivi đang bật?

string currentChannel: Kênh hiện tại đang bật

Có Phương thức khởi tạo:

-       Không có tham số  thiết lập: isOn=false; khởi tạo mảng channelList có 3 kênh mặc định là “VTV1”,”VTV2”, “VTV3”, currentChannel=”VTV1”

-       Có tham số là chuỗi string[] channelList  thiết lập: gán trường channelList theo tham số cung cấp vào, isOn=false; currentChannel lấy là kênh đầu tiên trong channelList

Phương thức private

-       string seachNextChannel có 1 tham số isForward kiểu bool : Trả về kết quả Nếu isForward là true thì tìm kênh kế tiếp trong channelList (đến cuối thì về kênh đầu tiên). Ngược lại thì tìm kênh trước trong channelList (về đầu thì quay lại kênh cuối),

-       void On() : Thiết lập isOn là true và hiển thị ---Tivi ON---

-       void Off(): thiết lập isOn là false và hiển thị ---Tivi OFF---

-       void Switch() : chuyển trạng thái isOn từ true -> false và ngược lại và hiển thị kết quả tương ứng ---Tivi ON --- hay ---Tivi OFF---

-       void Switch(string channel): Chuyển trạng thái giống Switch trên song nếu Tivi bật thì chọn luôn kênh theo tham số cung cấp vào là channel đồng thời hiển thị thông tin có tìm thấy kênh đó hay không.

-       void nextChannel() : Chỉ khi isOn là true thì thực hiện chuyển kênh (gán currentChannel theo kênh kế tiếp) đồng thời hiển thị tên kênh mới

-       void previousChannel() : chỉ khi isOn là true thì thực hiện chuyển kênh (gán currentChannel theo kênh trước đó ) đồng thời hiển thị tên kênh mới

-       void Show() : Khi tivi bật hiển thị trạng thái ---Tivi is On at channel : ### ---, khi tivi tắt thì hiển thị trạng thái ---- Tivi now OFF! ----

2.    Trong phương thức Main của lớp Program hãy viết chương trình test lớp trên:

-       Cho phép người dùng chọn 1 trong 2 cách khởi tạo tivi: Mặc định (chọn 1), Tự chọn kênh (chọn 2).

-       Căn cứ trên từng cách  chọn hãy gọi phương thức khởi tạo tương ứng (Chú ý: cách 2 thì cần cho người dùng nhập vào số kênh, và tên lần lượt từng kênh)

-       Tạo menu chức năng:

1.    Chuyen trang thai (switch)

2.    Chuyen trang thai kem theo kenh

3.    Bat tivi

4.    Tat tivi

5.    Chuyen kenh tiep

6.    Chuyen kenh truoc

7.    Xem thong tin Tivi

8.    Ket thuc

Từng chức năng sẽ gọi phương thức của đối tượng cTivi trên, chú ý với chức năng 2: cần cho người dùng nhập vào tên kênh cụ thể trước làm tham số để gọi phương thức Switch(string channel)

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

GokiSoft.com [Teacher]
GokiSoft.com

2021-07-19 02:10:49


#Program.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson07.bt999;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Program {
    public static void main(String[] args) {
        CTivi tivi;
        Scanner scan = new Scanner(System.in);
        int choose, n;
        
        System.out.println("1. Khoi tao TV mac dinh");
        System.out.println("2. Chon kenh");
        System.out.println("Chon: ");
        choose = Integer.parseInt(scan.nextLine());
        
        switch(choose) {
            case 1:
                tivi = new CTivi();
                break;
            default:
                System.out.println("Nhap vao so kenh: ");
                n = Integer.parseInt(scan.nextLine());
                String[] channelList = new String[n];
                
                for (int i = 0; i < n; i++) {
                    System.out.printf("\nNhap kenh (%d)", i + 1);
                    channelList[i] = scan.nextLine();
                }
                
                tivi = new CTivi(channelList);
                break;
        }
        
        //Phat trien menu chuong trinh
        do {
            showMenu();
            choose = Integer.parseInt(scan.nextLine());
            
            switch(choose) {
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Nhap kenh can chuyen: ");
                    String channel = scan.nextLine();
                    
                    tivi.Switch(channel);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    System.out.println("Goodbye!!!");
                    break;
                default:
                    System.out.println("Input failed!!!");
                    break;
            }
        } while(choose != 8);
    }
    
    static void showMenu() {
        System.out.println("1. Switch");
        System.out.println("2. Switch by channel");
        System.out.println("3. On");
        System.out.println("4. Off");
        System.out.println("5. Next channel");
        System.out.println("6. Previous channel");
        System.out.println("7. Show");
        System.out.println("8. Exit");
        System.out.println("Choose: ");
    }
}


#CTivi.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson07.bt999;

/**
 *
 * @author Diep.Tran
 */
public class CTivi {
    String[] channelList;
    boolean isOn;
    String currentChannel;
    int currentIndex;

    public CTivi() {
        isOn = false;
        channelList = new String[] {"VTV1", "VTV2", "VTV3"};
        currentChannel = "VTV1";
        currentIndex = 0;
    }

    public CTivi(String[] channelList) {
        this.channelList = channelList;
        isOn = false;
        if(channelList.length > 0) {
            currentChannel = channelList[0];
        }
        currentIndex = 0;
    }
    
    private String seachNextChannel(boolean isForward) {
        if(isForward) {
            currentIndex++;
            if(currentIndex >= channelList.length) {
                currentIndex = 0;
            }
        } else {
            currentIndex--;
            if(currentIndex < 0) {
                currentIndex = channelList.length - 1;
            }
        }
        return channelList[currentIndex];
    }
    
    public void On() {
        isOn = true;
        System.out.println("-- TV ON --");
    }
    
    public void Off() {
        isOn = false;
        System.out.println("-- TV OFF --");
    }
    
    public void Switch() {
        if(isOn) {
            Off();
        } else {
            On();
        }
    }
    
    public void Switch(String channel) {
        Switch();
        
        if(isOn) {
            boolean isFind = false;
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(channel)) {
                    currentIndex = i;
                    currentChannel = channelList[i];
                    System.out.println("Tim thay kenh");
                    isFind = true;
                    break;
                }
            }
            if(!isFind) {
                System.out.println("Khong tim thay kenh");
            }
        }
    }
    
    public void nextChannel() {
        if(isOn) {
            currentChannel = seachNextChannel(true);
            System.out.println("Current Channel: " + currentChannel);
        }
    }
    
    public void previousChannel() {
        if(isOn) {
            currentChannel = seachNextChannel(false);
            System.out.println("Current Channel: " + currentChannel);
        }
    }
    
    public void Show() {
        if(isOn) {
            System.out.println("-- Tivi is On at channel: " + currentChannel);
        } else {
            System.out.println("-- Tivi now OFF! --");
        }
    }
}



Nguyễn Tiến Đạt [T2008A]
Nguyễn Tiến Đạt

2021-03-08 15:50:56


#cTivi.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson9.DieuKhienTiVi;



/**
 *
 * @author MyPC
 */
public class cTivi {
    private String[] channelList;
    private boolean isOn;
    private String currentChannel;

    public cTivi() {
        isOn = false;
        channelList = new String[3];
        channelList[0] = "VTV1";
        channelList[1] = "VTV2";
        channelList[2] = "VTV3";
        currentChannel = channelList[0];
    }

    public cTivi(String[] channelList) {
        this.channelList = channelList;
        this.isOn = false;
        this.currentChannel = channelList[0];
    }

    

    
    
    public String searchNextChannel(boolean isForward){
        if(isForward == true){
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(currentChannel)){
                    if( i != channelList.length - 1 ) return channelList[i+1];
                    else return channelList[0];
                }
            }
        }else{
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(currentChannel)){
                    if( i != 0 ) return channelList[i-1];
                    else return channelList[channelList.length-1];
                }
            }
        }
        return null;
    }
    
    public void On(){
        isOn = true;
        System.out.println("---Tivi ON---");
    }
    
    public void Off(){
        isOn = false;
        System.out.println("---Tivi OFF---");
    }
    
    public void Switch(){
        if(isOn == false){
            isOn = true;
            System.out.println("---Tivi ON---");
        }else{
            isOn = false;
            System.out.println("---Tivi OFF---");
        }
    }
    
    public void Switch(String channel){
        if(isOn == false){
            System.out.println("Tivi chua bat!!");
        }else{
            int check = 0;
            for (String string : channelList) {
                if(string.equalsIgnoreCase(channel)){
                    check++;
                    System.out.println("Da tim thay kenh!!");
                    currentChannel = string;
                    break;
                }
            }
            if(check == 0) System.out.println("Khong tim thay kenh!!");
        }
    }
    
    public void nextChannel(){
        if(isOn == true){
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(currentChannel)){
                    if( i != channelList.length - 1 )  currentChannel = channelList[i+1];
                    else currentChannel = channelList[0]; 
                    break;
                }
            }
            System.out.println(currentChannel);
        }else System.out.println("Tivi chua bat!!");
    }
    
    public void previousChannel(){
        if(isOn == true){
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(currentChannel)){
                    if( i != 0 )  currentChannel = channelList[i-1];
                    else currentChannel = channelList[channelList.length-1]; 
                    break;
                }
            }
            System.out.println(currentChannel);
        }else System.out.println("Tivi chua bat!!");
    }
    
    public void Show(){
        if(isOn == true){
            System.out.println("---Tivi is On at channel: " + currentChannel + "---");
        }else{
            System.out.println("---Tivi now OFF!---");
        }
    }
}


#Program.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson9.DieuKhienTiVi;

import java.util.Scanner;

/**
 *
 * @author MyPC
 */
public class Program {
    public static void main(String[] args) {
        int choose;
        cTivi tivi;
        Scanner scan = new Scanner(System.in);
        System.out.println("Lua chon phuong thuc khoi tao tivi:");
        System.out.println("1.Mac dinh");
        System.out.println("2.Tu chon kenh");
        choose = Integer.parseInt(scan.nextLine());
        if(choose == 1){
            tivi = new cTivi();
            System.out.println("Da khoi tao mac dinh!!");
        }else{
            System.out.println("Nhap so kenh muon them vao:");
            int select = Integer.parseInt(scan.nextLine());
            String[] list = new String[select];
            int count = 0;
            while(true){
                System.out.println("Nhap kenh:");
                String kenh = scan.nextLine();
                list[count++] = kenh;
                select--;
                if(select == 0) break;
            }
            tivi = new cTivi(list);
            System.out.println("Da khoi tao tu chon kenh!!");
        }
        do{
            showMenu();
            System.out.println("Lua chon chuong trinh:");
            choose = Integer.parseInt(scan.nextLine());
            switch(choose){
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Nhap kenh:");
                    String kenh = scan.nextLine();
                    tivi.Switch(kenh);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    System.out.println("Ket thuc chuong trinh!!");
                    break;
                default:
                    System.out.println("Nhap sai!!");
                    break;
            }
        }while(choose != 8);
    }
    static void showMenu(){
        System.out.println("1.Chuyen trang thai");
        System.out.println("2.Chuyen trang thai kem theo kenh");
        System.out.println("3.Bat tivi");
        System.out.println("4.Tat tivi");
        System.out.println("5.Chuyen kenh tiep");
        System.out.println("6.Chuyen kenh truoc");
        System.out.println("7.Xem thong tin tivi");
        System.out.println("8.Ket thuc");
    }
}



Vũ Việt Đức [C1907L]
Vũ Việt Đức

2020-03-30 18:01:08



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession7;

/**
 *
 * @author ADMIN
 */
public class cTivi {
    private String[] channeList;
    private boolean isOn;
    private String currentChannel;

    public cTivi() {
        isOn = false;
        channeList = new String[]{"VTV1", "VTV2", "VTV3"};
        currentChannel = "VTV1";
    }

    public cTivi(String[] channeList) {
        this.channeList = channeList;
        isOn = false;
        currentChannel = channeList[0];
    }
    
    private String seachNextChannel(boolean isForward){
        int index = 0;
            
        for(int i = 0; i < channeList.length; i++){
            if(channeList[i].equals(currentChannel)){
                index = i;
                break;
            }
        }
        
        if(isForward){
            if(index == (channeList.length - 1)){
                return channeList[0];
            }else{
                return channeList[index + 1];
            }
        }else{
            if(index == 0){
                return channeList[channeList.length - 1];
            }else{
                return channeList[index - 1];
            }
        }
    }
    
    public void On(){
        isOn = true;
        System.out.println("---Tivi ON---");
    }
    
    public void Off(){
        isOn = false;
        System.out.println("---Tivi OFF---");
    }
    
    public void Switch(){
        if(isOn){
            isOn = !isOn;
            System.out.println("---Tivi OFF---");
        }
        else{
            isOn = !isOn;
            System.out.println("---Tivi ON---");
        }
    }
    
    public void Switch(String channel){
        if(isOn){
            isOn = !isOn;
            System.out.println("---Tivi OFF---");
        }
        else{
            isOn = !isOn;
            System.out.println("---Tivi ON---");
            int t = 0;
            for(int i = 0; i < channeList.length; i++){
                if(channeList[i].equals(channel)){
                    currentChannel = channel;
                    System.out.println("Tìm thấy kênh đã nhập");
                    t++;
                    break;
                }
            }
            if(t == 0){
                System.out.println("Không tìm thấy kênh đã nhập!");
            }
        }
    }
    
    public void nextChannel(){
        if(isOn){
            currentChannel = seachNextChannel(true);
            System.out.println(currentChannel);
        }
    }
    
    public void previousChannel(){
        if(isOn){
            currentChannel = seachNextChannel(false);
            System.out.println(currentChannel);
        }
    }
    
    public void Show(){
        if(isOn){
            System.out.println("---Tivi is On at channel : " + currentChannel + " ---");
        }else{
            System.out.println("---- Tivi now OFF! ----");
        }
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession7;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        cTivi tivi;
        System.out.println("Vui lòng chọn cách khởi tạo tivi:\n1. Mặc định\n2. Tự chọn kênh ");
        int ch = Integer.parseInt(scanner.nextLine());
        if(ch == 2){
            System.out.print("Vui lòng nhập số kênh: ");
            int numbers = Integer.parseInt(scanner.nextLine());
            String[] strArr = new String[numbers];
            for(int i = 0; i < numbers; i++){
                System.out.print("Nhập tên kênh thứ " + (i + 1) + " : ");
                strArr[i] = scanner.nextLine();
            }
            tivi = new cTivi(strArr);
        }else{
            tivi = new cTivi();
        }
        
        while(true){
            System.out.println("Vui long chon: 1.    Chuyen trang thai (switch)\n2.    Chuyen trang thai kem theo kenh\n3.    Bat tivi\n4.    Tat tivi\n5.    Chuyen kenh tiep\n6.    Chuyen kenh truoc\n7.    Xem thong tin Tivi\n8.    Ket thuc");
            int choose = Integer.parseInt(scanner.nextLine());
            
            switch(choose){
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.print("Vui lòng nhập kênh: ");
                    String k = scanner.nextLine();
                    tivi.Switch(k);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    break;
                default:
                    System.out.println("Lựa chọn không đúng, vui lòng chọn lại!");
            }
            
            if(choose == 8){
                break;
            }
        }
    }
}



Ngô Quang Huy [C1907L]
Ngô Quang Huy

2020-03-30 03:44:43



package March28;

public class cTivi {
    private String[] channelList;
    private boolean isOn;
    private String currentChannel;
    private int currentIndex;

    public cTivi() {
        this.isOn = false;
        channelList = new String[]{"VTV1","VTV2", "VTV3"};
        currentChannel = "VTV1";
        currentIndex = 0;
    }

    public cTivi(String[] channelList) {
        this.channelList = channelList;
        this.isOn = false;
        currentChannel = channelList[0];
        currentIndex = 0;
    }

    public String[] getChannelList() {
        return channelList;
    }

    public void setChannelList(String[] channelList) {
        this.channelList = channelList;
    }

    public boolean isIsOn() {
        return isOn;
    }

    public void setIsOn(boolean isOn) {
        this.isOn = isOn;
    }

    public String getCurrentChannel() {
        return currentChannel;
    }

    public void setCurrentChannel(String currentChannel) {
        this.currentChannel = currentChannel;
    }

    public int getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(int currentIndex) {
        this.currentIndex = currentIndex;
    }
    
    private String seachNextChannel (boolean isForward){
        if(isForward == true){
            this.currentIndex++;
            if(this.currentIndex == channelList.length){
                this.currentIndex = 0;
            }
        }else{
            this.currentIndex--;
            if(this.currentIndex < 0){
                this.currentIndex = channelList.length - 1;
            }
        }
        this.currentChannel = channelList[this.currentIndex];
        return currentChannel;
    }
    
    public void On(){
        this.isOn = true;
        System.out.println("Tivi On");
    }
    
    public void off(){
        this.isOn = false;
        System.out.println("Tivi Off");
    }
    
    public void Switch(){
        if(this.isOn == true){
            off();
        }else{
            On();
        }
    }
    
    public void Switch(String channel){
        Switch();
        if(this.isOn == true){
            this.isOn = false;
            System.out.println("Tivi Off");
        }else{
            this.isOn = true;
            System.out.println("Tivi On");
            int dk=0;
            for(int i=0;i<channelList.length;i++){
                if(channel.equals(channelList[i])){
                    dk=1;
                    this.currentChannel = channel;
                    System.out.println("The channel is found");
                    break;
                }
            }
            if(dk==0){
                System.out.println("The channel isn't here");
            }
        }
    }
    
    public void nextChannel(){
        if(this.isOn == true){
            this.currentChannel = seachNextChannel(true);
            System.out.println("Current: " + currentChannel);
        }
    }
    
    public void previousChannel(){
        if(this.isOn == true){
            this.currentChannel = seachNextChannel(false);
            System.out.println("Current: " + currentChannel);
        }
    }
    
    public void Show(){
        if(this.isOn == true){
            System.out.println("Tivi is On at channel "+currentChannel);
        }else{
            System.out.println("TV now off");
        }        
    }
}



package March28;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        cTivi tv;
        System.out.println("1.Default");
        System.out.println("2.Manuel");
        System.out.print("Choose: ");
        int choose = Integer.parseInt(input.nextLine());
        switch(choose){
            case 1:
                tv = new cTivi();
                break;
            default:
                System.out.println("Number of channel: ");
                int n = Integer.parseInt(input.nextLine());
                String[] arr = new String[n];
                System.out.println("Channel:");
                for(int i=0;i<n;i++){
                    arr[i] = input.nextLine();
                }
                tv = new cTivi(arr);
                break;
        }
        while(true){
            System.out.println("\n1.Default Switch");
            System.out.println("2.Manuel Switch");
            System.out.println("3.Turn On");
            System.out.println("4.Turn Off");
            System.out.println("5.Next Channel");
            System.out.println("6.Previous Channel");
            System.out.println("7.Show Information");
            System.out.println("8.Exit");
            System.out.print("Choose: ");
            choose = Integer.parseInt(input.nextLine());
            switch(choose){
                case 1:
                    tv.Switch();
                    break;
                case 2:
                    System.out.println("Find channel: ");
                    String t = input.nextLine();
                    tv.Switch(t);
                    break;
                case 3:
                    tv.On();
                    break;
                case 4:
                    tv.off();
                    break;
                case 5:
                    tv.nextChannel();
                    break;
                case 6:
                    tv.previousChannel();
                    break;
                case 7:
                    tv.Show();
                    break;
                default:
                    System.exit(0);
                    break;
            }
        }
    }
}



trung [C1907L]
trung

2020-03-29 16:29:17



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package btvn;

/**
 *
 * @author prdox
 */
public class cTivi {
    private String[] channelList;
    private boolean isOn;
    private String currentChannel;
    private int currentIndex;

    public cTivi() {
        isOn = false;
        channelList = new String[]{"VTV1", "VTV2", "VTV3"};
        currentChannel = "VTV1";
        isOn = false;
        currentIndex = 0;
    }
    
    public cTivi(String[] channelList) {
        this.channelList = channelList;
        isOn = false;
        if (channelList.length > 0){
            currentChannel = channelList[0];
            currentIndex = 0;
        }
        
    }
    
    private String searchNextChannel(boolean isForward) {
        int incDec = isForward ? 1 : -1;
        int nextIndex = currentIndex + incDec;
        nextIndex = (nextIndex > channelList.length-1) ? 0 : nextIndex;
        nextIndex = (nextIndex < 0) ? channelList.length - 1 : nextIndex;
        return channelList[nextIndex];
    }
    
    public void On(){
        isOn = true;
        System.out.println("---Tivi ON---");
    }
    
    public void Off(){
        isOn = false;
        System.out.println("---Tivi OFF---");
    }
    
    public void Switch() {
        if (isOn){
            Off();
        }else{
            On();
        }
    }
    
    public void Switch(String channel){
        if (isOn){
            Off();
        }else{
            int i = 0;
            for (; i < channelList.length; i++) {
                if (channel.equalsIgnoreCase(channelList[i])){
                    currentIndex = i;
                    currentChannel = channel;
                    break;
                }
            }
            if (i == channelList.length){
                System.out.println("Channel not found");
            }
            On();
        }
    }
    
    public void nextChannel(){
        if (!isOn) return;
        currentChannel = searchNextChannel(true);
        currentIndex = currentIndex == channelList.length-1 ? 0 : currentIndex+1;
        System.out.println(currentChannel);
    }
    
    public void previousChannel(){
        if (!isOn) return;
        currentChannel = searchNextChannel(false);
        currentIndex = currentIndex == 0 ? channelList.length - 1 : currentIndex - 1;
        System.out.println(currentChannel);
    }
    
    public void Show(){
        if (isOn) {
            System.out.format("---Tivi is On at channel:%s",currentChannel);
        }else{
            System.out.println("TV now OFF");
        }
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package btvn;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Main {

    public static void main(String[] args) {
        int consOp;
        cTivi testC;
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap vao cach khoi tao");
        System.out.println("1. Default");
        System.out.println("2. Manual");
        consOp = Integer.parseInt(input.nextLine());
        if (consOp == 1) {
            testC = new cTivi();
        } else {
            System.out.println("Nhap vao so kenh");
            int nChannel = Integer.parseInt(input.nextLine());
            String[] channelList = new String[nChannel];
            for (int i = 0; i < nChannel; i++) {
                System.out.format("Nhap vao kenh thu %d: ", i + 1);
                channelList[i] = input.nextLine();
            }
            testC = new cTivi(channelList);
        }
        boolean exit = false;
        int select;
        //in menu
        while(!exit){
            System.out.println("1.    Chuyen trang thai (switch)\n"
                + "2.    Chuyen trang thai kem theo kenh\n"
                + "3.    Bat tivi\n"
                + "4.    Tat tivi\n"
                + "5.    Chuyen kenh tiep\n"
                + "6.    Chuyen kenh truoc\n"
                + "7.    Xem thong tin Tivi\n"
                + "8.    Ket thuc");
            select = Integer.parseInt(input.nextLine());
            switch(select){
                case 1:
                    testC.Switch();
                    break;
                case 2:
                    System.out.println("Nhap vao kenh");
                    testC.Switch(input.nextLine());
                    break;
                case 3:
                    testC.On();
                    break;
                case 4:
                    testC.Off();
                    break;
                case 5:
                    testC.nextChannel();
                    break;
                case 6:
                    testC.previousChannel();
                    break;
                case 7:
                    testC.Show();
                    break;
                case 8:
                    exit = true;
                    break; 
            }
        }
    }
}



Hoàng Quang Huy [C1907L]
Hoàng Quang Huy

2020-03-29 10:49:05




package Tivi;

public class cTivi {

    private String[] channelList;
    private boolean isOn;
    private String currentChannel;
    private int channelIndex = 0;

    public cTivi() {
        this.isOn = false;
        channelList = new String[]{"VTV1", "VTV2", "VTV3"};
        this.currentChannel = "VTV1";
    }

    public cTivi(String[] channelList, boolean isOn, String currentChannel) {
        this.channelList = channelList;
        this.isOn = isOn;
        this.currentChannel = currentChannel;

    }

    public cTivi(String[] channelList) {
        this.channelList = channelList;
        this.isOn = false;
        if (channelList.length > 0) {
            this.currentChannel = channelList[0];
        }
    }

    public String[] getChannelList() {
        return channelList;
    }

    public void setChannelList(String[] channelList) {
        this.channelList = channelList;
    }

    public boolean isIsOn() {
        return isOn;
    }

    public void setIsOn(boolean isOn) {
        this.isOn = isOn;
    }

    public String getCurrentChannel() {
        return currentChannel;
    }

    public void setCurrentChannel(String currentChannel) {
        this.currentChannel = currentChannel;
    }

    private String searchNextChannel(boolean isForward) {
        if (isForward) {
            channelIndex++;
            if (channelIndex >= channelList.length) {
                channelIndex = 0;
            }
        } else {
            channelIndex--;
            if (channelIndex < 0) {
                channelIndex = channelList.length - 1;
            }
        }
        currentChannel = channelList[channelIndex];
        return currentChannel;
    }

    public void On() {
        if (this.isOn) {
            System.out.println("TV is currently on");
        } else {
            this.isOn = true;
            System.out.println("TV On");
        }
    }

    public void Off() {
        if (!this.isOn) {
            System.out.println("TV is currently off");
        } else {
            this.isOn = false;
            System.out.println("TV Off");
        }
    }

    public void Switch() {
        if (this.isOn) {
            System.out.println("TV Off");
            this.isOn = false;
        } else {
            System.out.println("TV On");
            this.isOn = true;
        }
    }

    public void Switch(String channel) {
        int count = 0;
        if (!this.isOn) {
            this.isOn = true;
            System.out.println("TV On");
        }
        for (int i = 0; i < channelList.length; i++) {
            if (channel.equals(channelList[i])) {
                this.currentChannel = channel;
                System.out.println("Current Channel: " + channel);
                count++;
            }
        }
        if (count == 0) {
            System.out.println("Can not find " + channel);
        }
    }

    public void NextChannel() {
        if (this.isOn) {
            searchNextChannel(true);
            System.out.println("Current Channel: " + currentChannel);
        }
    }

    public void previousChannel() {
        if (this.isOn) {
            searchNextChannel(false);
            System.out.println("Current Channel: " + currentChannel);
        }
    }

    public void Show() {
        if (isOn) {
            System.out.println("--- Tivi is On at channel " + currentChannel + "---");
        } else {
            System.out.println("--- Tivi is Off now ---");
        }
    }
}

----------------------------------------------------------------------------

package Tivi;

import java.util.Scanner;

public class Program {

    public static void showMenu() {
        System.out.println("1.  Chuyển trạng thái (switch) ");
        System.out.println("2.  Chuyển trạng thái kèm theo kênh");
        System.out.println("3.  Bật Tivi");
        System.out.println("4.  Tắt Tivi");
        System.out.println("5.  Chuyển kênh tiếp");
        System.out.println("6.  Chuyển kênh trước");
        System.out.println("7.  Xem thông tin Tivi");
        System.out.println("8.  Thoát");
        System.out.println("Lựa chọn của bạn là: ");
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n,choice;
        cTivi tivi = null;
        String name;
        do {
            System.out.println("1. Cài đặt kênh trên tivi mặc định ");
            System.out.println("2. Cài đặt kênh trên tivi thủ công");
            System.out.println("Lựa chọn của bạn là: ");
            choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    tivi = new cTivi();
                    break;
                case 2:
                    System.out.println("Nhập vào số kênh bạn muốn thêm: ");
                    n = Integer.parseInt(input.nextLine());
                    String[] list = new String[n];
                    for (int i = 0; i < n; i++) {
                        System.out.println("Nhập tên kênh");
                        name = input.nextLine();
                        list[i] = name;
                    }
                    tivi = new cTivi(list);
                    break;
                default:
                    System.out.println("Lựa chọn không hợp lệ");
                    break;
            }
        } while (choice != 1 && choice != 2);
        
        boolean flag = true;
        int choice2;
        while (flag) {
            showMenu();
            choice2 = Integer.parseInt(input.nextLine());
            switch (choice2) {
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Nhập vào tên kênh: ");
                    tivi.Switch(input.nextLine());
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.NextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    System.out.println("Thoát");
                    flag = false;
                    break;
                default:
                    System.out.println("Lựa chọn không hợp lệ");
                    break;
            }
        }
    }
}



Nguyen Duc Viet [C1907L]
Nguyen Duc Viet

2020-03-29 10:23:31



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

/**
 *
 * @author Diep.Tran
 */
public class CTivi {
    private String[] channelList;
    private boolean isOn;
    private String currentChannel;
    private int currentIndex = 0;

    public CTivi() {
        isOn = false;
        channelList = new String[]{"VTV1", "VTV2", "VTV3"};
        currentChannel = "VTV1";
        currentIndex = 0;
    }

    public CTivi(String[] channelList) {
        this.channelList = channelList;
        isOn = false;
        if(channelList.length > 0) {
            currentChannel = channelList[0];
            currentIndex = 0;
        }
    }
    
    private String searchNextChannel(boolean isForward) {
        if(channelList.length == 0) {
            return null;
        }
        
        if(isForward) {
            currentIndex++;
            if(currentIndex >= channelList.length) {
                currentIndex = 0;
            }
        } else {
            currentIndex--;
            if(currentIndex < 0) {
                currentIndex = channelList.length - 1;
            }
        }
        
        currentChannel = channelList[currentIndex];
        return currentChannel;
    }
    
    public void On() {
        isOn = true;
        System.out.println("--Tivi On--");
    }
    
    public void Off() {
        isOn = false;
        System.out.println("--Tivi Off--");
    }
    
    public void Switch() {
        if(isOn) {
            Off();
        } else {
            On();
        }
    }
    
    public void Switch(String channel) {
        Switch();
        if(isOn) {
            currentIndex = -1;
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(channel)) {
                    currentChannel = channelList[i];
                    currentIndex = i;
                    break;
                }
            }
            
            if(currentIndex == -1) {
                System.out.println("Khong tim thay kenh : " + channel);
            } else {
                System.out.println("Da tim thay kenh : " + channel);
            }
        }
    }
    
    public void nextChannel() {
        if(isOn) {
            searchNextChannel(true);
            System.out.println("Current Channel : " + currentChannel);
        }
    }
    
    public void previousChannel() {
        if(isOn) {
            searchNextChannel(false);
            System.out.println("Current Channel : " + currentChannel);
        }
    }
    
    public void Show() {
        if(isOn) {
            System.out.println("---Tivi is On at channel : " + currentChannel);
        } else {
            System.out.println("---- Tivi now OFF! ----");
        }
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        CTivi tivi;
        Scanner input = new Scanner(System.in);
        int choose;
        
        System.out.println("Chon cach khoi tao kenh");
        System.out.println("1. Mac dinh");
        System.out.println("2. Tu chon kenh");
        System.out.println("Choose: ");
        choose = Integer.parseInt(input.nextLine());
        
        switch(choose) {
            case 1:
                tivi = new CTivi();
                break;
            default:
                System.out.println("Nhap so kenh can them : ");
                int n = Integer.parseInt(input.nextLine());
                String[] channelList = new String[n];
                
                for (int i = 0; i < n; i++) {
                    System.out.format("\nNhap kenh (%d) : ", i);
                    channelList[i] = input.nextLine();
                }
                
                tivi = new CTivi(channelList);
                break;
        }
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose) {
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Nhap kenh can tim : ");
                    String searchChannel = input.nextLine();
                    
                    tivi.Switch(searchChannel);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    System.out.println("Exit Program!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 8);
    }
    
    public static void showMenu() {
        System.out.println("1.    Chuyen trang thai (switch)");
        System.out.println("2.    Chuyen trang thai kem theo kenh");
        System.out.println("3.    Bat tivi");
        System.out.println("4.    Tat tivi");
        System.out.println("5.    Chuyen kenh tiep");
        System.out.println("6.    Chuyen kenh truoc");
        System.out.println("7.    Xem thong tin Tivi");
        System.out.println("8.    Ket thuc");
        System.out.println("Choose: ");
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-03-28 17:30:53



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Tivi;

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class cTivi {

    private String[] channelList = {"VTV1", "VTV2", "VTV3"};
    private Boolean isOn = false;
    String currentChannel = channelList[0];

    String searchNextChanel(Boolean isForward) {
        if (isForward == true) {
            int indexCurrentChan = 0;
            for (int i = 0; i < channelList.length; i++) {
                if (channelList[i].compareTo(currentChannel) == 0) {
                    indexCurrentChan = i;
                }
            }
            indexCurrentChan = indexCurrentChan + 1 < channelList.length ? indexCurrentChan + 1 : 0;
            currentChannel = channelList[indexCurrentChan];
        }
        if (isForward == false) {
            int indexCurrentChan = 0;
            for (int i = 0; i < channelList.length; i++) {
                if (channelList[i].compareTo(currentChannel) == 0) {
                    indexCurrentChan = i;
                }
            }
            indexCurrentChan = indexCurrentChan - 1 < 0 ?  channelList.length - 1 : indexCurrentChan - 1 ;
            currentChannel = channelList[indexCurrentChan];
        }
        return currentChannel;
    }

    void On() {
        isOn = true;
    }

    void Off() {
        isOn = false;
    }

    void Switch() {
        if (isOn == true) {
            isOn = false;
        } else if (isOn == false) {
            isOn = true;
        }
    }

    void Switch(String channel) {
        if (isOn == true) {
            int flag = 1;
            for (int i = 0; i < channelList.length; i++) {
                if (channelList[i].compareTo(channel) == 0) {
                    currentChannel = channel;
                    flag = 2;
                }
            }
            if (flag == 1) {
                System.out.println("Your channel is not exists");
            }
        }
    }

    void nextChannel() {
        if (isOn == true) {
            searchNextChanel(isOn);
        }
    }

    void previousChannel() {
        if (isOn == true) {
            searchNextChanel(false);
        }
    }

    void Show() {
        if (isOn == true) {
            System.out.println("---Tivi is On at channel : " + currentChannel + "---");
        } else if (isOn == false) {
            System.out.println(" ---- Tivi now OFF! ----");
        }

    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Tivi;

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class Main {

    public static void menu() {
        System.out.println("1.Chuyen trang thai (switch)");
        System.out.println("2.Chuyen trang thai kem theo kenh");
        System.out.println("3.Bat tivi");
        System.out.println("4.Tat tivi");
        System.out.println("5.Chuyen kenh tiep");
        System.out.println("6.Chuyen kenh truoc");
        System.out.println("7.Xem thong tin Tivi");
        System.out.println("8.Ket thuc");
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        cTivi tivi;
         tivi = new cTivi();
        while (true) {
            menu();
            int choice = Integer.parseInt(input.nextLine());
            switch (choice) {
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Input channel : ");
                    String channel = input.nextLine();
                    tivi.Switch(channel);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                     tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                     tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    return;
            }
        }
    }
}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-03-18 02:48:51



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Tivi;
import java.util.Scanner;
/**
 *
 * @author abc
 */
public class Main {
    public static void main(String[] args)
    {
        cTivi tivi;
        tivi = new cTivi();
        Scanner input = new Scanner(System.in);
        int choose;
        
        System.out.println("Chon cach khoi tao kenh");
        System.out.println("1. Mac dinh");
        System.out.println("2. Tu chon kenh");
        System.out.println("Choose :");
        choose = Integer.parseInt(input.nextLine());
        
        switch(choose)
        {
            case 1 :
                tivi = new cTivi();
                break;
                
            case 2 :
                System.out.println("Nhap so kenh can them");
                int n = Integer.parseInt(input.nextLine());
                
                String channelList[] = new String[n];
                
                for(int i = 0 ; i < n ; i++)
                {
                    System.out.format("\nNhap kenh (%d) :", i+1);
                    channelList[i] = input.nextLine();
                }
                tivi = new cTivi(channelList);
                
                break;
                
            default :
                System.out.println("Moi ban nhap lai");
                break;
        }
        
        do
        {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            
            switch(choose)
            {
                case 1 :
                    tivi.Switch();
                    break;
                case 2 :
                    System.out.println("Nhap kenh can tim :");
                    String searchChannel = input.nextLine();
                    tivi.Switch(searchChannel);
                    break;
                case 3 :
                    tivi.On();
                    break;
                case 4 :
                    tivi.Off();
                    break;
                case 5 :
                    tivi.nextChannel();
                    break;
                case 6 :
                    tivi.previousChannel();
                    break;
                case 7 :
                    tivi.Show();
                    break;
                case 8 :
                    System.out.println("Exit Program");
                    break;
                default :
                    System.out.println("Nhap sai");
                break;
                
                
                
            }
        }while(choose!=8);
        
        
    }
    public static void showMenu()
    {
        System.out.println("1. Chuyen trang thai");
        System.out.println("2. Chuyen trang thai theo kenh");
        System.out.println("3. Bat Tivi");
        System.out.println("4. Tat Tivi");
        System.out.println("5. Chuyen kenh tiep");
        System.out.println("6. Chuyen kenh truoc");
        System.out.println("7. Xem thong tin Tivi");
        System.out.println("8.Ket thuc");
        
    }
    
    
    
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Tivi;

/**
 *
 * @author abc
 */
public class cTivi {
    String[] channelList; // chua danh sach kenh co cua Tivi
    boolean isOn; // trang thai tivi dang bat
    String currentChannel;
    Integer currentIndex = 0;
    
    public cTivi()
    {
        isOn = false;
        channelList = new String[]{"VTV1","VTV2","VTV3"};
        currentChannel = "VTV1";
        currentIndex = 0;
    }

    public cTivi(String[] channelList) {
        this.channelList = channelList;
        isOn = false;
        if(channelList.length > 0)
        {
            currentChannel = channelList[0];
            currentIndex = 0;
        }
    }
    
    
    private String searchNextChannel(boolean isForward){
        if(channelList.length == 0)
        {
            return null;
        }
        
        if (isForward)
        {
            currentIndex++;
            
            if ( currentIndex >= channelList.length)
            {
                currentIndex = 0;
            }
        }
        else
        {
            currentIndex--;
            if (currentIndex < 0)
            {
                currentIndex = channelList.length - 1;
            }
        }
        
        currentChannel = channelList[currentIndex];
        return currentChannel;
    }
    
    
    public void On()
    {
        isOn = true;
        System.out.println("Tivi is on");
    }
    
    public void Off()
    {
        isOn = false;
        System.out.println("Tivi is off");
    }
    
    public void Switch()
    {
        if(isOn)
        {
            Off();
        }
        else
        {
            On();
        }
    }
    
    
    public void Switch(String channel)
    {
        Switch();
        
        if(isOn)
        {
            currentIndex = -1;
            for ( int i = 0 ; i < channelList.length ; i++)
            {
                if(channelList[i].equalsIgnoreCase(channel))
                {
                    currentChannel = channelList[i];
                    currentIndex = i;
                    break;
                }
            }
            
            if (currentIndex == -1)
            {
                System.out.println("Khong tim thay kenh :" + channel);
            }
            else
            {
                System.out.println("Ta tim thay kenh :" + channel);
            }
            
        }
    }
    
    public void nextChannel()
    {
        if(isOn)
        {
            searchNextChannel(true);
            System.out.println("Current Channel :" + currentChannel);
        }
    }
    public void previousChannel()
    {
        if(isOn)
        {
            searchNextChannel(!true);
            System.out.println("CurrentChannel :" + currentChannel);
        }
    }
    
    public void Show()
    {
        if(isOn)
        {
            System.out.println("Tivi is on at channel :" + currentChannel);
        }
        else
        {
            System.out.println("Tivi is now off");
        }
    }
    
}



Hoang Ngo [T1907A]
Hoang Ngo

2020-03-16 06:55:56



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

import java.util.Scanner;

/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        CTivi tivi;
        Scanner input = new Scanner(System.in);
        int choose;
        
        System.out.println("Chon cach khoi tao kenh");
        System.out.println("1. Mac dinh");
        System.out.println("2. Tu chon kenh");
        System.out.println("Choose: ");
        choose = Integer.parseInt(input.nextLine());
        
        switch(choose) {
            case 1:
                tivi = new CTivi();
                break;
            default:
                System.out.println("Nhap so kenh can them : ");
                int n = Integer.parseInt(input.nextLine());
                String[] channelList = new String[n];
                
                for (int i = 0; i < n; i++) {
                    System.out.format("\nNhap kenh (%d) : ", i);
                    channelList[i] = input.nextLine();
                }
                
                tivi = new CTivi(channelList);
                break;
        }
        
        do {
            showMenu();
            choose = Integer.parseInt(input.nextLine());
            
            switch(choose) {
                case 1:
                    tivi.Switch();
                    break;
                case 2:
                    System.out.println("Nhap kenh can tim : ");
                    String searchChannel = input.nextLine();
                    
                    tivi.Switch(searchChannel);
                    break;
                case 3:
                    tivi.On();
                    break;
                case 4:
                    tivi.Off();
                    break;
                case 5:
                    tivi.nextChannel();
                    break;
                case 6:
                    tivi.previousChannel();
                    break;
                case 7:
                    tivi.Show();
                    break;
                case 8:
                    System.out.println("Exit Program!!!");
                    break;
                default:
                    System.out.println("Nhap sai!!!");
                    break;
            }
        } while(choose != 8);
    }
    
    public static void showMenu() {
        System.out.println("1.    Chuyen trang thai (switch)");
        System.out.println("2.    Chuyen trang thai kem theo kenh");
        System.out.println("3.    Bat tivi");
        System.out.println("4.    Tat tivi");
        System.out.println("5.    Chuyen kenh tiep");
        System.out.println("6.    Chuyen kenh truoc");
        System.out.println("7.    Xem thong tin Tivi");
        System.out.println("8.    Ket thuc");
        System.out.println("Choose: ");
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

/**
 *
 * @author Diep.Tran
 */
public class CTivi {
    private String[] channelList;
    private boolean isOn;
    private String currentChannel;
    private int currentIndex = 0;

    public CTivi() {
        isOn = false;
        channelList = new String[]{"VTV1", "VTV2", "VTV3"};
        currentChannel = "VTV1";
        currentIndex = 0;
    }

    public CTivi(String[] channelList) {
        this.channelList = channelList;
        isOn = false;
        if(channelList.length > 0) {
            currentChannel = channelList[0];
            currentIndex = 0;
        }
    }
    
    private String searchNextChannel(boolean isForward) {
        if(channelList.length == 0) {
            return null;
        }
        
        if(isForward) {
            currentIndex++;
            if(currentIndex >= channelList.length) {
                currentIndex = 0;
            }
        } else {
            currentIndex--;
            if(currentIndex < 0) {
                currentIndex = channelList.length - 1;
            }
        }
        
        currentChannel = channelList[currentIndex];
        return currentChannel;
    }
    
    public void On() {
        isOn = true;
        System.out.println("--Tivi On--");
    }
    
    public void Off() {
        isOn = false;
        System.out.println("--Tivi Off--");
    }
    
    public void Switch() {
        if(isOn) {
            Off();
        } else {
            On();
        }
    }
    
    public void Switch(String channel) {
        Switch();
        if(isOn) {
            currentIndex = -1;
            for (int i = 0; i < channelList.length; i++) {
                if(channelList[i].equalsIgnoreCase(channel)) {
                    currentChannel = channelList[i];
                    currentIndex = i;
                    break;
                }
            }
            
            if(currentIndex == -1) {
                System.out.println("Khong tim thay kenh : " + channel);
            } else {
                System.out.println("Da tim thay kenh : " + channel);
            }
        }
    }
    
    public void nextChannel() {
        if(isOn) {
            searchNextChannel(true);
            System.out.println("Current Channel : " + currentChannel);
        }
    }
    
    public void previousChannel() {
        if(isOn) {
            searchNextChannel(false);
            System.out.println("Current Channel : " + currentChannel);
        }
    }
    
    public void Show() {
        if(isOn) {
            System.out.println("---Tivi is On at channel : " + currentChannel);
        } else {
            System.out.println("---- Tivi now OFF! ----");
        }
    }
}