Results 1 to 5 of 5
Thread: New to the forum + assistance :)
- 10-31-2009, 01:46 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
New to the forum + assistance :)
Hey everyone I'm new to the forum and I signed up because I'm new in Java programming and I am really stuck and I would like more advanced people to assist me.
Thank you in advance :)
The problem is the following: I try to compile, and even though NetBeans doesn't detect any error prior to running, when I do run it I get the following error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - reached end of file while parsing
at obligatorio.Prueba.main(Prueba.java:19)
Java Result: 1
Here's the code:
Can you guys tell what's wrong with the programming? It's most likely a beginner's mistake! Thanks again!Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package obligatorio; import java.util.Scanner; public class Prueba { public static void main(String[] args) { Scanner input = new Scanner(System.in); Empresa E1; E1 = new Empresa(); Empleado P1; P1 = new Empleado(); System.out.println("1: Registre una empresa"); System.out.println("2: Registre un empleado"); System.out.println("3: Registre cosa larga"); int opcion = 0; do { System.out.println("Seleccione una opcion: "); opcion = input.nextInt(); boolean entrada = false; switch(opcion){ case 1:{ opcion = 1; System.out.println("Ingrese nombre: "); E1.setNombre(input.next()); System.out.println("Ingrese rut: "); E1.setRut(input.next()); break;} case 2:{ opcion = 2; System.out.println("Ingrese nombre: "); P1.setNombre(input.next()); System.out.println("Ingrese direccion: "); P1.setDireccion(input.next()); System.out.println("Ingrese documente: "); P1.setDocumento(input.next()); break;} case 3:{ opcion = 3; System.out.println("Aca va la cosa larga"); break;} } if(opcion == 1, 2, 3)){ entrada = true { while (entrada = true){ } }
- 10-31-2009, 02:18 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,538
- Rep Power
- 11
Your braces have to "match". What I mean is that for each { there has to be a later }. I think you may be missing a }.
Note that you don't need to put braces around the blocks of code that make up each of the cases. You can just say:
Also the line "opcion = 1;" is not really needed because you wouldn't get there unless the user had entered 1 and opcion would already be 1.Java Code:switch(opcion) { case 1: opcion = 1; System.out.println("Ingrese nombre: "); E1.setNombre(input.next()); System.out.println("Ingrese rut: "); E1.setRut(input.next()); break; case 2: opcion = 2; // etc
This doesn't make sense. Perhaps you should read up about conditional operators to see how you can express the condition "opcion is 1 or opcion is 2 or opcion is 3".Java Code:if(opcion == 1, 2, 3)) {
Finally use lower case letters to start variables. And make the variables readable even if that makes them a little longer.
Java Code://Empresa E1; //E1 = new Empresa(); Empresa empresa = new Empresa();
Last edited by pbrockway2; 10-31-2009 at 02:20 AM.
- 10-31-2009, 02:20 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,538
- Rep Power
- 11
I haven't addressed the "while(entrada=true){}" business because these other things should be corrected first.
And then you can say what this while loop was supposed to do.
- 10-31-2009, 06:33 AM #4
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
okay thank you, I seem to have fixed the problem and it runs correctly now.
The code is now as follows:
The only problem I seem to be having now is with the input.next(); as it takes only the first word typed as the value when the value should be more than one word in direccion (spanish for address), for instance, which should have a number and a street name. The code as it is now uses the first word as the value for the first set* and the second one for the following one. How do I make input.next() use everything the user types until they hit enter as the value for the first setting?Java Code:import java.util.Scanner; public class Prueba { public static void main(String[] args) { Scanner input = new Scanner(System.in); Empresa e1; e1 = new Empresa(); Empleado p1; p1 = new Empleado(); System.out.println("1: Registre una empresa"); System.out.println("2: Registre un empleado"); System.out.println("3: Registre cosa larga"); int opcion = 0; boolean entrada = false; while(entrada = true){ System.out.println("Seleccione una opcion: "); opcion = input.nextInt(); switch(opcion){ case 1: System.out.printf("Ingrese nombre: "); e1.setNombre(input.next()); System.out.printf("Ingrese rut: "); e1.setRut(input.next()); entrada = true; System.out.println(e1); break; case 2: opcion = 2; System.out.printf("Ingrese nombre: "); p1.setNombre(input.next()); System.out.printf("Ingrese direccion: "); p1.setDireccion(input.next()); System.out.printf("Ingrese documento: "); p1.setDocumento(input.next()); entrada = true; System.out.println(p1); break; case 3: opcion = 3; System.out.printf("Aca va la cosa larga"); entrada = true; break; } } } }
- 10-31-2009, 06:41 AM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Looking for assistance
By s_dawg101 in forum New To JavaReplies: 32Last Post: 11-04-2009, 02:49 AM -
In need of some assistance
By Boer84 in forum New To JavaReplies: 2Last Post: 07-08-2008, 04:14 PM -
X-Tremely new to this...Need assistance...
By Johnny562 in forum New To JavaReplies: 5Last Post: 07-01-2008, 09:17 PM -
[SOLVED] Your assistance required please!
By crazydeo in forum New To JavaReplies: 1Last Post: 05-21-2008, 11:58 AM -
Welcome to our new forum: Forum Lobby
By JavaForums in forum Forum LobbyReplies: 18Last Post: 02-07-2008, 05:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks