954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What is wrong with this code, (i am so frustrated please help!)

I created a little beginners program, and its about a Telephone network which has an operator and three clients: i made four classes, and it gives me error at planta and cliente

In cliente it gives error on public class cliente private operadora
Im Planta it gives me error in the fourth line

Pleaase Help!

1. Main Class

package mensajes;
public class Main {

    public static void main(String[] args) {
        Cliente c1 = new Cliente();            
        Cliente c2 = new Cliente ();
        Cliente c3 = new Cliente ();
        c1.setNombre("Julio");
        c1.setTelefono("12345678");
        c2.setNombre("Ana");
        c2.setTelefono("97812344");
        c3.setNombre("Gema");
        c3.setTelefono("45678922");
        Operadora op= new Operadora();
        op.suscribir(c1, c2, c3);
        c1.registrarOperadora(op);
        c2.registrarOperadora(op);
        c3.registrarOperadora(op);
        op.ponerTiempo(20);
        c1.llamar("1", 5);



    }

}


Cliente class

public class Cliente

{
private String nombre;
private String telefono;
private Operadora  op;
public void setNombre(String n){nombre=n;}
public void setTelefono (String t){telefono=t;}
public String getNombre(){return nombre;}
public String getTelefono (){return telefono;}
public void registrarOperadora(Operadora ref)
{
    op=ref;
}
public void llamar(String n, float t)
    {
     op.llamar(n,t);

}
public void responder()
    {
  JOptionPane.showMessageDialog(null,
          "Hola mi nombre es "+nombre+
          "y mi numero es "+telefono);
}


}

Plant Class

package mensajes;
public class Planta {
    private float tiempoAire;
    Cliente c1, c2, c3;   //
    public void setTiempo (float t){tiempoAire+=t;}
    public float getTiempo (){return tiempoAire;}
    public void suscribir (Cliente a, Cliente b, Cliente c)
    {
    c1 =a; c2=b; c3=c;
    }

public void llamar (String n, float t)

{
     this.tiempoAire-=t;
     if(c1.getNombre()==n)
         c1.responder();

else
    if (c2.getNombre()==n)
        c2.responder();

else
    c3.responder();

}
}

Operadora class

package mensajes;
import javax.swing.JOptionPane;
public class Operadora {
    private Planta p = new Planta (); //composicion
public void suscribir (Cliente a, Cliente b, Cliente c)
    {
    p.suscribir(a, b, c);
    }
public void llamar (String n, float t)
    {
    if(p.getTiempo()<t)
        JOptionPane.showMessageDialog(null,
                "Su llamada no puede realizarse. "+
                "El tiempo disponible es: " +
                p.getTiempo());

    else
        p.llamar(n, t);
}
public void  ponerTiempo(float t)
    {
   p.setTiempo(t);
}



}
rayden150
Light Poster
32 posts since Aug 2010
Reputation Points: 9
Solved Threads: 0
 

I had to add 2 lines to Cliente.java:

package mensajes;

import javax.swing.*;


Then the code compiled & ran. I did not see the errors you mention above.

kramerd
Posting Pro in Training
403 posts since Sep 2010
Reputation Points: 49
Solved Threads: 73
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: