Solução da Prova (IV- BIM) – POO-III 1) Questão import java.awt.*; public class Intervalo extends Applet{ TextField text1; TextField text2; TextField text3; Button b1; public void init (){ text1 = new TextField(10); text2 = new TextField(10); text3 = new TextField(10); b1 = new Button("Ok"); add(text1); add(text2); add(text3); add(b1); } public boolean action(Event vt, Object ob) { if(ob.equals("Ok")) { int x = Integer.parseInt(text1.getText()); int y = Integer.parseInt(text2.getText()); double k =Math.rint( ( Math.random()* (y-x))+x); text3.setText(""+k); // A caixa de texto 3 foi criada para mostrar o resultado...... } return true; } } 2) Questão import java.lang.*; import java.awt.*; import java.io.*; public class arqtexto extends Frame { Panel tela; Button b1; List lista; public arqtexto() { setLayout(new BorderLayout()); tela = new Panel(); add("Center",tela); lista = new List(3,false); lista.addItem(" "); // Cria Botao b1 = new Button("Mostra"); tela.add(b1); tela.add(lista); reshape(10,10,200,200); // Tamanho da tela. show(); // Exibe Formulario na tela. } public boolean action(Event evt,Object arg) { if("Mostra".equals(arg)) { FileInputStream f1; DataInputStream i1; try { f1 = new FileInputStream("arq.txt"); i1 = new DataInputStream(f1); String str = i1.readLine(); while(str != null) { lista.addItem(str); str = i1.readLine(); } } catch(Exception e) { System.out.println("Erro no arquivo !!! "); } } return true; } public static void main(String args[]) { new arqtexto(); } } 3) Questão n5 i= 1 j= 0 x= 5 a[i]= 5 a[j]= 0 i= 2 j= 0 x= 8 a[i]= 8 a[j]= 5 i= 3 j= 1 x= 19 a[i]= 19 a[j]= 8 i= 4 j= 2 x= 1 a[i]= 1 a[j]= 19 a[j]= 8 a[j]= 5 a[j]= 0 Resultado ----------1 5 8 19 4) Questão Obs : Essa questão será encontrada nos exemplos de aula no “site” do professor. 5) Questão import java.awt.*; import java.applet.*; public class mostrafig extends Applet { Image im1; public void paint(Graphics g) { im1 = getImage(getCodeBase(),"Foto1.jpg"); g.drawImage(im1,50,12,this); } }