CSC 190 Lecture 22: code

6 views2 pages
/**
* class: CSC190
* project: hw4
* date: 9/17/2013
* author:
* purpose: This program will determine if a point lies on a given line
*/
import java.util.Scanner;
public class Decision {
public static void main(String[] args) {
/*
* TODO: Check for divide undefined or 0 lines
*/
Scanner in = new Scanner(System.in);
float lx1, ly1, lx2, ly2, px, py;//inputs
float slope, b; //temps
float decision; //output
System.out.print("Enter the first x endpoint coordinate: " );
lx1 = in.nextFloat();
System.out.print("Enter the first y endpoint coordinate: " );
ly1 = in.nextFloat();
System.out.print("Enter the second x endpoint coordinate: " );
lx2 = in.nextFloat();
System.out.print("Enter the second y endpoint coordinate: " );
ly2 = in.nextFloat();
System.out.print("Enter the x coordinate of the point: " );
px = in.nextFloat();
System.out.print("Enter the y coordinate of the point: " );
py = in.nextFloat();
//find the slope
slope = (ly1 - ly2) / (lx1 - lx2);
//find b
b = (slope * lx1 - ly1) / -1;
/*
* Check for slopes of zero and if the point is on it:
* ((lx1 == lx2) && (px == lx1))
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

* purpose: this program will determine if a point lies on a given line import java. util. scanner; public class decision { public static void main(string[] args) { * todo: check for divide undefined or 0 lines. Scanner in = new scanner(system. in); float lx1, ly1, lx2, ly2, px, py;//inputs float slope, b; //temps float decision; //output. System. out. print("enter the first x endpoint coordinate: " ); lx1 = in. nextfloat(); System. out. print("enter the first y endpoint coordinate: " ); ly1 = in. nextfloat(); System. out. print("enter the second x endpoint coordinate: " ); lx2 = in. nextfloat(); System. out. print("enter the second y endpoint coordinate: " ); ly2 = in. nextfloat(); System. out. print("enter the x coordinate of the point: " ); px = in. nextfloat(); System. out. print("enter the y coordinate of the point: " ); py = in. nextfloat(); //find the slope slope = (ly1 - ly2) / (lx1 - lx2); = (slope * lx1 - ly1) / -1; * check for slopes of zero and if the point is on it:

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions