Classe 4ª F – Verifica scritta di Informatica del 11/12/2013

annuncio pubblicitario
Classe 4ª F – Verifica scritta di Informatica del 11/12/2013 – Correzione
package suono;
import
import
import
import
lejos.nxt.SensorPort;
lejos.nxt.SensorPortListener;
lejos.nxt.SoundSensor;
lejos.util.Delay;
public class Suono {
private
private
private
private
final int SOGLIA = 100;
SoundSensor ss;
int nSopraSoglia;
int secondi;
public class SoundSensorPortListener implements SensorPortListener {
@Override
public void stateChanged(SensorPort aSource, int aOldValue,
int aNewValue) {
int valore = ss.readValue();
if (valore > SOGLIA) {
nSopraSoglia++;
}
Delay.msDelay(10000);
secondi += 10;
}
}
public Suono() {
ss = new SoundSensor(SensorPort.S1);
nSopraSoglia = 0;
secondi = 0;
SensorPort.S1.addSensorPortListener(new SoundSensorPortListener());
while (secondi <= 600) ;
System.out.println("L'intensità sonora ha superato " + SOGLIA
+ " decibel per " + nSopraSoglia + " volte in 10 minuti");
}
public static void main(String[] args) {
new Suono();
}
}
package pianeti;
import
import
import
import
import
java.awt.EventQueue;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
java.io.BufferedReader;
java.io.FileReader;
import
import
import
import
import
import
import
javax.swing.JButton;
javax.swing.JFrame;
javax.swing.JLabel;
javax.swing.JOptionPane;
javax.swing.JPanel;
javax.swing.JTextField;
javax.swing.SpringLayout;
public class Pianeti extends JFrame {
private
private
private
private
private
JPanel contentPane;
JTextField txtNome;
JTextField txtMassa;
JTextField txtDistanza;
JTextField txtPeriodo;
/**
* Launch the application.
*/
public static void main(String[] args) { … }
/**
* Create the frame.
*/
public Pianeti() { … }
public void btnCercaActionPerformed() {
String nomePianeta = txtNome.getText();
try {
BufferedReader br = new BufferedReader(new FileReader("Pianeti.csv"));
String dato;
while (true) {
dato = br.readLine();
if (dato == null)
break;
String[] d = dato.split(";");
if (d[0].equalsIgnoreCase(nomePianeta)) {
txtNome.setText(d[0]);
txtMassa.setText(d[1]);
txtDistanza.setText(d[2]);
txtPeriodo.setText(d[3]);
break;
}
}
if (dato == null) {
JOptionPane.showMessageDialog(contentPane, "Pianeta "
+ nomePianeta + " non trovato", "Errore",
JOptionPane.ERROR_MESSAGE);
txtNome.setText("");
txtMassa.setText("");
txtDistanza.setText("");
txtPeriodo.setText("");
}
br.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(contentPane, e.toString(), "Errore",
JOptionPane.ERROR_MESSAGE);
}
}
}
Scarica