ASDV-Java/Semester 1/Assignments/lab14_CalebFontenot/StaticMethods.html

154 lines
13 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>StaticMethods.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}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST1 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
.ST2 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
.ST0 {color: #287bde}
.literal {color: #cc7832}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab14_CalebFontenot/src/lab14_calebfontenot/StaticMethods.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> lab14_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> StaticMethods {
<span class="literal">static</span> <span class="literal">int</span> <span class="ST1">executeCount</span> = <span class="number">0</span>;
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
{
StaticMethods.<span class="ST3">printJava</span>();
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; <span class="number">20</span>; i++) {
<span class="literal">for</span> (<span class="literal">int</span> y = <span class="number">0</span>; y &lt; <span class="number">5</span>; y++) {
StaticMethods.<span class="ST3">printMyName</span>();
}
System.<span class="ST1">out</span>.println();
}
<span class="ST1">executeCount</span> = <span class="number">0</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; <span class="number">50</span>; i++) {
<span class="literal">for</span> (<span class="literal">int</span> y = <span class="number">0</span>; y &lt; <span class="number">2</span>; y++) {
StaticMethods.<span class="ST3">printMessage</span>(<span class="string">&quot;</span><span class="string">Java is fun!</span><span class="string">&quot;</span>);
}
System.<span class="ST1">out</span>.println();
}
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">squareNumber</span>(<span class="number">5</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">squareNumber</span>(<span class="number">5</span><span class="number">.0</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">cubeNumber</span>(<span class="number">5</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">cubeNumber</span>(<span class="number">5</span><span class="number">.0</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">menu</span>());
<span class="literal">char</span> menuReturn = StaticMethods.<span class="ST3">menu</span>();
<span class="literal">if</span> (menuReturn == <span class="string">&#39;</span><span class="string">c</span><span class="string">&#39;</span>) {
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">cubeNumber</span>(<span class="number">5</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">cubeNumber</span>(<span class="number">5</span><span class="number">.0</span>));
} <span class="literal">else</span> <span class="literal">if</span> (menuReturn == <span class="string">&#39;</span><span class="string">s</span><span class="string">&#39;</span>) {
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">squareNumber</span>(<span class="number">5</span>));
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">squareNumber</span>(<span class="number">5</span><span class="number">.0</span>));
}
System.<span class="ST1">out</span>.println(StaticMethods.<span class="ST3">menuInteger</span>());
<span class="comment">// Area</span>
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST1">in</span>);
System.<span class="ST1">out</span>.print(<span class="string">&quot;</span><span class="string">Enter the number of sides: </span><span class="string">&quot;</span>);
<span class="literal">int</span> n = input.nextInt();
System.<span class="ST1">out</span>.print(<span class="string">&quot;</span><span class="string">Enter the side: </span><span class="string">&quot;</span>);
<span class="literal">double</span> side = input.nextDouble();
<span class="comment">// Call the area function</span>
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">The area of the polygon is: </span><span class="string">&quot;</span> + StaticMethods.<span class="ST3">area</span>(n, side));
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">printJava</span>() {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">Java</span><span class="string">&quot;</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">printMyName</span>() {
System.<span class="ST1">out</span>.print(<span class="string">&quot;</span><span class="string">Caleb Fontenot </span><span class="string">&quot;</span>);
System.<span class="ST1">out</span>.print(++<span class="ST1">executeCount</span> + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">printMessage</span>(String msg) {
System.<span class="ST1">out</span>.print(msg + <span class="string">&quot;</span> <span class="string">&quot;</span>);
System.<span class="ST1">out</span>.print(++<span class="ST1">executeCount</span> + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST2">squareNumber</span>(<span class="literal">int</span> number) {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">INT (squre) was called</span><span class="string">&quot;</span>);
<span class="literal">return</span> number * number;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST2">squareNumber</span>(<span class="literal">double</span> number) {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">DOUBLE (square) was called</span><span class="string">&quot;</span>);
<span class="literal">return</span> number * number;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST2">cubeNumber</span>(<span class="literal">int</span> number) {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">INT (cube) was called</span><span class="string">&quot;</span>);
<span class="literal">return</span> number * StaticMethods.<span class="ST3">squareNumber</span>(number);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST2">cubeNumber</span>(<span class="literal">double</span> number) {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">DOUBLE (cube) was called</span><span class="string">&quot;</span>);
<span class="literal">return</span> number * StaticMethods.<span class="ST3">squareNumber</span>(number);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">char</span> <span class="ST2">menu</span>() {
String s = <span class="string">&quot;&quot;</span>;
<span class="literal">do</span> {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">type S</span><span class="literal">\\</span><span class="string">s to square a number</span><span class="string">&quot;</span>);
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">type C</span><span class="literal">\\</span><span class="string">c to cube a number</span><span class="string">&quot;</span>);
System.<span class="ST1">out</span>.print(<span class="string">&quot;</span><span class="string">Input: </span><span class="string">&quot;</span>);
s = <span class="literal">new</span> Scanner(System.<span class="ST1">in</span>).next();
<span class="literal">if</span> (<span class="string">&quot;</span><span class="string">c</span><span class="string">&quot;</span>.compareToIgnoreCase(s) != <span class="number">0</span> &amp;&amp; <span class="string">&quot;</span><span class="string">s</span><span class="string">&quot;</span>.compareToIgnoreCase(s) != <span class="number">0</span>) {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="literal">\t</span><span class="string">please enter a valid character</span><span class="string">&quot;</span>);
}
} <span class="literal">while</span> (<span class="string">&quot;</span><span class="string">c</span><span class="string">&quot;</span>.compareToIgnoreCase(s) != <span class="number">0</span> &amp;&amp; <span class="string">&quot;</span><span class="string">s</span><span class="string">&quot;</span>.compareToIgnoreCase(s) != <span class="number">0</span>);
<span class="literal">return</span> s.toLowerCase().charAt(<span class="number">0</span>);
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST2">menuInteger</span>() {
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST1">in</span>);
<span class="literal">int</span> returnInt = -<span class="number">1</span>;
<span class="literal">while</span> (<span class="literal">true</span>) {
System.<span class="ST1">out</span>.print(<span class="string">&quot;</span><span class="string">Enter an integer (must be 1000, 2000, or 3000): </span><span class="string">&quot;</span>);
returnInt = input.nextInt();
<span class="literal">if</span> (returnInt == <span class="number">1000</span>){
<span class="literal">return</span> returnInt;
}
<span class="literal">else</span> <span class="literal">if</span> (returnInt == <span class="number">2000</span>) {
<span class="literal">return</span> returnInt;
}
<span class="literal">else</span> <span class="literal">if</span> (returnInt == <span class="number">3000</span>) {
<span class="literal">return</span> returnInt;
}
<span class="literal">else</span> {
System.<span class="ST1">out</span>.println(<span class="string">&quot;</span><span class="string">Integer not allowed, try again</span><span class="string">&quot;</span>);
}
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST2">area</span>(<span class="literal">int</span> n, <span class="literal">double</span> side) {
<span class="comment">// Compute area</span>
<span class="literal">return</span> (n * Math.<span class="ST3">pow</span>(side, <span class="number">2</span>)) / (<span class="number">4.0</span> * Math.<span class="ST3">tan</span>(Math.<span class="ST1">PI</span> / n));
}
}
</pre></body>
</html>