0% found this document useful (0 votes)
121 views7 pages

Konversi Desimal ke Romawi dalam Java

This document contains code for several Java programs: 1. A program that converts decimal numbers to Roman numerals by using arrays to store the Roman numeral values and conditionals to determine the proper concatenation based on the decimal number. 2. A similar program that converts decimals to Roman numerals without arrays by using conditionals and concatenation. 3. A cash register program that takes the price and quantity of an item as input, calculates the total, and then applies a discount based on the total amount to output the final price.

Uploaded by

Sunarya Raya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views7 pages

Konversi Desimal ke Romawi dalam Java

This document contains code for several Java programs: 1. A program that converts decimal numbers to Roman numerals by using arrays to store the Roman numeral values and conditionals to determine the proper concatenation based on the decimal number. 2. A similar program that converts decimals to Roman numerals without arrays by using conditionals and concatenation. 3. A cash register program that takes the price and quantity of an item as input, calculates the total, and then applies a discount based on the total amount to output the final price.

Uploaded by

Sunarya Raya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

*;

class DeretBilangan

public static void main(String[]args)throws Exception


{
BufferedReader kata = new BufferedReader(new InputStreamReader([Link]));

[Link](" Masukkan Jumlah Deret: ");


int deret =[Link]([Link]());
String hasil = "";
for (int i = 1 ;i<= deret ;i++ )

for (int j = 1;j<= i ;j++ )

hasil = hasil+j;

hasil = hasil+"\n";

}
[Link](hasil);

}
}

import [Link].*;

public class KonversiDesimalToRomawi {


public static void main (String args[])
{
int bil;
String tampil="";

//inisialisasi berupa array


String [] biasa = {"","I","II", "III", "IV", "V",
"VI", "VII", "VIII", "IX"};
String [] sepuluh = {"", "X", "XX","XXX","XL"};
String [] limapuluh = {"", "L", "LX", "LXX", "LXXX","XC"};
String [] seratus = {"", "C", "CC", "CCC", "CD"};
String [] limaratus = {"", "D", "DC", "DCC", "DCCC", "CM"};
String [] seribu = {"", "M", "MM", "MMM", "Mv", "v"};

// inputan dari keyboard


[Link]("Masukkan bilangan desimal : ");
Scanner obj = new Scanner([Link]);
bil = [Link]();

//kondisi dimana angka tdk lebih dari 5000


if (bil>5000)
{
[Link]("Maaf.., Angka Desimal Yang Di "+
"Inputkan Harus Di Bawah 5000");

}
else
{
//defenisi
int lmrts = bil % 1000;
int srts = lmrts % 500;
int lmpl = srts % 100;
int spl = lmpl % 50;
int ak = spl % 10;

int a = bil/1000;
tampil += ""+seribu[a];

//aturan konversi desimal ke romawi


if ( (lmrts >=900) && (lmrts <= 999))
{
tampil += "CM";

//90
if( (lmpl >= 90) && (lmpl <= 99) )
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}

}
else
{
int b = lmrts/500;
tampil += ""+limaratus[b];

//400
if ( (srts >= 400)&& (srts <= 499) )
{
tampil += "CD";

//90
if( (lmpl >= 90) && (lmpl <= 99) )
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}

}
else
{
int c = srts/100;
tampil += ""+seratus[c];
if((lmpl >= 90)&&(lmpl <= 99))
{
tampil += "XC";
int f= ak/1;
tampil += ""+biasa[f];
}
else
{
int d = lmpl/50;
tampil += ""+limapuluh[d];
int e = spl/10;
tampil += ""+sepuluh[e];
int f= ak/1;
tampil += ""+biasa[f];
}
}
}
[Link]("Maka angka Romawinya "+tampil);

}
}

Coding Program bisa di download di sini

Program ke dua
import [Link].*;

public class konversi


{
public static void main (String[]args)
{
InputStreamReader in= new InputStreamReader ([Link]);
BufferedReader rd = new BufferedReader(in);

String input=null;
int angka=0;

try
{
[Link]("Masukkan Bilangan Bulat anda: ");
input=[Link]();

angka = [Link](input);

if(angka<1||angka>5000)
{
[Link]("Tahun harus dalam jangkuan 1....5000");
}
else{
while (angka>=1000){
[Link]("M");
angka=angka-1000;
}
if (angka>=500){
if(angka>=900){
[Link]("CM");
angka=angka-900;
}
else{
[Link]("D");
angka=angka-500;
}
}
while (angka>=100){
if(angka>=400){
[Link]("CD");
angka=angka-400;
}
else{
[Link]("C");
angka=angka-100;
}
}
if(angka>=50){
if(angka>=90){
[Link]("XC");
angka=angka-90;
}
else{
[Link]("L");
angka=angka-50;
}
}
while(angka>=10){
if(angka>=40){
[Link]("XL");
angka=angka-40;
}
else{
[Link]("X");
angka=angka-10;
}
}
if(angka>=5){
if(angka==9){
[Link]("IX");
angka=angka-9;
}
else{
[Link]("V");
angka=angka-5;
}
}
while(angka>=1){
if(angka==4){
[Link]("IV");
angka=angka-4;
}
else{
[Link]("I");
angka=angka-1;
}
}
}

{
[Link]("");
}
}
catch(IOException ioe)
{
[Link]([Link]());
[Link](1);
}
catch(NumberFormatException nfe)
{
[Link]([Link]());
[Link](1);
}
}
}

import [Link].*;
public class ProgramKasir
{
public static void main(String args[])throws IOException
{
//membuat turunan class untuk input dari user
BufferedReader dataIn=new BufferedReader(new InputStreamReader([Link]));
[Link]("Berapa Harga Barang :");
int a = [Link]([Link]());
[Link]("Berapa Jumlah Barang yang diambil:");
int b = [Link]([Link]());
int total =(a*b);

[Link]("Harga barang = Rp "+a);


[Link]("Jmlah barang = "+b);

[Link]("Total harga sebelum diskon =Rp"+total);


if(total>10000 & total<=100000)
{
[Link]("Total harga yang harus dibayar (setelah diskon) =Rp ");
[Link](total-(total * 0));
}
else if(total>100000 & total<=500000)
{
[Link]("Total harga yang harus dibayar (setelah diskon) =Rp ");
[Link](total-(total * 0.05));
}
else if(total>500000 & total<=1000000)
{
[Link]("Total harga yang harus dibayar (setelah diskon) =Rp ");
[Link](total-(total * 0.1));
}
else
{
[Link]("Total harga yang harus dibayar (setelah diskon) =Rp ");
[Link](total-(total * 0.15));
}

}
}

You might also like