Академический Документы
Профессиональный Документы
Культура Документы
examines its elements to determine how many of the integers end in 0, how many end in 1, how
many end in 2 and so on. Your method will return an array of counters. The count of how many
elements end in 0 should be stored in its element [0], how many of the values end in 1 should be
stored in its element [1], and so on. For example, if a variable named list refers to an array
containing the values {9, 29, 44, 103, 2, 52, 12, 12, 76, 35, 20}, the call of countLastDigits(list)
should return an array containing {1, 0, 4, 1, 1, 1, 1, 0, 0, 2} because 1 element ends with 0 (20),
no elements end with 1, 4 elements end with 2 (2, 52, 12, 12), and so on.
Test your code with the following class:
import java.util.*;
// finish me
}
Write a program that hash 100 numbers into a hash table using a load factor of
75%. Please print your input file and then print the table once it is hashed.
Can somebody troubleshoot this
package Analysis;
public class AnalysisUI extends javax.swing.JFrame {
public AnalysisUI();
{
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(153, 255, 255));
jButton2.setForeground(new java.awt.Color(0, 0, 255));
jButton2.setText("Clear");
jButton2.setName("Clear"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE, 166,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE, 268,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(69, 69, 69)
.addComponent(jLabel2))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
379, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(67, 67, 67)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
case 1: sum=getSum(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+sum;
jTextField1.setText(text);
break;
case 2: min=getMin(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+min;
jTextField1.setText(text);
break;
case 3: max=getMax(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+max;
jTextField1.setText(text);
break;
case 4: sum=getSum(soilMoisture);
avg=sum/10;
text=(String) jList1.getSelectedValue()+": "+avg;
jTextField1.setText(text);
break;
jTextField1.setText(text);
break;
}
}
private int getSum(int soilMoisture[] )
{
int i;
//sum
int sum=0;
for(i=0;i<10;i++)
sum+= soilMoisture[i];
return sum;
}
return min;
}
private int getMax(int soilMoisture[] )
{
int max=soilMoisture[0];
for(int i=0;i<10;i++)
{
if(soilMoisture[i]<max)
max= soilMoisture[i];
}
return max;
}
private double getStd(int soilMoisture[] )
{
float avg=getSum(soilMoisture)/10;
int sum1=0;
for(int i=0;i<10;i++)
sum1+= Math.pow((soilMoisture[i]-avg),2);
sum1/= 9;
double std=Math.sqrt(sum1);
return std;
}
// Clear button
jTextField1.setText(null);
jTextField2.setText(null);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AnalysisUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
Which production should be in the grammar for a language L = M*, where A is the start symbol
for M and S is the start symbol for L?
A.
S -> AS | ?
B.
S -> SA | ?
C.
S -> AS | A
D.
Either A or B