//ButtontoRoman.class Java Applet //Prepared by ... at ... on .... import java.awt.*; import java.applet.*; public class ButtontoRoman extends Applet { private int dig; private int Total; private int Arabic; private String Roman; public void start() { Arabic=0; digit_in(dig); } public void digit_in(int digit_clicked) { dig=digit_clicked; Arabic=Arabic*10+dig; Total=Arabic; Roman=""; Arabic_to_Roman(); repaint(); } public void Arabic_to_Roman() { String[] T_Roman = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"}; int[] T_Arabic= {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; //All alert objects used here are optional and for purpose of testing only //This part contains the algorithm of converting Arabic numbers into Roman: int i; i=0; int count = 13; while (i < count) { //alert ("Counter is " + i) if (Total >= T_Arabic[i]) { //This part converts Arabic into Roman Total = Total - T_Arabic[i]; Roman=Roman+T_Roman[i]; //alert ("Roman = " + Roman + ", Reaminder = " + Total); //i=i-1; } else { i=i+1; } } } public void paint(Graphics g) { setBackground(new Color(0x0000FF)); g.setFont(new Font("TimesRoman",Font.BOLD+Font.ITALIC,48)); g.setColor(Color.red); g.drawString("Digit just pressed = "+dig,40,80); g.drawString("Arabic number = "+Arabic,40,140); g.drawString("Roman = "+Roman,40,200); } }