Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I made an applet that will read in two sets of points from the user by using JOptionPane(). The applet will then draw lines between

I made an applet that will read in two sets of points from the user by using JOptionPane(). The applet will then draw lines between the two points in each set. I want to compare the two lines and determine which the longer line is.

import javax.swing.*; import java.awt.*; import java.awt.Graphics; /**  * @author $Yazen Qassem  *  * $Sp18 CSCI 1130-91  */  public class Distances extends JFrame{ public Distances () { int level =0; setTitle( "Distances"); setSize(650, 650); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); String levelStr = JOptionPane.showInputDialog  ("Enter the Distances: "); level = Integer.parseInt(levelStr); } public static void main(String arg[]) { double ax =10; double ay =500; double bx = 10; double by = 10; double cx = 300; double cy = 300; double dx = 300; double dy = 10; double distAB = distance(ax, ay, bx, by); double distCD = distance(cx, cy, dx, dy); double sin60 = 490; System.out.println(distAB); System.out.println(distAB+distCD); } public static double distance(double x1, double y1, double x2, double y2) { double x = Math.pow(x1 - y1, 2); double y = Math.pow(x2,- y2); double dist = Math.sqrt(x + y); return dist; } public void paint (Graphics g) { super.paint(g); g.drawString("Point 1 Line 1(10,10)", 45,100); g.drawString("Point 2 Line 1(10,500)", 45,500); g.drawString("Point 1 Line 2(300,10)", 260,100); g.drawString("Point 2 Line 2(300,500)", 260,500); g.drawLine(30,100,30,500); g.drawLine(250,100,250,500); g.drawString("Line 1 distance: 490.0", 40,550); g.drawString("Line 2 distance: 490.0", 40,570); } } 

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

The answer alone is fine

Answered: 1 week ago

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago