Friday, September 23, 2016

Hello World in Many Ways


Terdapat banyak cara menampilkan "hello world" pada Java. Selain JOption yang sudah pernah diulas sebelumnya, ada cara lain yaitu seperti code di bawah ini:


public class HelloJava1 extends javax.swing.JComponent {
public static void main(String [] args) {
javax.swing.JFrame f = new javax.swing.JFrame("Hello Java1! ");
f.setSize(300, 300);
f.getContentPane().add(new HelloJava1());
f.setVisible(true);
}
public void paintComponent(java.awt.Graphics g) {
g.drawString("Hello World!", 125, 95);
}
}
view raw HelloJava1.java hosted with ❤ by GitHub
Lalu apa maksudnya deretan code tersebut?

 javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");

 javax.swing.JFrame merupakan suatu nama class yang dapat menampilkan halaman jendela pada layar (sebut saja nama kelas tersebut singkatnya JFrame). Kelas sendiri merupakan suatu template, blue print, seperti halnya rancangan gedung. new adalah kata kunci yang digunakan untuk memberikan informasi kepada Java agar mengalokasikan memori dan menginisialisaikan suatu objek baru bernama JFrame. 

f.setSize(300, 300); adalah ukuran jendela yang akan kita buat untuk bisa menampilkan "hello world". Dan ukurannya adalah sangat kecil.

f.getContentPane().add(new HelloJava1( )); maksudnya di dalam JFrame akan ditempatkan suatu objek bernama "HelloJava1"

f.setVisible(true); digunakan untuk menampilkan bingkai jendela beserta isinya karena main ( ) bertugas untuk menyembunyikan tampilan window, dan dengan perintah f.setVisible(true); maka tampilan akan keluar.

public void paintComponent(java.awt.Graphics g) {...} paint component merupakan method untuk memanggil jenis/tipe  Graphics yang disebut g

Hello World in Many Ways

Terdapat banyak cara menampilkan "hello world" pada Java. Selain JOption yang sudah pernah diulas sebelumnya, ada cara lain yaitu seperti code di bawah ini:


public class HelloJava1 extends javax.swing.JComponent {
public static void main(String [] args) {
javax.swing.JFrame f = new javax.swing.JFrame("Hello Java1! ");
f.setSize(300, 300);
f.getContentPane().add(new HelloJava1());
f.setVisible(true);
}
public void paintComponent(java.awt.Graphics g) {
g.drawString("Hello World!", 125, 95);
}
}
view raw HelloJava1.java hosted with ❤ by GitHub
Lalu apa maksudnya deretan code tersebut?

 javax.swing.JFrame f = new javax.swing.JFrame("HelloJava1");

 javax.swing.JFrame merupakan suatu nama class yang dapat menampilkan halaman jendela pada layar (sebut saja nama kelas tersebut singkatnya JFrame). Kelas sendiri merupakan suatu template, blue print, seperti halnya rancangan gedung. new adalah kata kunci yang digunakan untuk memberikan informasi kepada Java agar mengalokasikan memori dan menginisialisaikan suatu objek baru bernama JFrame. 

f.setSize(300, 300); adalah ukuran jendela yang akan kita buat untuk bisa menampilkan "hello world". Dan ukurannya adalah sangat kecil.

f.getContentPane().add(new HelloJava1( )); maksudnya di dalam JFrame akan ditempatkan suatu objek bernama "HelloJava1"

f.setVisible(true); digunakan untuk menampilkan bingkai jendela beserta isinya karena main ( ) bertugas untuk menyembunyikan tampilan window, dan dengan perintah f.setVisible(true); maka tampilan akan keluar.

public void paintComponent(java.awt.Graphics g) {...} paint component merupakan method untuk memanggil jenis/tipe  Graphics yang disebut g

Thursday, September 22, 2016

Menghitung berat dengan Java

Berikut ini adalah source code sederhana untuk menghitung berat di tempat yang berbeda. Massa benda akan tetap dimanapun berada, tetapi berat benda sangat bergantung kepada percepatan gravitasi di tempat tersebut.


class Beratku {
public static void main(String[] args) {
System.out.print("Massaku di bumi adalah " ); //beri spasi setelah kata adalah
double massa = 100 ;
System.out.println(massa);
System.out.print("Beratku di Bumi adalah " ); //beri spasi setelah kata adalah
double berat = massa*9.8 ;
System.out.println(berat);
System.out.print("Beratku di Planet A adalah " ); //beri spasi setelah kata adalah
double berat_a = massa*4.5 ; //misal gravitasi di planet A adalah 4,5 m/s2
System.out.println(berat_a);
}
}
view raw Beratku.java hosted with ❤ by GitHub

Friday, September 16, 2016

JOption Pane Untuk Program Input/output GUI Sederhana

JOptionPane merupakan class pada Java dibawah package javax.swing yang memungkinkan user untuk memasukan input dan menerima output.

import javax.swing.JOptionPane;
public class OperasiTambah {
public static void main(String args[]) {
String angkaPertama = JOptionPane.showInputDialog("Masukan angka pertama");
String angkaKedua = JOptionPane.showInputDialog("Masukan angka kedua");
//Konversi input string menjadi int
int angka1 = Integer.parseInt(angkaPertama);
int angka2 = Integer.parseInt(angkaKedua);
//Jumlahan dua bilangan bulat
int jumlah = angka1 + angka2;
//Tampilkan hasil dalam message dialog JOptionPane
JOptionPane.showMessageDialog(null, " Jumlah kedua angka adalah " + jumlah,
" Jumlah Dua Bilangan bulat ", JOptionPane.PLAIN_MESSAGE);
}
}




Monday, August 22, 2016

And I found programming is really fun. I hope one day this knowledge would give a benefit for me and hopefully for others :)

Tuesday, February 9, 2016

A simple code to see the IP address


#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\ipconfig");
return 0;
}
view raw ip-adress.c hosted with ❤ by GitHub

Wednesday, February 3, 2016


So this is the  code how to convert the Roman Numeral. I got from the book I learn about :)



#include<stdio.h>
main ()
{
int year;
printf("Ente years from 1 to 3999: ");
scanf("%d", &year);
if(year < 1 || year > 3999)
printf("year in 1 to 3999 years range");
else
{
while (year>= 1000)
{
printf("M");
year = year - 1000;
if (year>= 500)
{
if (year>= 900)
{
printf("CM");
year = year - 900;
}
else
{
printf("D");
year = year - 500;
}
}
while (year>= 100)
{
if (year>= 400)
{
printf("CD");
year = year - 400;
}
else
{
printf("C");
year = year - 500;
}
}
if (year>= 50)
{
if (year>= 90)
{
printf("XC");
year = year - 90;
}
else
{
printf("L");
year = year - 50;
}
}
while(year>=10)
{
if (year>= 40)
{
printf("XL");
year = year - 40;
}
else
{
printf("X");
year = year - 10;
}
}
if (year>=5)
{
if (year == 9)
{
printf("IX");
year = year - 9;
}
else
{
printf("V");
year = year - 5;
}
}
while(year>=1)
{
if (year==4)
{
printf("IV");
year = year - 4;
}
else
{
printf("I");
year = year - 1;
}
}
}
printf("\n");
}
}
view raw greek_num.c hosted with ❤ by GitHub

Thursday, January 28, 2016

Calculate The Depreciation with C

For my improvement, I follow the book that guide me into a topic of depreciation. The definition of depreciation itself: method of calculating the cost of tangible assets over it useful life.

For example, if a business purchases a delivery truch with a cost of Rp. 150.000.000 and it is expected to be used for 5 years. The business might have depreciation expense of expected years with the calculation :

first we sum of 5 years  :
 sum = 1+2+3+4+5=15 -->  15 can be formulated as 
 sum = n(n+1)/2
 n is for calculated years

The depreciation of every years can be like this:
  • depreciation of 1 years: 5/15*Rp. 150.000.000 =  Rp. 50.000.000
  • depreciation of 1 years: 4/15*Rp. 150.000.000 =  Rp. 40.000.000
  • depreciation of 1 years: 3/15*Rp. 150.000.000 =  Rp. 30.000.000
  • depreciation of 1 years: 2/15*Rp. 150.000.000 =  Rp. 20.000.000
  • depreciation of 1 years: 1/15*Rp. 150.000.000 =  Rp. 10.000.000

In this learn, We will make a code how to  make a list of depreciation as above 

Here is the code I adopted from C handbook:
     ------------------------------------------------------------

#include<stdio.h>

main ()

{
long int cost;
int i, sum, year;
double deprec;
printf("Cost: ");
scanf("%d", &cost);
printf("Year: ");
scanf("%d", &year);
sum = year * (year+1)/2;
for (i=1;i<=year;i++)
{
deprec = (year + 1.0 - i)/sum*cost;
printf("%2d %.0lf\n", i, deprec);
}
return 0;
}

-------------------------------------------------
The outcome:

Wednesday, January 27, 2016

This program will show a fibonanci series like  1 1 2 3 5 8 13 .......


#include<stdio.h>
int main ()
{
int fn, fn1, fn2;
fn1=1;
fn2=1;
printf("%4d", fn1);
printf("%4d", fn2);
fn=fn1+fn2;
while(fn<=200)
{
printf("%4d", fn);
fn2 = fn1;
fn1 = fn;
fn = fn1+fn2;
}
printf("\n");
return 0;
}
view raw fibonaci.c hosted with ❤ by GitHub

Tuesday, January 26, 2016

Calculator with C Language

Here I am with one program today :). And here is the code how to make simple calculator. Actually I copied the code from here, and tried to understand it. So simple and make sense. 
#include<stdio.h>
int main()
{
/*This is a calculator programme. Calculator is able to perform the operation of two numbers*/
int num;float a,b,c;
printf("Hello World this is a calculator ");
printf("\nchoose a number from the menu to operate the desired function");
printf("\npress 1 for addition\npress 2 for subtraction\npress 3 for multiplication\npress 4 for division \n");
scanf("%d",&num);
/*The operation is performed using the switch case method*/
switch(num)
{
case 1:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c= a+b;
printf("the addition of two numbers is %f",c);
break;
case 2:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a-b;
printf("the subtraction of two numbers is %f",c);
break;
case 3:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a*b;
printf("the multiplication of two numbers is %f",c);
break;
case 4:
printf("enter two numbers \n");
scanf("%f%f",&a,&b);
c=a/b;
printf("the division of two numbers is %f ",c);
}
}
view raw calculator.c hosted with ❤ by GitHub

Wednesday, January 20, 2016

It's been a while not to fill up this blog. By the way, I'm trying to collect some stuff in order to improve my C learning language.

Living in digital world and improving one of programming language is just like a need #programming #c #language

Foto kiriman Hani (read:honey) (@hanifadinna) pada

Here is the code:
#include<stdio.h>
main ()
{
float i, j, h;
printf("Enter the height of triangle: ");
scanf("%f", &h);
for(i=1;i<=h;i++)
{
for(j=1;j<=i;j++)
printf("*");
printf("\n"); // new line
}
return 0;
view raw triangle.c hosted with ❤ by GitHub