69 lines
3.4 KiB
HTML
69 lines
3.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>Triangle.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab6_CalebFontenot/src/main/java/com/calebfontenot/lab6_calebfontenot/Triangle.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> com.calebfontenot.lab6_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> Triangle {
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
|
<span class="comment">// Setup variables</span>
|
|
<span class="literal">double</span> x1,
|
|
y1,
|
|
xIntercept;
|
|
|
|
<span class="comment">// Create scanner</span>
|
|
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
|
|
|
<span class="comment">// Prompt for input</span>
|
|
System.out.print(<span class="string">"</span><span class="string">Enter a point's x and y coords: </span><span class="string">"</span>);
|
|
x1 = input.nextDouble();
|
|
y1 = input.nextDouble();
|
|
|
|
<span class="comment">// Calculate!</span>
|
|
|
|
<span class="comment">// 2. Calculate x by -.5 and add 100 to that</span>
|
|
xIntercept = ((-<span class="number">0.5</span> * x1) + <span class="number">100</span>);
|
|
System.out.println(<span class="string">"</span><span class="string">x intercept is </span><span class="string">"</span> + xIntercept);
|
|
<span class="comment">// Check if y is inside of the triangle</span>
|
|
|
|
<span class="literal">if</span> (y1 <= xIntercept)
|
|
{
|
|
System.out.println(x1 +<span class="string">"</span><span class="string">, </span><span class="string">"</span>+ y1 + <span class="string">"</span><span class="string"> is inside of the triangle!</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">else</span>
|
|
{
|
|
System.out.println(x1 +<span class="string">"</span><span class="string">, </span><span class="string">"</span>+ y1 + <span class="string">"</span><span class="string"> is outside of the triangle!</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|