java orienta 03

4
Java Orientado a Objetos I JAVA ORIENTADO A OBJETOS I Prácticas A Continuación 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[]) [Escriba aquí]

Upload: renequispesoncco

Post on 27-Sep-2015

221 views

Category:

Documents


1 download

DESCRIPTION

Java Orienta 03

TRANSCRIPT

Java Orientado a Objetos I

Java Orientado a Objetos I

JAVA ORIENTADO A OBJETOS IPrcticasA 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 Telesupimport 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); 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 15Jessica Visual Net 16Criseida C++ 16Patty Effiel 17Promedio Final...:16.0Forma 2: Resultado en un panel (Clase Java)// Autor: Profesor: Jorge Carmona Telesupimport 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 Nota "+"\n"+ "=========================="+ "\n"+Alumnos[0]+" "+Cursos[0]+" "+Notas[0]+ "\n"+Alumnos[1]+" "+Cursos[1]+" "+Notas[1]+ "\n"+Alumnos[2]+" "+Cursos[2]+" "+Notas[2]+ "\n"+Alumnos[3]+" "+Cursos[3]+" "+Notas[3]+ "\n"+"=========================="+ "\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 Nota1","",1); 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); a.promedio[0]=(nn1+nn2+nn3+nn4)/4; a.imprime(); }}Resultado:

[Escriba aqu]