Sunteți pe pagina 1din 3

Java Orientado a Objetos I

JAVA ORIENTADO A OBJETOS I


Prcticas
A Continuacin Un ejemplo de promedio de de 4 notas de alumnos, resuelto
en 2 formas:
Forma 1: Resultado en consola

(Clase Java)

Forma 2: Resultado en un panel

(Clase Java)

Forma 1: Resultado en consola (Clase Java)


// Autor: Profesor: Jorge Carmona Telesup
import javax.swing.*;
class ArregloNombres
{
String[] Alumnos = { "Jorge", "Jessica", "Criseida", "Patty"};
String[] Cursos = { "
Java", " Visual Net","C++", "
Effiel"};
String[] Notas = new String[Cursos.length];
double[] promedio=new double[1];
void imprime()
{
int i = 0;
System.out.println("Promedio de Notas Telesup 2010");
System.out.println("------------------------------");
System.out.println(Alumnos[i] + "
" + Cursos[i]+" "+ Notas[i]);
i++;
System.out.println(Alumnos[i] + "
" + Cursos[i]+"
"+ Notas[i]);
i++;
System.out.println(Alumnos[i] + "
" + Cursos[i]+"
"+ Notas[i]);
i++;
System.out.println(Alumnos[i] + "
" + Cursos[i]+"
"+ Notas[i]);
}
void calcular()
{System.out.println("Promedio Final...:"+promedio[0]);
}
public static void main (String arguments[])
{
ArregloNombres a = new ArregloNombres();
ArregloNombres p = new ArregloNombres();
String n1,n2,n3,n4;
int nn1,nn2,nn3,nn4;
// Ingresando numero como texto;
n1=JOptionPane.showInputDialog(null,"Ingrese Nota1","",1);
[Escriba aqu]

Java Orientado a Objetos I


n2=JOptionPane.showInputDialog(null,"Ingrese Nota2","",1);
n3=JOptionPane.showInputDialog(null,"Ingrese Nota3","",1);
n4=JOptionPane.showInputDialog(null,"Ingrese Nota4","",1);
System.out.println("-----");
nn1=Integer.parseInt(a.Notas[0] = n1);
nn2=Integer.parseInt(a.Notas[1] = n2);
nn3=Integer.parseInt(a.Notas[2] = n3);
nn4=Integer.parseInt(a.Notas[3] = n4);
p.promedio[0]=(nn1+nn2+nn3+nn4)/4;
a.imprime();
p.calcular();
}
}
Resultado:
Promedio de Notas Telesup 2010
-----------------------------Jorge

Java

15

Jessica

Visual Net

16

Criseida

C++

16

Patty

Effiel

17

Promedio Final...:16.0
Forma 2: Resultado en un panel (Clase Java)
// Autor: Profesor: Jorge Carmona Telesup
import javax.swing.*;
class ArregloNombres
{
String[] Alumnos = { "1. Jorge", "2. Jessica", "3. Criseida", "4.
Patty"};
String[] Cursos = { "
Java", " Visual Net","C++", "
Effiel"};
String[] Notas = new String[Cursos.length];
double[] promedio=new double[1];
void imprime()
{
// anexar objetos String a salida
String salida=" Alumno
Curso
"=========================="+
"\n"+Alumnos[0]+"
"+Cursos[0]+"
"\n"+Alumnos[1]+"
"+Cursos[1]+"
"\n"+Alumnos[2]+"
"+Cursos[2]+"
"\n"+Alumnos[3]+"
"+Cursos[3]+"
"\n"+"=========================="+
[Escriba aqu]

Nota "+"\n"+
"+Notas[0]+
"+Notas[1]+
"+Notas[2]+
"+Notas[3]+

Java Orientado a Objetos I


"\n El Promedio es

"+promedio[0];

JOptionPane.showMessageDialog(null,salida,"Promedio de Notas
Telesup",JOptionPane.INFORMATION_MESSAGE);
}
public static void main (String arguments[])
{
ArregloNombres a = new ArregloNombres();
String n1,n2,n3,n4;
int nn1,nn2,nn3,nn4;
// Ingresando numero como texto;
n1=JOptionPane.showInputDialog(null,"Ingrese
n2=JOptionPane.showInputDialog(null,"Ingrese
n3=JOptionPane.showInputDialog(null,"Ingrese
n4=JOptionPane.showInputDialog(null,"Ingrese
System.out.println("-----");
nn1=Integer.parseInt(a.Notas[0] = n1);
nn2=Integer.parseInt(a.Notas[1] = n2);
nn3=Integer.parseInt(a.Notas[2] = n3);
nn4=Integer.parseInt(a.Notas[3] = n4);
a.promedio[0]=(nn1+nn2+nn3+nn4)/4;
a.imprime();
}
}
Resultado:

[Escriba aqu]

Nota1","",1);
Nota2","",1);
Nota3","",1);
Nota4","",1);

S-ar putea să vă placă și