Skip to main content

Clock

Pembuatan Clock menggunakan BlueJ

Class yang digunakan sebagai berikut :

  1. Main Clock : digunakan sebagai penghubung antara NumberDisplay dan ClockMechanics
  2. NumberDisplay : digunakan sebagai format output number pada jam
  3. ClockMechanics : digunakan sebagai pengatur mekanisme jam
Main Clock Source Code

import java.util.concurrent.TimeUnit;
/**
 * MainClock class as connector NumberDisplay and ClockMechanics class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class MainClock
{
    NumberDisplay numberobj = new NumberDisplay();
    ClockMechanics clockobj = new ClockMechanics();
    int Marker = 0;
    private String[] time_now = {"","","","","","",""};
    private String[] converter = new String[7];
    public MainClock()
    {
        while(true)
        {
                Reset();
                clockobj.UpdateTime();
                SetTime();
                Print();
             

        }

    }
 
    public void Reset()
    {
        for(int a = 0; a < 7; a++)
        {
            time_now[a] = "";
        }
    }
 
    public void Print()
    {
        for(int a = 0; a < 7; a++)
        {
            if(time_now[a]!=null)
            {
                System.out.println(time_now[a]);
            }
        }
     
        System.out.println("                                                          " + (clockobj.GetMonth()+1) + "/" + clockobj.GetDay() + "/" + clockobj.GetYear());
    }
 
    public void ConvertNumber(int x)
    {
        converter = numberobj.ChooseNumber(x);
        Marker++;
        for(int a = 0; a < 7; a++)
        {
            if((a == 2 || a == 4) && (Marker == 2 || Marker == 4))
            {
                time_now[a] += converter[a] + "█";
       
            }
            else
            {
                time_now[a] += converter[a] + "░";
            }
        }
    }
 
    public void SetTime()
    {
        int seconddigit1 = clockobj.GetSecond()%10;
        int seconddigit2 = (clockobj.GetSecond()/10)%10;
        int minutedigit1 = clockobj.GetMinute()%10;
        int minutedigit2 = (clockobj.GetMinute()/10)%10;
        int hourdigit1 = clockobj.GetHour()%10;
        int hourdigit2 = (clockobj.GetHour()/10)%10;
     
        ConvertNumber(hourdigit2);
        ConvertNumber(hourdigit1);
        ConvertNumber(minutedigit2);
        ConvertNumber(minutedigit1);
        ConvertNumber(seconddigit2);
        ConvertNumber(seconddigit1);
        Marker = 0;
    }
}


Number Display Source Code


/**
 * NumberDisplay as a formatting output class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class NumberDisplay
{
    //Pallet ░▒▓█■▄▀
 
    public String[] ChooseNumber(int Number)
    {
        String[] SevenSegment = new String[7];
        switch(Number)
        {
            case 0:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░██░░░██░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 1:
            SevenSegment[0] = "░░░░░░██░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░░░░░░██░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 2:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░░░░";
            SevenSegment[5] = "░██░░░░░░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 3:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 4:
            SevenSegment[0] = "░██░░░██░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 5:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░░░░";
            SevenSegment[2] = "░██░░░░░░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 6:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░░░░";
            SevenSegment[2] = "░██░░░░░░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 7:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░░░░░░██░";
            SevenSegment[2] = "░░░░░░██░";
            SevenSegment[3] = "░░░░░░██░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░░░░░░██░";
            break;
         
            case 8:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░██░░░██░";
            SevenSegment[5] = "░██░░░██░";
            SevenSegment[6] = "░███████░";
            break;
         
            case 9:
            SevenSegment[0] = "░███████░";
            SevenSegment[1] = "░██░░░██░";
            SevenSegment[2] = "░██░░░██░";
            SevenSegment[3] = "░███████░";
            SevenSegment[4] = "░░░░░░██░";
            SevenSegment[5] = "░░░░░░██░";
            SevenSegment[6] = "░███████░";
        }
     
        return SevenSegment;
    }
}


Clock Mechanics Source Code

import java.util.*;
/**
 * ClockMechanics as clock algorithm class
 *
 * @author Satria Ade Veda Karuniawan
 * @version Version 1.0
 */
public class ClockMechanics
{
    GregorianCalendar date = new GregorianCalendar();
    private int day, month, year;
    private int second, minute, hour;
 
    public ClockMechanics()
    {
        second = date.get(Calendar.SECOND);
        minute = date.get(Calendar.MINUTE);
        hour = date.get(Calendar.HOUR);

        day = date.get(Calendar.DAY_OF_MONTH);
        month = date.get(Calendar.MONTH);
        year = date.get(Calendar.YEAR);
    }
 
    public void UpdateTime()
    {
     
     
        second++;
        if(second == 60)
        {
            second = 0;
            minute++;
        }
     
        if(minute == 60)
        {
            minute = 0;
            hour++;
        }
     
        if(hour == 12)
        {
            hour = 0;
        }
        try
            {
                Thread.sleep(1000);
            } catch(InterruptedException e)
            {
             
            }
     
        System.out.print('\u000C');
    }
 
 
    public int GetSecond()
    {
        return second;
    }
 
    public int GetMinute()
    {
        return minute;
    }
 
    public int GetHour()
    {
        return hour;
    }
 
    public int GetDay()
    {
        return day;
    }
 
    public int GetMonth()
    {
        return month;
    }
 
    public int GetYear()
    {
        return year;
    }
}

Workspace



Untuk keluar dari program setelah dijalankan

  1. Membuka tab View pada window BlueJ
  2. Pilih show Debugger (dapat melalui shortcut CTRL + D)
  3. Pilih Threads main
  4. Tekan tombol Terminate
Tampilan saat program dijalankan (Membuat object MainClock)


Comments

Popular posts from this blog

Technical Support AI

Technical Support - Artificial Intelligence (*From now on, I'll try my best to explain about all of my Project using English) For this project, I made 3 classes to control the Bot Mechanism (Referencing to Objects-First-with-Java-A-Practical-Introduction-Using-BlueJ-David-J-Barnes pages 155) : InputReader Class (Used for detect or to take any user input) SupportSystem Class (As a main function connecting the user input and database) Responder Class (Handling AI-Output and Its role as 'mini' database) Current Version : 1.2 In the future, I'm expecting to have a bigger Responder's Database and would be separated from the Class itself, so it will be easier to make some modification inside the AI's Database and easier to manage. And then i'll try to improve the UX Design inside, so that the user can have a feeling about how 'Human' this AI. InputReader Class In this class, pretty much the same as how the name of the class is writt...

Fox And Rabbit

Implementasi Fox and Rabbit berupa simulasi hubungan antara predator (dalam hal ini Fox) dan prey (dalam hal ini Rabbit), digunakan 9 class : Simulator (sebagai class utama yang digunakan untuk melakukan simulasi) SimulatorView (sebagai pengatur tampilan yang diimplementasikan pada class Simulator) Field (sebagai class yang mengatur dan memanipulasi bidang simulasi yang telah ditentukan) FieldStats (sebagai class berupa value holder yang menyimpan kondisi dari Field) Counter (sebagai class penghitung seperti increment dan reset value) Location (sebagai class yang memiliki informasi posisi pada Field) Randomizer (sebagai class yang mengatur nilai random) Fox (sebagai class simulator yang bertindak sebagai predator) Rabbit (sebagai class simulator yang bertindak sebagai prey) Source Code Simulator import java.util.Random; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.awt.Color; import java.util.concurrent.TimeUnit; impo...

Ticketing Machine

Pembuatan simulasi Ticketing Machine menggunakan OOP Class yang digunakan di dalam Project terdiri atas : Main class TicketMachine class Destination class Library yang digunakan di dalam Project adalah java.util.Scanner Source code Destination class /**  * A class which describes Destination  *  * @author Satria Ade Veda Karuniawan  * @version version 1.0  */ public class Destination {     private String Station;     private int PriceAdult;     private int PriceChild;     //Struct destination       public Destination(String name)     {         Station = name;         PriceAdult = 0;         PriceChild = 0;     }       public void SetInfo(int pa, int pc)     {         PriceAdult = pa;         PriceChild = pc;   ...