jam digital

20.21 viia 0 Comments

import javax.swing.*;

import java.awt.event.*;

import java.util.Date;

import java.awt.*;

class modulno3
extends JFrame {

// Deklarasi komponen Label

JLabel tampil_jam = new JLabel();

// Konstruktor

public modulno3() {

tampil_jam.setFont(new Font("Dialog", 1, 30));

this.getContentPane().setLayout(new FlowLayout());

this.getContentPane().add(tampil_jam);

// ActionListener untuk Keperluan Timer

ActionListener taskPerformer = new ActionListener() {

@Override
public void actionPerformed( ActionEvent evt) {

String nol_jam = "";

String nol_menit = "";

String nol_detik = "";

// Membuat Date

Date dt = new Date();

// Mengambil nilaj JAM, MENIT, dan DETIK Sekarang

int nilai_jam = dt.getHours();

int nilai_menit = dt.getMinutes();

int nilai_detik = dt.getSeconds();

// Jika nilai JAM lebih kecil dari 10 (hanya 1 digit)

if (nilai_jam <= 9) {

// Tambahkan “0? didepannya

nol_jam = "0";

}

// Jika nilai MENIT lebih kecil dari 10 (hanya 1 digit)

if (nilai_menit <= 9) {

// Tambahkan “0? didepannya

nol_menit = "0";

}

// Jika nilai DETIK lebih kecil dari 10 (hanya 1 digit)
if (nilai_detik <= 9) {
// Tambahkan “0? didepannya
nol_detik = "0";

}

// Membuat String JAM, MENIT, DETIK

String jam = nol_jam + Integer.toString(nilai_jam);
String menit = nol_menit + Integer.toString(nilai_menit);
String detik = nol_detik + Integer.toString(nilai_detik);
// Menampilkan pada Layar
tampil_jam.setText(" " + jam + " : " + menit + " : " + detik + " ");

}

};

// Timer

new Timer(1000, taskPerformer).start();

}

// MAIN

public static void main(String[] args) {

modulno3 jd = new modulno3();

jd.setTitle("Jam Digital");

jd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jd.setSize(200, 90);

jd.show();
String nama = JOptionPane.showInputDialog("Masukkan data nama anda");
String Time = null;

// Double jm=Double.parseDouble(Time);

String keterangan;
double jam = 0;
if(jam >= 00.01 && jam <= 10.00){
keterangan = "Sekarang sudah pagi";
}
else if(jam>=10.01 && jam <= 15.00){
keterangan = "Sekarang sudah siang";
}
else if(jam >= 15.01 && jam <= 18.00){
keterangan = "Sekarang sudah sore";
}
else{keterangan = "Sekarang sudah malam waktunya tidur.. :D";}

JOptionPane.showMessageDialog(null,nama+","+keterangan);

}
}



sesuaikan class

0 komentar:

upper case

20.18 viia 0 Comments

import javax.swing.*;
import java.util.Scanner;
class uppercase {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("masukkan kata:");
String kata=s.nextLine();
String input=JOptionPane.showInputDialog("Masukan Agka :");
int bilangan=Integer.valueOf(input);
int angka;
int huruf=0;
int jumlahkata=kata.length();
for (int i=0;i
{
char karakter=kata.charAt(i);

if(Character.isLowerCase(karakter)==false && kata !=" ")
{
System.out.println("huruf besar "+karakter);
huruf+=1;
}

}

System.out.println("jadi jumlah huruf besar "+huruf);
System.out.println("jadi jumlah kata:"+jumlahkata);
System.out.println("Program Penentu Bilangan Ganjil - Genap");
if (bilangan%2==0)
System.out.println("Angka "+ bilangan +" = Bilangan Genap"); // menampilkan apabila bilangan Genap
else
System.out.println("Angka "+ bilangan +" = Bilangan Ganjil"); // menampilkan apabila bilangan Ganjil
}
}

0 komentar:

calculator

19.54 viia 0 Comments

Public Class FormCalculator

Dim sign_Indicator As Integer = 0
Dim variable1 As Double
Dim variable2 As Double
Dim addBit As Integer = 0
Dim subBit As Integer = 0
Dim multBit As Integer = 0
Dim divBit As Integer = 0
Dim modBit As Integer = 0
Dim powerBit As Integer = 0
Dim permBit As Integer = 0
Dim combBit As Integer = 0
Dim andBit As Integer = 0
Dim orBit As Integer = 0
Dim xorBit As Integer = 0
Dim powerFunctionBit As Integer = 0
'Dim trigFunctionBit As Integer = 0
'Dim HypertrigFunctionBit As Integer = 0
'Dim InversetrigFunctionBit As Integer = 0
'Dim otherFuncsBit As Integer = 0
'Dim logicalFuncsBit As Integer = 0
' Dim memFuncsBit As Integer = 0
Dim fl As Integer = 0
Dim memoryVariable As Double = 0
'Dim scientificModeBit As Integer = 0

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(0)
ElseIf sign_Indicator = 1 Then
displayText.Text = 0
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(1)
ElseIf sign_Indicator = 1 Then
displayText.Text = 1
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(2)
ElseIf sign_Indicator = 1 Then
displayText.Text = 2
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(3)
ElseIf sign_Indicator = 1 Then
displayText.Text = 3
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(4)
ElseIf sign_Indicator = 1 Then
displayText.Text = 4
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(5)
ElseIf sign_Indicator = 1 Then
displayText.Text = 5
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(6)
ElseIf sign_Indicator = 1 Then
displayText.Text = 6
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(7)
ElseIf sign_Indicator = 1 Then
displayText.Text = 7
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(8)
ElseIf sign_Indicator = 1 Then
displayText.Text = 8
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
If sign_Indicator = 0 Then
displayText.Text = displayText.Text & CStr(9)
ElseIf sign_Indicator = 1 Then
displayText.Text = 9
sign_Indicator = 0
End If
fl = 1
End Sub

Private Sub displayText_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles displayText.KeyPress
e.Handled = True
If e.KeyChar Like "[0-9]" Or e.KeyChar = Chr(&H8) Then
e.Handled = False
End If
End Sub

Private Sub btnSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSign.Click
If displayText.Text.Length = 0 Then
displayText.Text = displayText.Text + CStr("-")
ElseIf displayText.Text <> "." Then
displayText.Text = displayText.Text * -1
End If
End Sub

Private Sub btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click
displayText.Clear()
sign_Indicator = 0
variable1 = 0
variable2 = 0
memoryVariable = 0
reset_SignBits()
End Sub

Private Sub btnClearTextbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearTextbox.Click
displayText.Clear()
End Sub
Private Function reset_SignBits()
addBit = 0
subBit = 0
multBit = 0
divBit = 0
modBit = 0
powerBit = 0
permBit = 0
combBit = 0
andBit = 0
orBit = 0
xorBit = 0
fl = 0
Return 0
End Function

Private Function permutation(ByVal variable1, ByVal variable2)
Dim result As Double
result = Factorial(variable1) / Factorial(variable1 - variable2)
Return result
End Function

Private Function combination(ByVal variable1, ByVal variable2)
Dim result As Double
result = Factorial(variable1) / (Factorial(variable2) * Factorial(variable1 - variable2))
Return result
End Function
Private Function Calculate()
If displayText.Text <> "." Then

variable2 = displayText.Text
If fl = False Then
variable1 = variable2
ElseIf addBit = 1 Then
variable1 = variable1 + variable2
ElseIf subBit = 1 Then
variable1 = variable1 - variable2
ElseIf multBit = 1 Then
variable1 = variable1 * variable2
ElseIf divBit = 1 Then
variable1 = variable1 / variable2
ElseIf modBit = 1 Then
variable1 = variable1 Mod variable2
ElseIf powerBit = 1 Then
variable1 = Math.Pow(variable1, variable2)
ElseIf permBit = 1 Then
variable1 = permutation(variable1, variable2)
ElseIf combBit = 1 Then
variable1 = combination(variable1, variable2)
ElseIf andBit = 1 Then
variable1 = variable1 And variable2
ElseIf orBit = 1 Then
variable1 = variable1 Or variable2
ElseIf xorBit = 1 Then
variable1 = variable1 Xor variable2
Else
variable1 = variable2
End If
displayText.Text = CStr(variable1)

End If
Return 0
End Function

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
addBit = 1
sign_Indicator = 1
End If
End Sub

Private Sub btnSub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSub.Click

If displayText.Text.Length <> 0 Then
variable2 = displayText.Text
Calculate()
reset_SignBits()
subBit = 1
sign_Indicator = 1
End If
End Sub

Private Sub btnMult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMult.Click
If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
multBit = 1
sign_Indicator = 1
End If
End Sub

Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiv.Click
If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
divBit = 1
sign_Indicator = 1
End If
End Sub

Private Sub btnModulus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModulus.Click
If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
modBit = 1
sign_Indicator = 1
End If
End Sub

Private Sub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click
If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
powerBit = 1
sign_Indicator = 1
End If
End Sub
Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click

If displayText.Text.Length <> 0 Then
Calculate()
reset_SignBits()
End If
sign_Indicator = 1
End Sub

Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click
Dim i As Integer
Dim chr As Char
Dim decimal_Indicator As Integer = 0

If sign_Indicator <> 1 Then
For i = 0 To displayText.Text.Count - 1
chr = displayText.Text(i)
If chr = "." Then
decimal_Indicator = 1
End If
Next

If decimal_Indicator <> 1 Then
displayText.Text = displayText.Text & CStr(".")
End If
End If
End Sub

Private Sub btnBackSpace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackSpace.Click
If displayText.Text.Length <> 0 Then
displayText.Text = displayText.Text.Remove(displayText.Text.Length - 1, 1)
End If
End Sub














Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsqrt.Click
If displayText.Text.Length <> 0 Then
If displayText.Text <> "." Then
displayText.Text = Math.Sqrt(displayText.Text)
End If
sign_Indicator = 1
End If
End Sub

Public Function Factorial(ByVal temp)
Dim result As Double = temp
If temp = 0 Then
Return 1
Else
For i = temp - 1 To 1 Step -1
result = result * i
Next
End If
Return result
End Function

Private Sub btnSquare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSquare.Click
If displayText.Text.Length <> 0 Then
displayText.Text = displayText.Text * displayText.Text
End If
sign_Indicator = 1
End Sub

Private Sub btnCube_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCube.Click
If displayText.Text.Length <> 0 Then
displayText.Text = displayText.Text * displayText.Text * displayText.Text
End If
sign_Indicator = 1
End Sub

Private Sub btnxPower4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnxPower4.Click
If displayText.Text.Length <> 0 Then
displayText.Text = displayText.Text * displayText.Text * displayText.Text * displayText.Text
End If
sign_Indicator = 1
End Sub

Private Sub btnM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnM.Click
If displayText.Text.Length <> 0 Then
If memoryVariable = 0 Then
memoryVariable = CDbl(displayText.Text)
End If
End If
sign_Indicator = 1
displayText.Text = CStr(memoryVariable)
End Sub

Private Sub btnMplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMplus.Click
If memoryVariable <> 0 Then
memoryVariable = memoryVariable + memoryVariable
End If
sign_Indicator = 1
displayText.Text = CStr(memoryVariable)
End Sub

Private Sub btnMminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMminus.Click
If memoryVariable <> 0 Then
memoryVariable = memoryVariable - memoryVariable
End If
sign_Indicator = 1
displayText.Text = CStr(memoryVariable)
End Sub
End Class

0 komentar: