Question
I am writing a Results Letter for my class, the application should prompt the user for a patient's first and last names. The application should
I am writing a Results Letter for my class, the application should prompt the user for a patient's first and last names. The application should then extract these names so that a result letter can be constructed. After the application prompts the user to enter a name, a loop control variable is initialized to 0. While the variable remains less than the length of the entered name, each character is compared to the space character. When a space is found, two new strings are created. The first, firstName, is the substring of the original entry from position 0 to the location where the space was found. The second, familyName, is the substring of the original entry from the position after the space to the end of the string. However it is not running correctly in my java compiler, what am I missing?
HERE IS MY CODE BELOW:
import javax.swing.*;
public class ResultsLetter {
public static void main(String[] args) {
String name;
String firstName = "";
String familyName = "";
int x;
char c;
name = JOptionPane.showInputDialog(null, "Please enter patient's first and last name");
x = 0;
while(x < name.length()) {
if(name.charAt(x) == ' ') {
firstName = name.substring (0, x);
familyName = name.substring(x + 1, name.length());
}
++x;
}
JOptionPane.showMessageDialog(null,
"Dear " + firstName +
"\nYour results for your Papsmear that you had done have come back normal." +
"\nPlease feel free to call our office at 479-271-0005 if you have any further questions." +
"\nPlease make sure you are scheduled for your annual exam yearly and pap smear every 3 years." +
"\nSincerely," +
"\nLifespring Women's Healthcare");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started