Start New Discussion within our Software Development Community

I'm trying to create a SimpleBirthDay calculator.The requirement is "program must use a Scanner class and JOptionPane class to capture input from user".But i'm having a problem on getting the messagedialogbox to show the result.I found out that using the Scanner class we gonna need to insert the data into the command prompt to show the dialogbox
Am i doing this correctly.Below is my code.

import javax.swing.JOptionPane;
import java.util.Scanner;

public class InputExample2{
	public static void main(String[] args){
		String name = "";
		int month = 0;
		int date =0;
		int year =0;
		int newMonth;
		int newDate;

		JOptionPane.showInputDialog(null, "Please enter your birth month: ");

		JOptionPane.showInputDialog(null, "Please enter your birth date: ");

		JOptionPane.showInputDialog(null, "Please enter your year of birth: ");

		Scanner input = new Scanner(System.in);

		month = input.nextInt();

		newMonth = (((((18 + month)*25)-333)*8)-554)/2;

		year = input.nextInt();
		date = input.nextInt();

		newDate = (((((date * 5)+692)*20)+ year)-32940);


		JOptionPane.showMessageDialog(null,
                        "Your Birthday is: " + newMonth + "-"
                        + newDate + "-" + year);
	} //main
} //class

well, you're asking input using JOptionPane boxes, but you're not using it,
after which, you are asking input in Scanner, but without letting the user know
so, try this:

int year = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your year of birth: "));

and drop that .nextInt();

if you need to use scanner for at least one, print a message with System.out.print("enter month: ");
or something
but use the input you give, and don't write your code so that you have to give double input.

This article has been dead for over six months. Start a new discussion instead.