ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/QuadraticEquation.html

124 lines
7.7 KiB
HTML
Raw Normal View History

2023-01-26 12:27:18 -06:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>QuadraticEquation.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}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.ST2 {color: #9876aa}
.ST3 {color: #ffc66d}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST5 {color: #ffc66d; font-family: monospace; font-style: italic}
.ST6 {color: #9876aa; font-family: monospace; font-style: italic}
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST4 {font-family: monospace; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab2_CalebFontenot/src/main/java/com/calebfontenot/lab5_calebfontenot/QuadraticEquation.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab5_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> QuadraticEquation {
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">a</span>;
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">b</span>;
<span class="literal">private</span> <span class="literal">double</span> <span class="ST2">c</span>;
<span class="literal">public</span> QuadraticEquation(<span class="literal">double</span> a, <span class="literal">double</span> b, <span class="literal">double</span> c)
{
<span class="literal">this</span>.<span class="ST2">a</span> = a;
<span class="literal">this</span>.<span class="ST2">b</span> = b;
<span class="literal">this</span>.<span class="ST2">c</span> = c;
}
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getDiscriminant</span>()
{
<span class="literal">return</span> <span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>;
}
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getRoot1</span>()
{
<span class="literal">if</span> (getDiscriminant() &lt; <span class="number">0</span>) {
<span class="literal">return</span> -<span class="number">88888888</span>;
}
<span class="literal">return</span> (<span class="ST2">b</span> + Math.<span class="ST4">sqrt</span>(<span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>)) / (<span class="number">2</span> * <span class="ST2">a</span>);
}
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getRoot2</span>()
{
<span class="literal">if</span> (getDiscriminant() &lt; <span class="number">0</span>) {
<span class="literal">return</span> -<span class="number">88888888</span>;
}
<span class="literal">return</span> (-<span class="ST2">b</span> + Math.<span class="ST4">sqrt</span>(<span class="ST2">b</span> * <span class="ST2">b</span> - <span class="number">4</span> * <span class="ST2">a</span> * <span class="ST2">c</span>)) / (<span class="number">2</span> * <span class="ST2">a</span>);
<span class="comment">//return getDiscriminant() &lt; 0 ? 0</span>
<span class="comment">// : ((-b) + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);</span>
}
@Override
<span class="literal">public</span> String <span class="ST3">toString</span>()
{
<span class="literal">return</span> <span class="string">&quot;</span><span class="string">QuadraticEquation{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">a=</span><span class="string">&quot;</span> + <span class="ST2">a</span> + <span class="string">&quot;</span><span class="string">, b=</span><span class="string">&quot;</span> + <span class="ST2">b</span> + <span class="string">&quot;</span><span class="string">, c=</span><span class="string">&quot;</span> + <span class="ST2">c</span> + <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">b</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">b</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getB</span>()
{
<span class="literal">return</span> <span class="ST2">b</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">c</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">c</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getC</span>()
{
<span class="literal">return</span> <span class="ST2">c</span>;
}
<span class="comment">/**</span>
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">a</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">a</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getA</span>()
{
<span class="literal">return</span> <span class="ST2">a</span>;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST5">main</span>(String[] args)
{
QuadraticEquation eq1 = <span class="literal">new</span> QuadraticEquation(<span class="number">1</span>, -<span class="number">4</span>, <span class="number">4</span>);
System.<span class="ST6">out</span>.println(eq1);
System.<span class="ST6">out</span>.println(eq1.getRoot1());
System.<span class="ST6">out</span>.println(eq1.getRoot2());
}
}
</pre></body>
</html>