Retroceder   Foros del Web > Programación para sitios web > Java y JSP

Respuesta
 
Herramientas Desplegado
Antiguo 29-jun-2005, 12:24   #1 (permalink)
ubbito ha deshabilitado el karma
 
Fecha de Ingreso: junio-2005
Mensajes: 2
Ayuda estetica con Metodo Imprimir

HOLA AMIGOS OJALA PUEDAN AYUDARME Y PRONTO.

TENGO UNA TAREA,ACERCA DE POLINOMIOS, LA TENGO CASI LISTA.
PERO ESTETICAMENTE NO SE VE MUY BIEN.

RESULATA QUE NECESITO AYUDA CON EL METODO IMPRIMIR (UN POLINOMIO)??


el metodo imprimir seria algo asi

......2............9......9.2..................... ......(*)
24(x) + 24.6(x) - 7(x) + 9

(*) NOTA:LOS PUNTOS(......) ESOS NO DEBEN IR LOS PUSE SOLA PA QUE QUEDE TODO EN ORDEN PORQUE SE ME CORRIAN LOS NUMEROS TODOS JUNTOS PA LA IZQUIERDA, AQUI EN EL FORO.


En la tarea,existe un metodo imprimir que imprime muy feo, lo hice para guiarme, solo para eso, pero en todo caso en el
metodo pide datos tambien imprime un termino.

El main que hay no lo tomen en cuenta, es solo para guiarme en algunas cosas

OJALA PUEDAN AYUDARME POH!!
A CONTINUACION ESTA LO QUE LLEVO!!


SEPARADO EN:

1.teclado.java
2.polinomio.java


1.TECLADO.JAVA

//iNICIO TECLADO.
import java.io.*;


public class Teclado {


//variable de clase asignada a la entrada estandar del sistema
public static BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));

//metodo que permite leer un string desde el teclado
public static String LeerString() {
String cadena="";
try {
cadena = new String(entrada.readLine());
}
catch (IOException e) {
System.out.println("Error de E/S");
}
return cadena;
}

//metodo que permite leer un entero desde el teclado
public static int LeerInt() {
int entero = 0;
boolean error = false;
do {
try {
error = false;
entero = Integer.valueOf(entrada.readLine()).intValue();
}
catch (NumberFormatException e1) {
error = true;
System.out.println("Error en el formato del numero, intentelo de nuevo.");
}
catch (IOException e) {
System.out.println("Error de E/S");
}
} while (error);
return entero;
}

//metodo que permite leer un float desde el teclado
public static float LeerFloat() {
float real=0;
boolean error = false;

//FIN TECLADO.


2. POLINOMIO.JAVA
//INICIO POLINOMIO

import java.util.*;
import java.lang.*;
public class Polinomio
{

private char Variable;
private Vector Coeficiente;
private Vector Exponente;
private int CantTerminos;

public Polinomio(char var,Vector coef, Vector exp)
{
Variable = var;
Coeficiente = coef;
Exponente = exp;
CantTerminos = exp.size();

}


public Polinomio()
{
Coeficiente = new Vector();
Exponente = new Vector();
CantTerminos = 0;
}


public static Polinomio PideDatos()
{
Polinomio Nuevo;
char variable;
Vector coef,exp;
coef = new Vector();
exp = new Vector();
boolean sigue = true;
Double Coef,Exp;
Coef = new Double(0);
int i=0,larg=0,j=0;
Pantalla.Imprime("Ingrese la variable con la que trabajara el Polinomio = ");
variable = Teclado.LeerChar();
while(sigue)
{

Pantalla.Imprime("Ingrese El Coeficiente del termino "+(i+1)+" = ");
Coef = new Double(Teclado.LeerDouble());
larg = Coef.toString().length();
coef.addElement(Coef);
Pantalla.Imprime("Ingrese el Exponente del termino "+(i+1)+" = ");
Exp = new Double(Teclado.LeerDouble());
exp.addElement(Exp);
i++;
for(j=0;j<larg;j++)
Pantalla.Imprime(" ");
Pantalla.Imprimeln(" "+Exp);
Pantalla.Imprimeln(""+Coef+" "+"("+variable+")");
if(i!=0)
{
Pantalla.Imprime("Desea Ingresar Otro Termino al Polinomio (s/n) = ");
if(Teclado.LeerChar()=='n')
sigue=false;
}
}
Nuevo = new Polinomio(variable,coef,exp);
return (Nuevo);
}


private void OrdenaPolinomio()
{
int i,j;
Double Dtemporal_1,Dtemporal_2;
for(i=(Exponente.size()-1);i>0;i--)
{
for(j=0;j<i;j++)
{
Dtemporal_1 = (Double)Exponente.elementAt(j);
Dtemporal_2 = (Double)Exponente.elementAt(j+1);
if(Dtemporal_1.doubleValue()<Dtemporal_2.doubleVal ue())
{
Exponente.setElementAt(Dtemporal_1,(j+1));
Exponente.setElementAt(Dtemporal_2,(j));
Dtemporal_1 = (Double)Coeficiente.elementAt(j);
Dtemporal_2 = (Double)Coeficiente.elementAt(j+1);
Coeficiente.setElementAt(Dtemporal_1,(j+1));
Coeficiente.setElementAt(Dtemporal_2,(j));
}

//FIN POLINOMIO


ESO ES TODO GRACIAS


SI PUENEN = MANDARME LAS POSIBLES RESPÙESTAS A ubbito@gmail.com

SE LOS aAGRADECERIA AUN MAS!!

CHAU

Última edición por ubbito; 29-jun-2005 a las 12:29.
ubbito está desconectado   Responder Citando
Antiguo 29-jun-2005, 13:39   #2 (permalink)
ubbito ha deshabilitado el karma
 
Fecha de Ingreso: junio-2005
Mensajes: 2
Aun espero la ayuda!!
ubbito está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Desactivado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 13:24.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93