Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a Java program that reads a line and a line segment and then determines whether they intersect or not. When they overlap completely,

Please write a Java program that reads a line and a line segment and then determines whether they intersect or not. When they overlap completely, consider that as intersecting. Use variables ((lp1x, lp1y), (lp2x, lp2y)) to represent a line and ((sp1x, sp1y), (sp2x, sp2y)) to represent a line segment. Some examples:

((lp1x, lp1y), (lp2x, lp2y)) ((sp1x, sp1y), (sp2x, sp2y)) outputs

((0,0),(5,4))((4,0),(0,4))intersecting

((0,0),(5,5))((1,1),(4,4))intersecting

((2,1),(6,1))((4,1),(5,4))intersecting

((0,0),(5,4))((2,0),(4,1))non-intersecting

((1,1),(1,4))((2,3),(5,3))non-intersecting

Divide the problem into four cases using a nested if statement after checking on the inputs:

vertical line and vertical line segment

vertical line and non-vertical line segment

non-vertical line and vertical line segment

non-vertical line and non-vertical line segment

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

Step: 3

blur-text-image

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions