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.
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.