Hello All,
This is my first time taking Java, so I might need quite a bit of help form ya all.
Anyways, I have this program that has to be in Applet, and it is comparing two floating numbers. I have to have the program decide which one is larger, then say that number is bigger, and if the two numbers are equal, I have to have it specify that these numbers are equal. So I understand what I have done so far, but dont know how to make the program read those instructions. So here is what I have so far, can anyone please help me?
// Java packages
import java.awt.Graphics; // import class Graphics
import javax.swing.*; // import package javax.swing
public class ComparisonApplet extends JApplet {
float comparison; // comparison of values entered by user
// initialize applet by obtaining values from user
public void init()
{
String firstNumber; // first string entered by user
String secondNumber; // second number entered by user
float number1; // first number to be compared
float number2; // second number to be compared
// obtain first number from user
firstNumber = JOptionPane.showInputDialog( "Enter first floating-point value" );
// obtain second number from user
secondNumber = JOptionPane.showInputDialog( "Enter second floating-point value" );
// convert numbers from type String to type float
number1 = Float.parseFloat( firstNumber );
number2 = Float.parseFloat( secondNumber );
// compare numbers
if ( number1 == number2 )
if ( number1 > number2 );
} // end method init
// draw rectangle on applets background
public void paint( Graphics g)
{
// call superclass version of method paint
super.paint( g );
// draw rectangle starting from (15, 10) that is 270
// pixels wide and 20 pixels tall
g.drawRect( 15, 10, 270, 20 );
// draw results as a String at (25,25)
g.drawString( "Is larger" + comparison, 25, 25 );
} // end method paint
} // end class Comparison Applet