- Contoh program Biodata & hasil dari program Biodata:
/**
* Menampilkan biodata
*
* @author Alberto Sanjaya
* @version (a version number or a date)
*/
public class Biodata
{
public static void main (String[] args)
{
System.out.println ("############### Biodata ##############");
System.out.println ("\n");
System.out.println ("Nama : Alberto Sanjaya");
System.out.println ("NRP : 05111840000150");
System.out.println ("Kelas : PBO D");
System.out.println ("Departemen : Informatika");
System.out.println ("Asal : Bekasi");
}
}
Hasil dari Main program :
- Contoh dari program Waktu & hasil dari program
/**
* Write a description of class Time here.
*
* @author Alberto Sanjaya
* @version (a version number or a date)
*/
public class TimeTOT
{
// instance variables - replace the example below with your own
private int jam;
private int menit;
private int detik;
public void setTime(int j,int m,int d)
{
if ((j>=0 && j<24) &&(m>=0 &&m<60) && (d>=0 &&d<60))
{
jam=j;
menit = m;
detik = d;
}
else
{
throw new IllegalArgumentException("Jam/menit/detik salah");
}
}
public String toUniversalString()
{
return String.format ("%02d:%02d:%02d",jam,menit,detik);
}
public String toString()
{
return String.format("%d:%02d;%02d %s", ((jam==0 ||jam==12) ? 12: jam%12),menit,detik,jam<12? "AM" : "PM");
}
}
Untuk Main yang digunakan :
/**
* Write a description of class Timetest here.
*
* @author Alberto Sanjaya
* @version (a version number or a date)
*/
public class Timetest
{
public static void main(String[] args)
{
TimeTOT waktu = new TimeTOT();
System.out.print("Inisiasi Jam Dunia : ");
System.out.println(waktu.toUniversalString());
System.out.print("Inisiasi Jam Regional : ");
System.out.println(waktu.toString() );
System.out.println();
waktu.setTime(17,22,5);
System.out.print ("Waktu dunia setelah mengatur waktu :");
System.out.println(waktu.toUniversalString());
System.out.print ("Waktu regional setelah mengatur waktu :");
System.out.println(waktu.toString());
System.out.println();
try
{
waktu.setTime(60,55,71);
}
catch (IllegalArgumentException e)
{
System.out.printf("Pengecualian :%s\n\n",e.getMessage());
}
System.out.println("Setelah mencoba setting gagal :");
System.out.print("Waktu Dunia : ");
System.out.println(waktu.toUniversalString());
System.out.print("Waktu Lokal : ");
System.out.println(waktu.toString());
}
}
Dan Hasilnya :
Comments