PDA

View Full Version : Guys can anyone here with any Java knowledge help me?



sho.gun
10-11-2001, 08:57 PM
I have to write a program for homework and its driving me crazy. I wrote the thing but it won't compile cuz it has errors and I have no idea what the errors are. I went over the book, nothing, and my teacher didn't really explain this well cuz he speaks like he's drunk. Anyway, can anyone help? This is driving me crazy.

The program is supposed to take a user defined name such as George William Clinton and it's supposed to change it into: Clinton, George W.

This is what I wrote and it says "Cannot Resolve Symbol", and other errors involving the userName variable.



/*
Filename: Name.java
Programmer: Alvin
Project #: 6
Class: MWF 1000-1050
*/


import javax.swing.*;

public class Name
{
public static void main (String[]args)
{
String userName;
char firstName,// The first name
middleName,// The middle name
lastName, // The last name
initial; // The initial

userName = JOptionPane.showInputDialog("Enter first, middle, and last name");
firstName = userName.substring(0,name.indexOf(' '));
middleName = userName.substring(userName.indexOf(' '),userName.lastIndexOf(' '));
lastName = userName.substring(userName.lastIndexOf(' '));
initial = userName.charAt (userName.lastIndexOf(' ') + 1);
System.out.println("The input string is: " + userName );
System.out.println("The output is: " + lastName + "," + firstName + " " + initial + ".");
System.exit(0);
}
}



Thanks if anyone can help.

Burzhui
10-11-2001, 09:08 PM
right of the bat

public static void main( String args[] )

still workjing on it though

Burzhui
10-11-2001, 09:52 PM
OK here it be


import javax.swing.JOptionPane;

class Name
{
public static void main( String args[] )
{
String userName;
String firstName,// The first name
middleName,// The middle name
lastName, // The last name
initial; // The initial

userName = JOptionPane.showInputDialog("Enter first, middle, and last name");
firstName = userName.substring(userName.indexOf(' '));
middleName = userName.substring(userName.indexOf(' '),userName.lastIndexOf(' '));
lastName = userName.substring(userName.lastIndexOf(' '));
initial = userName.charAt (userName.lastIndexOf(' ') + 1)+"";

System.out.println("The input string is: " + userName );
System.out.println("The output is: " + lastName + "," + firstName + " " + initial + ".");
System.exit(0);
}
}

sho.gun
10-11-2001, 09:57 PM
Thanks again Burzhui!

revil
10-11-2001, 11:00 PM
Originally posted by sho.gun
Thanks again Burzhui!
Don't hear that too often round here. I think he's made a few enemies.

Apex
10-11-2001, 11:18 PM
You know it's late when you read this subject line and think it says "Guys can anyone here with any Jedi knowledge help me?". Either that or I've spent too much time talking with darth.

Sorry, carry on.

sho.gun
10-11-2001, 11:31 PM
Originally posted by revil

Don't hear that too often round here. I think he's made a few enemies.

Thanks Burzhui Thanks Burzhui Thanks Burzhui Thanks Burzhui!

Burzhui
10-12-2001, 04:48 AM
No prob bob, the syntax is all good and it compiles fine, just go through the prog and see that everything works as you expected. good luck with it:cool:

Burzhui
10-12-2001, 04:48 AM
Originally posted by Apex
You know it's late when you read this subject line and think it says "Guys can anyone here with any Jedi knowledge help me?". Either that or I've spent too much time talking with darth.

Sorry, carry on.

the force is strongly with you and it will guide you to bed

sho.gun
10-12-2001, 09:36 AM
Originally posted by Burzhui
No prob bob, the syntax is all good and it compiles fine, just go through the prog and see that everything works as you expected. good luck with it:cool:

Hey yeah, it runs fine now. Just one question, in the line:


initial = userName.charAt (userName.lastIndexOf(' ') + 1)+"";
, how come you added a +"" at the end? If I take that out, the program will not compile. Just wonderin.

Burzhui
10-12-2001, 09:39 AM
because otherwise it's a wrong type, you need any kind of string .

Remember how i changed your types from char to string?

Well you need a string so i just added an empty string to the end

Burzhui
10-12-2001, 11:49 AM
Also, i would really use a string tokenizer for this, it would just make it soo much simpler

sho.gun
10-12-2001, 01:06 PM
Oooh yeah, I forgot about that char stuff. And as for the string tokenizer, we haven't learned that yet so I doubt I'll know how. *sigh*.. this is gonna be a loong 4 years...