Eu estou fazendo um curso que não é muito bom né, e estou numa avaliação que eu não consigo progredir, vou postar o exercicio aqui e oque eu tenho até agora…
Questão: Faça um programa que receba o nome do aluno, as notas da prova 1 e prova 2 e então calcule a média final, mostrando-a junto com o resultado, que pode ser Aprovado ou reprovado
Porem os alunos podem cursar uma formação diferente e a média ser outra…As médias são as seguintes: Graduação(7), Pós Graduação(6), Doutorado(5)
Codigo:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ProvaJAVA.java
*
* Created on 30/07/2020, 11:44:31
*/
package prova_java;
import javax.swing.JOptionPane;
/**
*
* @author Aluno
*/
public class ProvaJAVA extends javax.swing.JFrame {
/** Creates new form ProvaJAVA */
public ProvaJAVA() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
bgCurso = new javax.swing.ButtonGroup();
Nome = new javax.swing.JLabel();
Numerodematricula = new javax.swing.JLabel();
Prova1 = new javax.swing.JLabel();
Prova2 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jTNome = new javax.swing.JTextField();
jTNummatricula = new javax.swing.JTextField();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jTProva1 = new javax.swing.JTextField();
jTProva2 = new javax.swing.JTextField();
jBLimpar = new javax.swing.JButton();
jBCalcularmedia = new javax.swing.JButton();
jBSair = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Dados do Aluno");
Nome.setText("Nome");
Numerodematricula.setText("Número de Matricula");
Prova1.setText("Nota 1° Prova");
Prova2.setText("Nota 2° Prova");
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Tipo de Curso");
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel6.setText("DADOS DO ALUNO");
jTNome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTNomeActionPerformed(evt);
}
});
jTNummatricula.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTNummatriculaActionPerformed(evt);
}
});
jTNummatricula.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTNummatriculaKeyTyped(evt);
}
});
bgCurso.add(jRadioButton1);
jRadioButton1.setText("Graduação");
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
}
});
bgCurso.add(jRadioButton2);
jRadioButton2.setText("Pós-Graduação");
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
}
});
bgCurso.add(jRadioButton3);
jRadioButton3.setText("Doutorado");
jTProva1.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
jTProva1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTProva1ActionPerformed(evt);
}
});
jTProva1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTProva1KeyTyped(evt);
}
});
jTProva2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jTProva2KeyTyped(evt);
}
});
jBLimpar.setText("Limpar");
jBLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBLimparActionPerformed(evt);
}
});
jBCalcularmedia.setText("Calcular Média");
jBCalcularmedia.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBCalcularmediaActionPerformed(evt);
}
});
jBSair.setText("Sair");
jBSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBSairActionPerformed(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.LEADING)
.addComponent(jLabel6)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Nome)
.addComponent(Numerodematricula)
.addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTNummatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTProva1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jBCalcularmedia, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jBLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTProva2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(Prova1)
.addGap(90, 90, 90)
.addComponent(Prova2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5)
.addComponent(jRadioButton1))
.addComponent(jRadioButton2)
.addComponent(jRadioButton3))
.addGap(22, 22, 22))
.addComponent(jBSair, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel6)
.addGap(26, 26, 26)
.addComponent(Nome)
.addGap(7, 7, 7)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(Numerodematricula)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTNummatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(56, 56, 56)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Prova1)
.addComponent(Prova2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTProva1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTProva2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton3)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jBLimpar)
.addComponent(jBSair))
.addComponent(jBCalcularmedia))
.addContainerGap(17, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jBSairActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void jBLimparActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTNome.setText(null);
jTNummatricula.setText(null);
jTProva1.setText(null);
jTProva2.setText(null);
}
private void jBCalcularmediaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
double nota1 = Integer.parseInt(jTProva1.getText());
double nota2 = Integer.parseInt(jTProva2.getText());
double resultado;
resultado = nota1 + nota2 /2;
JOptionPane.showMessageDialog(null, " A sua média é: " + resultado);
}
private void jTProva1KeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
String caracteres="0987654321";
if(!caracteres.contains(evt.getKeyChar()+"")){
evt.consume();
}
}
private void jTProva2KeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
String caracteres="0987654321";
if(!caracteres.contains(evt.getKeyChar()+"")){
evt.consume();
}
}
private void jTNummatriculaKeyTyped(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
String caracteres="0987654321";
if(!caracteres.contains(evt.getKeyChar()+"")){
evt.consume();
}
}
private void jTProva1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTNummatriculaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTNomeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String caracteres="0987654321";
if(caracteres.contains(evt.getKeyChar()+"")){
evt.consume();
}
}
/**
* @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(ProvaJAVA.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ProvaJAVA.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ProvaJAVA.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ProvaJAVA.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ProvaJAVA().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel Nome;
private javax.swing.JLabel Numerodematricula;
private javax.swing.JLabel Prova1;
private javax.swing.JLabel Prova2;
private javax.swing.ButtonGroup bgCurso;
private javax.swing.JButton jBCalcularmedia;
private javax.swing.JButton jBLimpar;
private javax.swing.JButton jBSair;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JTextField jTNome;
private javax.swing.JTextField jTNummatricula;
private javax.swing.JTextField jTProva1;
private javax.swing.JTextField jTProva2;
// End of variables declaration
}
ME AJUDEM PLSSS