Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a java program in java swing or javafx or just java that computes the i

ID: 3831260 • Letter: 1

Question

1. Write a java program in java swing or javafx or just java that computes the intersection point of two lines AB and CD. The user will specify the points A, B, C and D by clicking. Draw a small circle around the intersection point. If the two lines AB and CD do not have a unique intersection point (because they are parallel or coinciding), display a line of text indicating this. Please capture output screen for each different scenario in your report. 2.

2. Write a program that, for four points A, B, C, and P,

- Draws a triangle formed by ABC and a small cross showing the position of P

- Displays a line of text indicating which of the following three cases applies: P lies (a) inside ABC, (b) outside ABC, or (c) on an edge of ABC.

The user will specify the four points by clicking. Please capture output screen for each different scenario in your report.

Make sure you email me the document when you can

Explanation / Answer

import java.awt.Graphics;

import javax.swing.JFrame;

import java.awt.Color;

public class Intersection

    extends java.applet.Applet

    implements java.awt.event.MouseListener

{

  String coordinates= "No click as yet" ;

  public Intersection()

  {

    addMouseListener ( this ) ;

    }

  public void paint ( java.awt.Graphics gr )

  {

    gr.drawString ( coordinates, 10 , 20 );

  }

  public void mouseClicked

   ( java.awt.event.MouseEvent ev )

  {

    int ax ,ay, bx, by, cx,cy, dx, dy ;

     

    ax = ev.getX() ;    

    ay = ev.getY() ;    

    coordinates= " ax = "   + ax +   " , ay = "   + ay ;

                bx = ev.getX() ;    

    by = ev.getY() ;    

    coordinates= " bx = "   + bx +   " , by = "   + by ;

                cx = ev.getX() ;    

    cy = ev.getY() ;    

    coordinates= " cx = "   + cx +   " , cy = "   + cy ;

                dx = ev.getX() ;    

    dy = ev.getY() ;    

    coordinates= " dx = "   + dx +   " , dy = "   + dy ;

    

  }

   

  public void mousePressed(java.awt.event.MouseEvent ev) { }

  public void mouseReleased(java.awt.event.MouseEvent ev) { }

  public void mouseEntered(java.awt.event.MouseEvent ev) { }

  public void mouseExited(java.awt.event.MouseEvent ev) { }

public void intersectionPoint(){

int val = (ay - by) * (ax - bx) -

              (cx - dx) * (cy - dy);

    if (val == 0) // colinear

System.out.println("Points are collinear or parallel");

else{

double xi = ((cx-dx)*(ax*by-ay*bx)-(ax-bx)*(cx*dy-cy*dx))/val;

double yi = ((cy-dy)*(ax*by-ay*bx)-(ay-by)*(cx*dy-cy*dx))/val;// calculating intersection points

}

}

import javafx.application.Application;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.stage.Stage;

import javafx.scene.shape.Circle;

         

public class Circle extends Application {

   @Override

   public void start(Stage stage) {

      //Drawing a Circle

      Circle circle = new Circle();

         Intersection intersect= new Intersection();

      //Setting the properties of the circle

      circle.setCenterX(intersect.xi);

      circle.setCenterY(intersect.yi);

      circle.setRadius(100.0f);

         

      //Creating a Group object

      Group root = new Group(circle);

         

      //Creating a scene object

      Scene scene = new Scene(root, 600, 300);

      //Adding scene to the stage

      stage.setScene(scene);

         

      //Displaying the contents of the stage

      stage.show();

   }

   public static void main(String args[]){

      launch(args);

   }

}      

Similarly you can do for the triangle also.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote