Read Chapter 20 Applets Write an applet that asks the user t

Read Chapter 20: Applets Write an applet that asks the user to enter two floating-point numbers, obtains the two numbers from the user and draws their sum, product (multiplication), difference and quotient (division) Input X Input Enter first floating-point value Enter second floating-point value OK Cancel OK Cancel Applet The sum is 99.9 Applet started.

Solution

import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

public class Calculation extends JApplet
{
   private double sum,product,difference,quotient;

   public void init()
   {
       String firstNumber = JOptionPane.showInputDialog(\"Enter first floating-point value\");
       String secondNumber = JOptionPane.showInputDialog(\"Enter second floating-point value\");

       double number1 = Double.parseDouble( firstNumber );
       double number2 = Double.parseDouble( secondNumber );

       sum = number1 + number2;
difference = number1 - number2;
product = number1 * number2 ;
quotient= number1 / number2 ;
   }

   public void paint( Graphics g )
   {
       super.paint( g );
       g.drawString( \"The sum is \" + sum, 30, 20 );
g.drawString( \"The difference is \" + difference, 30, 40 );
g.drawString( \"The product is \" + product, 30, 60 );
g.drawString( \"The quotient is \" + quotient, 30, 80 );
   }
}

 Read Chapter 20: Applets Write an applet that asks the user to enter two floating-point numbers, obtains the two numbers from the user and draws their sum, pro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site