import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.lang.String; public class Roomanumbrid extends Applet implements ActionListener{ TextField tf=new TextField(10); TextField tf2=new TextField(10); Label silt1, silt2; Button bt=new Button("Teisenda"); public Roomanumbrid(){ setLayout(new BorderLayout()); Panel p=new Panel(new GridLayout(2, 2)); p.add(silt1=new Label("Sisesta arv:")); p.add(tf); p.add(silt2=new Label("Roomanumber:")); p.add(tf2); add(p, BorderLayout.CENTER); Panel p2=new Panel(); p2.add(bt); bt.addActionListener(this); add(p2, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e){ String arv; String yhed[]={"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; String kymned[]={"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String sajad[]={"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String tuhanded[]={"M", "MM"}; String lnyhed[]={"1", "2", "3", "4", "5", "6", "7", "8", "9"}; String lnkymned[]={"10", "20", "30", "40", "50", "60", "70", "80", "90"}; String lnsajad[]={"100", "200", "300", "400", "500", "600", "700", "800", "900"}; String lntuhanded[]={"1000", "2000"}; String roomanumber=""; arv=tf.getText(); if(arv.length()==4){ if(arv.substring(0,1).equals("1"))roomanumber=roomanumber+tuhanded[0]; if(arv.substring(0,1).equals("2"))roomanumber=roomanumber+tuhanded[1]; if(arv.substring(1,2).equals("1"))roomanumber=roomanumber+sajad[0]; if(arv.substring(1,2).equals("2"))roomanumber=roomanumber+sajad[1]; if(arv.substring(1,2).equals("3"))roomanumber=roomanumber+sajad[2]; if(arv.substring(1,2).equals("4"))roomanumber=roomanumber+sajad[3]; if(arv.substring(1,2).equals("5"))roomanumber=roomanumber+sajad[4]; if(arv.substring(1,2).equals("6"))roomanumber=roomanumber+sajad[5]; if(arv.substring(1,2).equals("7"))roomanumber=roomanumber+sajad[6]; if(arv.substring(1,2).equals("8"))roomanumber=roomanumber+sajad[7]; if(arv.substring(1,2).equals("9"))roomanumber=roomanumber+sajad[8]; if(arv.substring(2,3).equals("1"))roomanumber=roomanumber+kymned[0]; if(arv.substring(2,3).equals("2"))roomanumber=roomanumber+kymned[1]; if(arv.substring(2,3).equals("3"))roomanumber=roomanumber+kymned[2]; if(arv.substring(2,3).equals("4"))roomanumber=roomanumber+kymned[3]; if(arv.substring(2,3).equals("5"))roomanumber=roomanumber+kymned[4]; if(arv.substring(2,3).equals("6"))roomanumber=roomanumber+kymned[5]; if(arv.substring(2,3).equals("7"))roomanumber=roomanumber+kymned[6]; if(arv.substring(2,3).equals("8"))roomanumber=roomanumber+kymned[7]; if(arv.substring(2,3).equals("9"))roomanumber=roomanumber+kymned[8]; if(arv.substring(3,4).equals("1"))roomanumber=roomanumber+yhed[0]; if(arv.substring(3,4).equals("2"))roomanumber=roomanumber+yhed[1]; if(arv.substring(3,4).equals("3"))roomanumber=roomanumber+yhed[2]; if(arv.substring(3,4).equals("4"))roomanumber=roomanumber+yhed[3]; if(arv.substring(3,4).equals("5"))roomanumber=roomanumber+yhed[4]; if(arv.substring(3,4).equals("6"))roomanumber=roomanumber+yhed[5]; if(arv.substring(3,4).equals("7"))roomanumber=roomanumber+yhed[6]; if(arv.substring(3,4).equals("8"))roomanumber=roomanumber+yhed[7]; if(arv.substring(3,4).equals("9"))roomanumber=roomanumber+yhed[8]; if((arv.substring(2,3).equals("4"))&&(arv.substring(3,4).equals("9")))roomanumber=roomanumber+"IL"; if((arv.substring(2,3).equals("9"))&&(arv.substring(3,4).equals("9")))roomanumber=roomanumber+"IC"; if((arv.substring(1,2).equals("4"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"XC"; if((arv.substring(1,2).equals("4"))&&(arv.substring(2,3).equals("9"))&&(arv.substring(3,4).equals("9")))roomanumber=roomanumber+"XD"; if((arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"XM"; if((arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9"))&&(arv.substring(3,4).equals("9")))roomanumber=roomanumber+"IM"; tf2.setText("" +roomanumber); } if(arv.length()==3){ if((arv.substring(1,2).equals("4"))&&(arv.substring(2,3).equals("9")) || (arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")) || (arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9")) || (arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")) || (arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9")) || (arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9"))){ if((arv.substring(1,2).equals("4"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"IL"; if((arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"IC"; if((arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9")))roomanumber=roomanumber+"XC"; if((arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"XD"; if((arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9")))roomanumber=roomanumber+"XM"; if((arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9"))&&(arv.substring(2,3).equals("9")))roomanumber=roomanumber+"IM"; tf2.setText("" +roomanumber); }else{ if(arv.substring(0,1).equals("1"))roomanumber=roomanumber+sajad[0]; if(arv.substring(0,1).equals("2"))roomanumber=roomanumber+sajad[1]; if(arv.substring(0,1).equals("3"))roomanumber=roomanumber+sajad[2]; if(arv.substring(0,1).equals("4"))roomanumber=roomanumber+sajad[3]; if(arv.substring(0,1).equals("5"))roomanumber=roomanumber+sajad[4]; if(arv.substring(0,1).equals("6"))roomanumber=roomanumber+sajad[5]; if(arv.substring(0,1).equals("7"))roomanumber=roomanumber+sajad[6]; if(arv.substring(0,1).equals("8"))roomanumber=roomanumber+sajad[7]; if(arv.substring(0,1).equals("9"))roomanumber=roomanumber+sajad[8]; if(arv.substring(1,2).equals("1"))roomanumber=roomanumber+kymned[0]; if(arv.substring(1,2).equals("2"))roomanumber=roomanumber+kymned[1]; if(arv.substring(1,2).equals("3"))roomanumber=roomanumber+kymned[2]; if(arv.substring(1,2).equals("4"))roomanumber=roomanumber+kymned[3]; if(arv.substring(1,2).equals("5"))roomanumber=roomanumber+kymned[4]; if(arv.substring(1,2).equals("6"))roomanumber=roomanumber+kymned[5]; if(arv.substring(1,2).equals("7"))roomanumber=roomanumber+kymned[6]; if(arv.substring(1,2).equals("8"))roomanumber=roomanumber+kymned[7]; if(arv.substring(1,2).equals("9"))roomanumber=roomanumber+kymned[8]; if(arv.substring(2,3).equals("1"))roomanumber=roomanumber+yhed[0]; if(arv.substring(2,3).equals("2"))roomanumber=roomanumber+yhed[1]; if(arv.substring(2,3).equals("3"))roomanumber=roomanumber+yhed[2]; if(arv.substring(2,3).equals("4"))roomanumber=roomanumber+yhed[3]; if(arv.substring(2,3).equals("5"))roomanumber=roomanumber+yhed[4]; if(arv.substring(2,3).equals("6"))roomanumber=roomanumber+yhed[5]; if(arv.substring(2,3).equals("7"))roomanumber=roomanumber+yhed[6]; if(arv.substring(2,3).equals("8"))roomanumber=roomanumber+yhed[7]; if(arv.substring(2,3).equals("9"))roomanumber=roomanumber+yhed[8]; tf2.setText("" +roomanumber); } } if(arv.length()==2){ if((arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9")) || (arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9"))){ if((arv.substring(0,1).equals("4"))&&(arv.substring(1,2).equals("9")))roomanumber=roomanumber+"IL"; if((arv.substring(0,1).equals("9"))&&(arv.substring(1,2).equals("9")))roomanumber=roomanumber+"IC"; tf2.setText("" +roomanumber); }else{ if(arv.substring(0,1).equals("1"))roomanumber=roomanumber+kymned[0]; if(arv.substring(0,1).equals("2"))roomanumber=roomanumber+kymned[1]; if(arv.substring(0,1).equals("3"))roomanumber=roomanumber+kymned[2]; if(arv.substring(0,1).equals("4"))roomanumber=roomanumber+kymned[3]; if(arv.substring(0,1).equals("5"))roomanumber=roomanumber+kymned[4]; if(arv.substring(0,1).equals("6"))roomanumber=roomanumber+kymned[5]; if(arv.substring(0,1).equals("7"))roomanumber=roomanumber+kymned[6]; if(arv.substring(0,1).equals("8"))roomanumber=roomanumber+kymned[7]; if(arv.substring(0,1).equals("9"))roomanumber=roomanumber+kymned[8]; if(arv.substring(1,2).equals("1"))roomanumber=roomanumber+yhed[0]; if(arv.substring(1,2).equals("2"))roomanumber=roomanumber+yhed[1]; if(arv.substring(1,2).equals("3"))roomanumber=roomanumber+yhed[2]; if(arv.substring(1,2).equals("4"))roomanumber=roomanumber+yhed[3]; if(arv.substring(1,2).equals("5"))roomanumber=roomanumber+yhed[4]; if(arv.substring(1,2).equals("6"))roomanumber=roomanumber+yhed[5]; if(arv.substring(1,2).equals("7"))roomanumber=roomanumber+yhed[6]; if(arv.substring(1,2).equals("8"))roomanumber=roomanumber+yhed[7]; if(arv.substring(1,2).equals("9"))roomanumber=roomanumber+yhed[8]; tf2.setText("" +roomanumber); } } if(arv.length()==1){ for(int i=0; i<9; i++){ if(arv.equals(lnyhed[i]))roomanumber=yhed[i]; } tf2.setText("" +roomanumber); } } public static void main(String argumendid[]){ Frame f=new Frame("Roomanumbrid"); f.setSize(200,100); f.add(new Roomanumbrid()); f.setBackground(new Color(240,200,200)); f.setVisible(true); } }