Hello, Script error someone help please?
Well, i am very new to java and am taking a computer science course at my school. for our first project we where asked to create a very simple code that took the users birthdate input (month date, year [format]). Then it took that birthdate and broke it up using strings, displaying the users month of birth date of birth and year of birth into a message box.
My problem is that i got everything to work except for when it shows the user Date of birth, for me it always adds the , year next to the date and everything i have tried yas lead me into complier errors or not done the desired results
well here is my code can anyone help me fix the problem?
Quote:
/* Author: Arsalan Modjbafan
* Due date: 08-25-04
* Lab #: Lab 2A
* File: Birthday.Java
*
* The Lab2A class will bring up an input box that asks for a users birth date
* Then uses that information to show them a message spliting up the Month Day and Year
*/
import javax.swing.*;
public class Birthday {
public static void main( String[] args) {
JFrame lab2A;
lab2A = new JFrame();
lab2A.setSize(700,400);
lab2A.setLocation(324,0);
lab2A.setTitle("Lab 2A");
lab2A.setVisible(true);
String month, day, year, birthday;
birthday = JOptionPane.showInputDialog(lab2A,
"Enter birth date in the format Month Day, Year\nFor example: August 25, 2004");
month = birthday.substring(0, birthday.indexOf(" "));
day = birthday.substring(birthday.indexOf(" ") + 1);
year = birthday.substring(birthday.indexOf(", ") + 1);
JOptionPane.showMessageDialog(lab2A, "Month: " + month + "\nDay: " + day + "\nYear: " + year);
}
}