Skip to content

Instantly share code, notes, and snippets.

View swarawan's full-sized avatar

Rio Swarawan Putra swarawan

  • Jakarta, Indonesia
View GitHub Profile
Kalkulator
Nilai 1 : <inputA> // 5
Nilai 2 : <inputB> // 2
Pilih Operator:
1. Tambah
2. Kurang
3. Kali
4. Bagi
Pilihan (1..4) : <inputOperator> // 1
Buat sistem lift
- ada 20 lantai
- posisi pemain ada di lantai `x`
- pemain ingin ke lantai `y`
Soal:
gambarkan alur lift tersebut.
Contoh:
posisi pemain = 5
@swarawan
swarawan / Sistem Parkir
Last active March 9, 2018 15:11
Belajar menggunakan kondisi (decision) dan perulangan (loop)
total roda <= 2 -> lahan parkir sebelah kiri
total roda > 2 <=4 -> lahan parkir sebelah kanan
total roda > 4 -> basement
check here -> https://github.com/swarawan/batch-6-java-basic.git
/**
* Return string formatted with dot separator and prepended with currency
* symbol (IDR). By default will return Rp 0.
*
* @param defaultOutput Default string to return (with currency prefix) when error happen.
*/
@NonNull
public static final String formatCurrency(@Nullable BigDecimal input, @NonNull String defaultOutput) {
if (input == null)
return defaultOutput;
@swarawan
swarawan / Get Duration
Created September 14, 2017 01:12
Get duration depend on inserted Date.
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;
long diffMonth = diff / (30 * 24 * 60 * 60 * 1000);
@swarawan
swarawan / DateUtils.java
Created June 19, 2017 05:30
Pretty date format to get duration.
public class DateUtils {
public static String getDurationDate(Date date) {
Date today = new Date();
long diff = today.getTime() - date.getTime();
long diffSeconds = diff / 1000 % 60;
long diffMinutes = diff / (60 * 1000) % 60;
long diffHours = diff / (60 * 60 * 1000) % 24;
long diffDays = diff / (24 * 60 * 60 * 1000) % 30;
long diffWeeks = diff / (30 * 24 * 60 * 60 * 1000) / 4;