Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong on this?

Status
Not open for further replies.

chals1

Technical User
Sep 3, 2003
73
ES
i've put:

class menu {
public static void main(String args[]) {
char eleccionMenu;
char eleccionRead;

public Complejo lectura() {
double a;
double b;

Bla bla...

This is the Javac error:
illegal start of expression
public Complejo lectura() {


 
does the class Complejo exists?
try importing it.
 
My program has two files:
menu.java
Complejo.java

which are located at same directory.
When compiling 'menu', shouldn't 'Complejo' be compiled as well?

I doubt wether is right to use the "public" keyword of Complejo inside a method. Is that an inappropriate place?
 
You have to close your "main" method :

class menu {
public static void main(String args[]) {
char eleccionMenu;
char eleccionRead;
} // Close you main method

public Complejo lectura() {
double a;
double b;

Bla bla...


 
I've followed your post but the same error remains.
Sorry for the repetitive posts but i should have presented this work yesterday.
This is the menu.java:

import consola.*;
class menu {
char eleccionMenu;
public static void main(String args[]) {
char eleccionMenu;
do {
System.out.println("Elija una opción:\n");
System.out.println("1. Sumar dos complejos");
System.out.println("2. Restar dos complejos");
System.out.println("3. Opuesto de un complejo:");
System.out.println("4. Conjugar");
System.out.println("5. Multiplicar dos complejos");
System.out.println("6. Dividir dos complejos");
System.out.println("7. Invertir");
System.out.println("8. Potencia");
System.out.println("9. Raíces");
eleccion = consola.leerchar();
} while( eleccionMenu < '1' || eleccionMenu > '9');
System.out.println(&quot;\n&quot;);

switch (eleccionMenu) {
case '1':
c1=lectura();
c2=lectura();
c3 = c1.sumar(c2);
break;
case '2':
c1=lectura();
c2=lectura();
c3 = c1.restar(c2);
break;
case '3':
c1=lectura();
c2 = c1.opuesto();
break;
case '4':
c1=lectura();
c2 = c1.conjugar();
break;
case '5':
c1=lectura();
c2=lectura();
c3 = c1.multiplicar(c2);
break;
case '6':
c1=lectura();
c2=lectura();
c3 = c1.dividir(c2);
break;
case '7':
c1=lectura();
c2 = c1.invertir();
break;
case '8':
c1=lectura();
c2 = c1.potencia(n);
break;
case '9':
c1=lectura();
c2 = c1.raíces(n);
break;

}
public Complejo lectura() {
char eleccionRead;
double a;
double b;
Complejo c;

do {
System.out.println(&quot;1. Módulo_Argumento&quot;);
System.out.println(&quot;2. Parte real_Parte imaginaria&quot;);
eleccionRead = consola.leerchar();
} while( eleccionRead < '1' || eleccionRead > '2');

a = consola.leerdouble();
b = consola.leerdouble();

if((eleccionMenu < 5) && (eleccionRead == 1)) {
a = getParteReal();
b = getParteImaginaria();
}
if((eleccionMenu > 4) && (eleccionRead == 2)) {
a = getMódulo();
b = getArgumento();
}

c = new Complejo(a,b);
return c;
}

}
 
I repeat, you don't seem to close your main method :

case '9':
c1=lectura();
c2 = c1.raíces(n);
break;

} // This is the closing brace of the &quot;switch&quot;
} // Add this line

public Complejo lectura() {
char eleccionRead;
 
Hologram is exactly right.Do close your main method!

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
turkey_clr.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top