//Java ejemplo promedio de notas de un estudiante
import javax.swing.*;
import java.awt.event.*;
public class NOTAS extends JFrame implements ActionListener{
JLabel titulo,Matematicas1, Ingles, Contabilidad, Algoritmos, Programacion,promedio,resultado,semestre;
JTextField mate,ingles,contab,algor,progr;
JButton calcular,SALIR;
double notas[]= new double[5];
int i=0;
public NOTAS(){
setLayout(null);
titulo=new JLabel("PROMEDIO NOTAS DEL SEMESTRE ");
titulo.setBounds(20, 20, 200, 20);
add(titulo);
Matematicas1=new JLabel("Matematicas: ");
Matematicas1.setBounds(20, 60, 100, 20);
add(Matematicas1);
Ingles=new JLabel("Ingles1: ");
Ingles.setBounds(20, 80, 100, 20);
add(Ingles);
Contabilidad=new JLabel("Contabilidad: ");
Contabilidad.setBounds(20, 100, 100, 20);
add(Contabilidad);
Algoritmos=new JLabel("Algoritmos: ");
Algoritmos.setBounds(20, 120, 100, 20);
add(Algoritmos);
Programacion=new JLabel("Programacion: ");
Programacion.setBounds(20, 140, 100, 20);
add(Programacion);
promedio=new JLabel("PROMEDIO: ");
promedio.setBounds(20, 220, 180, 20);
add(promedio);
mate=new JTextField();
mate.setBounds(120, 60, 60, 20);
add(mate);
ingles=new JTextField();
ingles.setBounds(120, 80, 60, 20);
add(ingles);
contab=new JTextField();
contab.setBounds(120, 100, 60, 20);
add(contab);
algor=new JTextField();
algor.setBounds(120, 120, 60, 20);
add(algor);
progr=new JTextField();
progr.setBounds(120, 140, 60, 20);
add(progr);
calcular=new JButton("CALCULAR");
calcular.setBounds(20, 170, 160, 20);
add(calcular);
calcular.addActionListener(this);
SALIR=new JButton("SALIR");
SALIR.setBounds(150, 280, 100, 20);
add(SALIR);
SALIR.addActionListener(this);
semestre=new JLabel("SEMSESTRE: ");
semestre.setBounds(20, 240, 200, 20);
add(semestre);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==calcular){
double m=Double.parseDouble(mate.getText());
notas[0]=m;
double i=Double.parseDouble(ingles.getText());
notas[1]=i;
double c=Double.parseDouble(contab.getText());
notas[2]=c;
double a=Double.parseDouble(algor.getText());
notas[3]=a;
double p=Double.parseDouble(progr.getText());
notas[4]=p;
double promediar;
promediar=(m+i+c+a+p)/5;
promedio.setText("PROMEDIO: "+promediar);
if(promediar>=3.0){
semestre.setText("notas: "+notas[0]+","+notas[1]+","+notas[2]+","+notas[3]+","+notas[4]);
//semestre.setText("SEMESTRE: APROBADO");
}else if(promediar<3.0){
semestre.setText("SEMESTRE: REPROBADO");
}
}
if(e.getSource()==SALIR){
System.exit(0);
}
}
public static void main(String[] args) {
NOTAS obj = new NOTAS();
obj.setBounds(0, 0, 300, 350);
obj.setVisible(true);
}
}
Curso de programación con Java NetBeans en donde
aprenderá como crear aplicaciones para ambiente cliente/servidor.