|
-
JAVA help
Hello,
I have to do this problem and I can't get it to work correctly. There is
something wrong with the display.
I have to have it display on the applet string "this number is greater" or
"numbers are equal" Here is the
source code.
If anyone can help, I would be extremely appreciative. I have been working
on this for almost a week and
I am ready to pull out my hair.
import java.awt.Graphics; //import class Graphics
import javax.swing.*; //import package javax.swing
public class FloatingApplet extends JApplet {
double sum;
public void init ()
{
String firstNumber, //first string number
secondNumber, //second string number
result; //result string number
double number1, //first number to double
number2; //second number to double
//read in first number from user
firstNumber =
JOptionPane.showInputDialog (
"Enter first floating-point value");
secondNumber =
JOptionPane.showInputDialog (
"Enter second floating-point value");
//convert numbers from type string to type double
number1 = Double.parseDouble (firstNumber);
number2 = Double.parseDouble (secondNumber);
//initialize result to empty string
result = "";
if ( number1 > number2 )
result = result + number1 + ">" + number2 ;
if (number1 < number2)
result = result + number1 + "<" + number2 ;
if (number1 == number2)
result = result + number1 + " == " + number2
;
}
public void paint ( Graphics g)
//draw the results with g.drawstring
{
g.drawRect (15, 10, 270, 20);
g.drawString ( "" , 25,25 );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks