import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.*; import java.text.*; class Help extends Frame implements WindowListener { public Help(String title){ super(title); setLayout(new GridLayout(1,1)); setSize(500,400); addWindowListener(this); StringBuffer buf = new StringBuffer(); buf.append("Users select seven car parameters\n"); buf.append("such as:\n"); buf.append("1. Color;\n"); buf.append("2. Type;\n"); buf.append("3. Fuel;\n"); buf.append("4. Engine;\n"); buf.append("5. Cabin;\n"); buf.append("6. Price;\n"); buf.append("7. Number of Doors.\n"); buf.append("Users select parameters by marking \n"); buf.append("Users may select the number of cars to choose (from 1 to 100)\n"); buf.append("Users may select the variance of impressions (nuo 0.1 iki 0.01), and the cost of waiting. \n"); buf.append("Othervise these parameters are defined by default values. \n"); buf.append("To start the program, press the buton 'Start'. \n"); buf.append("That opens the result window informing about the preferable and \n"); buf.append("the best car. \n"); buf.append(" The button 'Graph'.\n"); buf.append("opens the graphical image.\n"); buf.append("Red points denote impressions obtained by Monte Carlo simulation.\n"); buf.append(" Green line denotes the optimal decision function\n"); buf.append("Blue point shows the optimal solution\n"); buf.append("where impressions cross the critical green line first time,\n"); TextArea txt = new TextArea(); txt.setFont(new Font("NewRomanBaltic",Font.PLAIN,12)); txt.append(buf.toString()); add(txt); } public void windowActivated(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowClosing(WindowEvent e){ dispose(); } public void windowDeactivated(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowOpened(WindowEvent e){} } class Grafik extends Frame implements WindowListener { int N; double[] s; double[] kr; int i; int ji; public Grafik(String title, int n1, double[] s1, double[] kr1, int ji1) { super(title); setLayout(null); addNotify(); setSize(300,400); addWindowListener(this); N = n1; s = new double[N]; kr = new double[N]; for (i=0;iw[j]) j=i; } label[14] = new Label("The best car Nr. "+j); label[15] = new Label("Actual quality: "+w[j]); label[16] = new Label("Impression: "+s[j]); for (i=1;i<17;i++) add(label[i]); } public void windowActivated(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowClosing(WindowEvent e){ dispose(); } public void windowDeactivated(WindowEvent e){} public void windowDeiconified(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowOpened(WindowEvent e){} } public class DarbasNew extends Applet implements ActionListener { TextField t1,t2,t3; Label l1, l2, l3, l4, l5, l6, l7, l8, l9,l10,l11,l12; Checkbox c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14; Checkbox c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26; CheckboxGroup g1, g2, g3, g4, g5, g6, g7; Button b1, b2, b3; Panel p1, p2, p3, p4, p5, p6, p7, p8; double si; double M = 0.9; double[] s; double[] w; double[] kr; int N; int K = 100; int max; String str; int ji; double c; int []data = new int[100]; GridBagLayout gb; GridBagConstraints con; GridLayout grid; //--------------------------------------------- public void init() { grid = new GridLayout(); grid.setRows(2); grid.setColumns(4); setLayout(grid); gb = new GridBagLayout(); con = new GridBagConstraints(); con.gridwidth = GridBagConstraints.REMAINDER; p1 = new Panel(gb); p2 = new Panel(gb); p3 = new Panel(gb); p4 = new Panel(gb); p5 = new Panel(gb); p6 = new Panel(gb); p7 = new Panel(gb); p8 = new Panel(gb); setFont(new Font("NewRomanBaltic",Font.BOLD,12)); //-- l1 = new Label("Color"); gb.setConstraints(l1,con); con.anchor = GridBagConstraints.WEST; g1 = new CheckboxGroup(); c1 = new Checkbox("Light",g1,true); c2 = new Checkbox("Dark",g1,false); c3 = new Checkbox("Pearl",g1,false); gb.setConstraints(c1,con); gb.setConstraints(c2,con); gb.setConstraints(c3,con); p1.add(l1); p1.add(c1); p1.add(c2); p1.add(c3); add(p1); //-- //-- con.anchor = GridBagConstraints.CENTER; l2 = new Label("Type of car"); gb.setConstraints(l2,con); con.anchor = GridBagConstraints.WEST; g2 = new CheckboxGroup(); c4 = new Checkbox("Sedan",g2,true); c5 = new Checkbox("Universal",g2,false); c6 = new Checkbox("Cabriolet",g2,false); c7 = new Checkbox("Chachback",g2,false); gb.setConstraints(c4,con); gb.setConstraints(c5,con); gb.setConstraints(c6,con); gb.setConstraints(c7,con); p2.add(l2); p2.add(c4); p2.add(c5); p2.add(c6); p2.add(c7); add(p2); //-- //-- con.anchor = GridBagConstraints.CENTER; l3 = new Label("Fuel"); gb.setConstraints(l3,con); con.anchor = GridBagConstraints.WEST; g3 = new CheckboxGroup(); c8 = new Checkbox("Gasolin",true,g3); c9 = new Checkbox("Gas",false,g3); c10 = new Checkbox("Dysel",false,g3); gb.setConstraints(c8,con); gb.setConstraints(c9,con); gb.setConstraints(c10,con); p3.add(l3); p3.add(c8); p3.add(c9); p3.add(c10); add(p3); //-- //-- con.anchor = GridBagConstraints.CENTER; l4 = new Label("Engine"); gb.setConstraints(l4,con); con.anchor = GridBagConstraints.WEST; g4 = new CheckboxGroup(); c11 = new Checkbox("less than 1.5 ltr",true,g4); c12 = new Checkbox("From 1.5 to 2.0 ltr",false,g4); c13 = new Checkbox("More than 2.0 ltr",false,g4); gb.setConstraints(c11,con); gb.setConstraints(c12,con); gb.setConstraints(c13,con); p4.add(l4); p4.add(c11); p4.add(c12); p4.add(c13); add(p4); //-- //-- con.anchor = GridBagConstraints.CENTER; l5 = new Label("Cabin"); gb.setConstraints(l5,con); con.anchor = GridBagConstraints.WEST; g5 = new CheckboxGroup(); c14 = new Checkbox("Light",true,g5); c15 = new Checkbox("Dark",false,g5); c16 = new Checkbox("Leather",false,g5); c17 = new Checkbox("Barchat",false,g5); c18 = new Checkbox("Simple",false,g5); gb.setConstraints(c14,con); gb.setConstraints(c15,con); gb.setConstraints(c16,con); gb.setConstraints(c17,con); gb.setConstraints(c18,con); p5.add(l5); p5.add(c14); p5.add(c15); p5.add(c16); p5.add(c17); p5.add(c18); add(p5); //-- //-- con.anchor = GridBagConstraints.CENTER; l6 = new Label("Price"); gb.setConstraints(l6,con); con.anchor = GridBagConstraints.WEST; g6 = new CheckboxGroup(); c19 = new Checkbox("From 5,000 ",true,g6); c20 = new Checkbox("From 5,000 to 12.500",false,g6); c21 = new Checkbox("From 12,500 to 25,000",false,g6); c22 = new Checkbox("More than 25,000",false,g6); gb.setConstraints(c19,con); gb.setConstraints(c20,con); gb.setConstraints(c21,con); gb.setConstraints(c22,con); p6.add(l6); p6.add(c19); p6.add(c20); p6.add(c21); p6.add(c22); add(p6); //-- //-- con.anchor = GridBagConstraints.CENTER; l7 = new Label("Number of doors"); gb.setConstraints(l7,con); con.anchor = GridBagConstraints.WEST; g7 = new CheckboxGroup(); c23 = new Checkbox("Two",true,g7); c24 = new Checkbox("Three",false,g7); c25 = new Checkbox("Four",false,g7); c26 = new Checkbox("Five",false,g7); gb.setConstraints(c23,con); gb.setConstraints(c24,con); gb.setConstraints(c25,con); gb.setConstraints(c26,con); p7.add(l7); p7.add(c23); p7.add(c24); p7.add(c25); p7.add(c26); add(p7); //-- //-- con.anchor = GridBagConstraints.CENTER; l8 = new Label("Number of Cars"); gb.setConstraints(l8,con); t1=new TextField("50",5); gb.setConstraints(t1,con); l9 = new Label("Distribution of Impressions"); gb.setConstraints(l9,con); l10 = new Label("Waiting Cost"); gb.setConstraints(l10,con); t2=new TextField("0.05",5); gb.setConstraints(t2,con); t3=new TextField("0.0001",5); gb.setConstraints(t3,con); con.fill = GridBagConstraints.HORIZONTAL; con.insets = new Insets(1,20,1,20); b1 = new Button("Start"); gb.setConstraints(b1,con); b2 = new Button("Graph"); gb.setConstraints(b2,con); b2.setEnabled(false); b3 = new Button("Help"); gb.setConstraints(b3,con); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); p8.add(l8); p8.add(t1); p8.add(l9); p8.add(t2); p8.add(l10); p8.add(t3); p8.add(b1); p8.add(b2); p8.add(b3); add(p8); data[0]=1133524; data[1]=2222222; data[2]=2432213; data[3]=2323231; data[4]=1331534; data[5]=1231512; data[6]=3111514; data[7]=3311524; data[8]=2312242; data[9]=3421411; data[10]=2111334; data[11]=1411313; data[12]=1423324; data[13]=1111111; data[14]=2222222; data[15]=3333333; data[16]=1112511; data[17]=1233311; data[18]=1431134; data[19]=1111144; data[20]=1333221; data[21]=2131311; data[22]=2212221; data[23]=1121342; data[24]=1223441; data[25]=2423124; data[26]=2322412; data[27]=3111212; data[28]=1411331; data[29]=3412441; data[30]=2123413; data[31]=1133532; data[32]=1313424; data[33]=1233531; data[34]=1113542; data[35]=2312121; data[36]=1422323; data[37]=3433342; data[38]=2412511; data[39]=2413234; data[40]=3222442; data[41]=2113511; data[42]=2133143; data[43]=2231343; data[44]=2133412; data[45]=2423321; data[46]=3421133; data[47]=2131331; data[48]=3431411; data[49]=2213214; data[50]=2211311; data[51]=1223144; data[52]=2422443; data[53]=3133432; data[54]=2123531; data[55]=1211232; data[56]=2312532; data[57]=3232133; data[58]=3411433; data[59]=3213423; data[60]=1332512; data[61]=3331513; data[62]=1212232; data[63]=1212432; data[64]=1232513; data[65]=2123232; data[66]=1221324; data[67]=3133144; data[68]=3313221; data[69]=1332244; data[70]=3431521; data[71]=3121112; data[72]=2413142; data[73]=2111122; data[74]=3312124; data[75]=1132534; data[76]=1232324; data[77]=2231233; data[78]=1331242; data[79]=3132343; data[80]=2232433; data[81]=1133412; data[82]=2131431; data[83]=2131243; data[84]=3223143; data[85]=3311114; data[86]=3211121; data[87]=1313324; data[88]=3113434; data[89]=1112534; data[90]=2321512; data[91]=2121242; data[92]=3422513; data[93]=2333142; data[94]=2331112; data[95]=2113544; data[96]=3413413; data[97]=3112413; data[98]=2233211; data[99]=2222214; } public void actionPerformed(ActionEvent e){ if (e.getSource()==b1){ calculate(); b2.setEnabled(true); } if (e.getSource()==b2){ Grafik fr = new Grafik("Graph",N,s,kr,ji); fr.pack(); fr.show(); // grafikas(); } if (e.getSource()==b3){ Help pag = new Help("Help"); pag.show(); // grafikas(); } } public void calculate() { N=Integer.valueOf(t1.getText()).intValue(); if (N>100) { N=100; t1.setText(Integer.toString(N)); } if (N<1) { N=1; t1.setText(Integer.toString(N)); } si=Double.valueOf(t2.getText()).doubleValue(); if (si>0.1) { si=0.1; t2.setText(Double.toString(si)); } if (si<0.01) { si=0.01; t2.setText(Double.toString(si)); } c=Double.valueOf(t3.getText()).doubleValue(); int i,j,h; double w1,s1,z; s = new double[N]; w = new double[N]; kr = new double[N]; double pw[] = new double[K]; double psw[][] = new double[K][K]; double pss[] = new double[K]; double pws[][] = new double[K][K]; double matrica[][] = new double[N][K]; double Un[] = new double[K]; double Un_1[] = new double[K]; for(i=0;i=0;j--) { Un_1[0]=0.0; for(i=0;i=0;j--) { for(i=K-1;i>=0;i--) { if(matrica[j][max]>matrica[j][i]) max=i; } kr[j]=matrica[j][max]; } Random a=new Random(); for(i=0;i=0.5) return y+vid; else return vid-y; } }