Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA In course unit 2, you were introduced to the Input methods that could be used to get user input using dialog boxes. If you

JAVA

In course unit 2, you were introduced to the Input methods that could be used to get user input using dialog boxes. If you need a refresher on these methods, read the Input Methods tutorial in this course unit and download the compiled file Input.class to your computer (if you havent done so earlier in this course). If you have trouble using the Input.class file, you may have to download the Input.java source code and compile it on your computer. The compiled file and the source file can both be found in the course downloads folder.

The Input class methods can be used to enter program input data using a dialog box. Program output can also be displayed in a dialog box using the JOptionPane class. The syntax for using JOptionPane to display output is as follows:

JOptionPane.showMessageDialog( null, strg );

Where string is a variable of type String and contains the output information you want to display. For example,

JOptionPane.showMessageDialog( null, The date is 3/12/2012 );

Would produce the following output:

image text in transcribed

Design a Date class that models a date as having integer month, day, and year attributes. Include appropriate methods to make the Date class functional and easy to reuse. Write a program called DateExercise that uses dialog boxes to prompt the user for the month, day, and year attributes and displays the message The date is mm/dd/yy in a dialog box.

Input class file :

import javax.swing.*; public class Input { public static byte getByte( String s ) { String input = JOptionPane.showInputDialog( s ); return Byte.parseByte( input ); } public static short getShort( String s ) { String input = JOptionPane.showInputDialog( s ); return Short.parseShort( input ); } public static int getInt( String s ) { String input = JOptionPane.showInputDialog( s ); return Integer.parseInt( input ); } public static long getLong( String s ) { String input = JOptionPane.showInputDialog( s ); return Long.parseLong( input ); } public static float getFloat( String s ) { String input = JOptionPane.showInputDialog( s ); return Float.parseFloat( input ); } public static double getDouble( String s ) { String input = JOptionPane.showInputDialog( s ); return Double.parseDouble( input ); } public static boolean getBoolean( String s ) { String input = JOptionPane.showInputDialog( s ); return Boolean.parseBoolean( input ); } public static char getChar( String s ) { String input = JOptionPane.showInputDialog( s ); return input.charAt(0); } public static String getString( String s ) { String input = JOptionPane.showInputDialog( s ); return input; } } } 
Message i The date is 3/12/2012 OK

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions