Escuela Politecnica Nacional Operaciones Con Polinomios Ronny Rodriguez 2015-A

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

ESCUELA

POLITECNICA
NACIONAL
OPERACIONES
CON POLINOMIOS
RONNY
RODRIGUEZ
2015-A

18/06/2015
INTERFAZ GRAFICA

CLS POLINOMIO
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prypolinomios;

/**
*
* @author usuario

*/
public class ClsPolinomio {
private int _grado;
private float [] _a;

//Constructores
public ClsPolinomio (){
_grado=0;
}
public ClsPolinomio (int grd){
_grado=grd;
_a=new float [grd+1];
}
public ClsPolinomio(int grd,float []coef){
_grado=grd;
_a=coef;
}
public ClsPolinomio(ClsPolinomio x){
this._grado=x._grado;
this._a=x._a;
}
//Get and set
public float a (int indice){ // Get individual
return _a[indice];
}
public void a (int indice, float valor){

//Set individual

_a[indice]=valor;
}
public float [] a(){ //Get de toda la estructura
return _a;
}
public void a(float [] val){ //Set de toda la estructura
_a=val;
}
//Rutinas
public int numterm (){ //funcion q cacula el numero de terminos
return _grado+1;
}
public double Fx (float valx){
double FdeX=0;
for (int i=0; i<=_grado;i++)
FdeX=FdeX+_a[i]*Math.pow(valx,i);
return FdeX;
}
public ClsPolinomio mas (ClsPolinomio b){
ClsPolinomio resp; //declarar un polinomio resp pero no lo creamos
if(this._grado>b._grado){
resp=new ClsPolinomio(this);
for (int i=0; i<=b._grado; i++)
resp._a[i]=resp._a[i]+b._a[i];
}
else {

resp=new ClsPolinomio (b);


for (int i=0; i<=this._grado; i++)
resp._a[i]=resp._a[i]+this._a[i];
}
return resp;
}
public ClsPolinomio menos(ClsPolinomio b){
ClsPolinomio r;
if (this._grado > b._grado){
r = new ClsPolinomio(this);
for(int i=0;i<=b._grado;i++)
r._a[i]-= b._a[i];
}
else
{
r= new ClsPolinomio(b) ;
for(int i=0;i<=this._grado;i++)
r._a[i]= this._a[i]-r._a[i];
}
return r;
}
public ClsPolinomio por(ClsPolinomio Q){
ClsPolinomio p = new ClsPolinomio(this._grado+Q._grado);
for(int i=0; i <= Q._grado ; i++){
for(int j=0; j<=this._grado;j++){
p._a[i+j]= p._a[i+j]+ Q._a[i]*this._a[j] ;

}
}
return p;
}
public String por (){//inicializamos t poniendo " "
String t=" ";
for (int i=0;i<=this._grado;i++){
t= t + " ( "+_a[this._grado -i]+ "X^" + (this._grado-i) + " ) +";
}
return t;
}
public String ver(){
String linea;
linea="";
for(int i=_grado; i>0 ;i--){
linea = linea + " " + _a[i] + "X^" + i + " + ";}
linea = linea + " " + _a[0] ;
return linea;
}
}
PRY POLINOMIO
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prypolinomios;

/**
*
* @author usuario
*/
public class PryPolinomios {

/**
* @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(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new WinPolinomio().setVisible(true);
}
});// TODO code application logic here
}
}
WIN POLINOMIO
/*
* To change this template, choose Tools | Templates

* and open the template in the editor.


*/

/*
* WinPolinomio.java
*
* Created on 05/06/2015, 08:40:26 AM
*/
package prypolinomios;

/**
*
* @author usuario
*/
public class WinPolinomio extends javax.swing.JFrame {

/** Creates new form WinPolinomio */


public WinPolinomio() {
initComponents();
}
ClsPolinomio p,q,r;
int grd, lim;
float []Coef;
int Codigo;
float valx;
float a,b;

//lim para leer los coeficientes

int n;

private void BtnGradoMouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
grd=Integer.parseInt(TxtPantalla.getText());
lim=grd;
Coef=new float [grd+1];
BtnCoeficiente.setText("Coeficiente("+lim+")");
TxtPantalla.setText(null);
TxtPantalla.requestFocus();
}

private void BtnCoeficienteMouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
if(lim>0){
Coef[lim]=Float.parseFloat(TxtPantalla.getText());
lim-=1;
BtnCoeficiente.setText("Coeficiente("+lim+")");
TxtPantalla.setText(null);
TxtPantalla.requestFocus();
}
else{
Coef[lim]=Float.parseFloat(TxtPantalla.getText());
q=new ClsPolinomio(grd, Coef);
TxtPantalla.setText(q.ver());
TxtPantalla.requestFocus();

}
}

private void BtnMasMouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
p=new ClsPolinomio (q);
Codigo=1;
TxtPantalla.setText(null);
TxtPantalla.requestFocus();
}
private void BtnIgualMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
switch (Codigo){
case 1:
q=new ClsPolinomio(p.mas(q));
break;
case 2:
q=new ClsPolinomio(p.menos(q));
break;
case 3:
q=new ClsPolinomio(p.por(q));
break;
}
TxtPantalla.setText(q.ver());
TxtPantalla.requestFocus();
}

private void BtnMenosMouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
p=new ClsPolinomio (q);
Codigo=2;
TxtPantalla.setText(null);
TxtPantalla.requestFocus();
}
private void BtnPorMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
p=new ClsPolinomio (q);
Codigo=3;
TxtPantalla.setText(null);
TxtPantalla.requestFocus();
}
private void BtnEvaluarMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
valx=Integer.parseInt(TxtPantalla.getText());
TxtPantalla.setText(q.Fx(valx)+"");
}

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {


// TODO add your handling code here:
dispose ();
}

/**

* @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(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(WinPolinomio.class.getName()).log(java.util.l
ogging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new WinPolinomio().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton BtnCoeficiente;
private javax.swing.JButton BtnEvaluar;
private javax.swing.JButton BtnGrado;
private javax.swing.JButton BtnIgual;
private javax.swing.JButton BtnMas;
private javax.swing.JButton BtnMenos;
private javax.swing.JButton BtnPor;
private javax.swing.JTextField TxtPantalla;
private javax.swing.JButton jButton1;
private javax.swing.JToggleButton jToggleButton1;

// End of variables declaration


}

You might also like