Finish Lab8
This commit is contained in:
parent
3b21e05ce0
commit
d9b25652f4
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@
|
||||
/03_Sep13_2022/target/
|
||||
/lab7_CalebFontenot/target/
|
||||
/MP2_CalebFontenot/target/
|
||||
/lab8_CalebFontenot/target/
|
||||
|
BIN
lab8_CalebFontenot.zip
Normal file
BIN
lab8_CalebFontenot.zip
Normal file
Binary file not shown.
53
lab8_CalebFontenot/ConditionalOperator1.html
Normal file
53
lab8_CalebFontenot/ConditionalOperator1.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ConditionalOperator1.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator1.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.lab8_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> ConditionalOperator1 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">please enter an even number: </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> number = scan.nextInt();
|
||||
<span class="literal">if</span> ( number % <span class="number">2</span> == <span class="number">0</span> )
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="literal">\n</span><span class="string">"</span> + number + <span class="string">"</span><span class="string"> fufills the request!</span><span class="string">"</span>);
|
||||
<span class="literal">else</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="literal">\n</span><span class="string">"</span> + number + <span class="string">"</span><span class="string"> does not fufill the request!</span><span class="string">"</span>);
|
||||
|
||||
System.<span class="ST2">out</span>.println(number % <span class="number">2</span> == <span class="number">0</span> ? <span class="string">"</span><span class="string"> yes sir!</span><span class="string">"</span> : <span class="string">"</span><span class="string"> no sir!</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
45
lab8_CalebFontenot/ConditionalOperator2.html
Normal file
45
lab8_CalebFontenot/ConditionalOperator2.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ConditionalOperator2.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}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator2.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.lab8_calebfontenot;
|
||||
|
||||
<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> ConditionalOperator2 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
java.util.Scanner input = <span class="literal">new</span> java.util.Scanner(System.<span class="ST2">in</span>);
|
||||
<span class="literal">double</span> x = input.nextDouble();
|
||||
<span class="literal">double</span> y = input.nextDouble();
|
||||
<span class="literal">double</span> z = input.nextDouble();
|
||||
System.<span class="ST2">out</span>.println((x < y && y < z) ? <span class="string">"</span><span class="string">sorted</span><span class="string">"</span> : <span class="string">"</span><span class="string">not sorted</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
45
lab8_CalebFontenot/ConditionalOperator3.html
Normal file
45
lab8_CalebFontenot/ConditionalOperator3.html
Normal file
@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ConditionalOperator3.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}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator3.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.lab8_calebfontenot;
|
||||
|
||||
<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> ConditionalOperator3 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
java.util.Scanner input = <span class="literal">new</span> java.util.Scanner(System.<span class="ST2">in</span>);
|
||||
<span class="literal">double</span> x = input.nextDouble();
|
||||
<span class="literal">double</span> y = input.nextDouble();
|
||||
<span class="literal">double</span> z = input.nextDouble();
|
||||
System.<span class="ST2">out</span>.println((x < y && y < z) ? <span class="number">100</span> : <span class="number">200</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
53
lab8_CalebFontenot/ConditionalOperator4.html
Normal file
53
lab8_CalebFontenot/ConditionalOperator4.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ConditionalOperator4.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/ConditionalOperator4.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.lab8_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> ConditionalOperator4 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">please enter an even number: </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> number = scan.nextInt();
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="literal">\n</span><span class="string">"</span> + number + ( number % <span class="number">2</span> == <span class="number">0</span> ? <span class="string">"</span><span class="string"> fufills the request!</span><span class="string">"</span> : <span class="string">"</span><span class="string"> does not fufill the request!</span><span class="string">"</span>));
|
||||
|
||||
<span class="literal">if</span> (number % <span class="number">2</span> == <span class="number">0</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string"> yes sir!</span><span class="string">"</span>);
|
||||
<span class="literal">else</span>
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string"> no sir!</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
94
lab8_CalebFontenot/DecimalToHex1.html
Normal file
94
lab8_CalebFontenot/DecimalToHex1.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>DecimalToHex1.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: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; 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/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex1.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.lab8_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> DecimalToHex1 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> inputDecimal,
|
||||
outputHex = <span class="number">0x0</span>;
|
||||
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
<span class="comment">// Prompt for input</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a decimal value (0-15): </span><span class="string">"</span>);
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
<span class="comment">// Switch moment</span>
|
||||
<span class="literal">switch</span> (inputDecimal) {
|
||||
<span class="literal">case</span> <span class="number">0</span>:
|
||||
outputHex = <span class="number">0x0</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">1</span>:
|
||||
outputHex = <span class="number">0x1</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>:
|
||||
outputHex = <span class="number">0x2</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">3</span>:
|
||||
outputHex = <span class="number">0x3</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">4</span>:
|
||||
outputHex = <span class="number">0x4</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">5</span>:
|
||||
outputHex = <span class="number">0x5</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">6</span>:
|
||||
outputHex = <span class="number">0x6</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">7</span>:
|
||||
outputHex = <span class="number">0x7</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">8</span>:
|
||||
outputHex = <span class="number">0x8</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">9</span>:
|
||||
outputHex = <span class="number">0x9</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">10</span>:
|
||||
outputHex = <span class="number">0xA</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">11</span>:
|
||||
outputHex = <span class="number">0xB</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">12</span>:
|
||||
outputHex = <span class="number">0xC</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">13</span>:
|
||||
outputHex = <span class="number">0xD</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">14</span>:
|
||||
outputHex = <span class="number">0xE</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">15</span>:
|
||||
outputHex = <span class="number">0xF</span>; <span class="literal">break</span>;
|
||||
|
||||
}
|
||||
|
||||
<span class="comment">// Output</span>
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">The hex value is </span><span class="string">"</span> + String.<span class="ST3">format</span>(<span class="string">"</span><span class="string">%x</span><span class="string">"</span>, outputHex));
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
93
lab8_CalebFontenot/DecimalToHex2.html
Normal file
93
lab8_CalebFontenot/DecimalToHex2.html
Normal file
@ -0,0 +1,93 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>DecimalToHex2.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: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; 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/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/DecimalToHex2.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.lab8_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> DecimalToHex2 {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> inputDecimal,
|
||||
outputHex = <span class="number">0x0</span>;
|
||||
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
<span class="comment">// Prompt for input </span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a decimal value (0-15): </span><span class="string">"</span>);
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
<span class="comment">// Switch moment</span>
|
||||
<span class="literal">if</span> (inputDecimal == <span class="number">0</span>) {
|
||||
outputHex = <span class="number">0x0</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">1</span>) {
|
||||
outputHex = <span class="number">0x1</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">2</span>) {
|
||||
outputHex = <span class="number">0x2</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">3</span>) {
|
||||
outputHex = <span class="number">0x3</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">4</span>) {
|
||||
outputHex = <span class="number">0x4</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">5</span>) {
|
||||
outputHex = <span class="number">0x5</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">6</span>) {
|
||||
outputHex = <span class="number">0x6</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">7</span>) {
|
||||
outputHex = <span class="number">0x7</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">8</span>) {
|
||||
outputHex = <span class="number">0x8</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">9</span>) {
|
||||
outputHex = <span class="number">0x9</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">10</span>) {
|
||||
outputHex = <span class="number">0xA</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">11</span>) {
|
||||
outputHex = <span class="number">0xB</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">12</span>) {
|
||||
outputHex = <span class="number">0xC</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">13</span>) {
|
||||
outputHex = <span class="number">0xD</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">14</span>) {
|
||||
outputHex = <span class="number">0xE</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (inputDecimal == <span class="number">15</span>) {
|
||||
outputHex = <span class="number">0xF</span>;
|
||||
}
|
||||
|
||||
<span class="comment">// Output</span>
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">The hex value is </span><span class="string">"</span> + String.<span class="ST3">format</span>(<span class="string">"</span><span class="string">%x</span><span class="string">"</span>, outputHex));
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
63
lab8_CalebFontenot/Switch1.html
Normal file
63
lab8_CalebFontenot/Switch1.html
Normal file
@ -0,0 +1,63 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch1.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1.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.lab8_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> Switch1 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a year to tell you a Chinese joke: </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> year = input.nextInt();
|
||||
|
||||
<span class="literal">switch</span> (year % <span class="number">12</span>) {
|
||||
<span class="literal">case</span> <span class="number">0</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">monkey</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">1</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rooster</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">dog</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">3</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">pig</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">4</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rat</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">5</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">ox</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">6</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">tiger</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">7</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rabbit</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">8</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">dragon</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">9</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">snake</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">10</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">horse</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">11</span>: System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">sheep</span><span class="string">"</span>); <span class="literal">break</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
73
lab8_CalebFontenot/Switch1ConvertedToIfElse.html
Normal file
73
lab8_CalebFontenot/Switch1ConvertedToIfElse.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch1ConvertedToIfElse.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch1ConvertedToIfElse.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.lab8_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> Switch1ConvertedToIfElse {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a year to tell you a Chinese joke: </span><span class="string">"</span>);
|
||||
<span class="literal">int</span> year = input.nextInt();
|
||||
|
||||
<span class="literal">if</span> (year == <span class="number">0</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">monkey</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">1</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rooster</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">2</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">dog</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">3</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">pig</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">4</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rat</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">5</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">ox</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">6</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">tiger</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">7</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">rabbit</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">8</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">dragon</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">9</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">snake</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">10</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">horse</span><span class="string">"</span>);
|
||||
<span class="literal">else</span> <span class="literal">if</span> (year == <span class="number">11</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">sheep</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
50
lab8_CalebFontenot/Switch2.html
Normal file
50
lab8_CalebFontenot/Switch2.html
Normal file
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch2.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: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch2.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.lab8_calebfontenot;
|
||||
|
||||
<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> Switch2 {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> x = <span class="number">1</span>, a = <span class="number">3</span>;
|
||||
<span class="literal">switch</span> (a) {
|
||||
<span class="literal">case</span> <span class="number">1</span>: x += <span class="number">5</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>: x += <span class="number">10</span>;
|
||||
<span class="literal">case</span> <span class="number">3</span>: x += <span class="number">16</span>;
|
||||
<span class="literal">case</span> <span class="number">4</span>: x+= <span class="number">34</span>;
|
||||
}
|
||||
System.<span class="ST2">out</span>.println(x + <span class="string">"</span><span class="string">, </span><span class="string">"</span> + a);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
92
lab8_CalebFontenot/Switch3.html
Normal file
92
lab8_CalebFontenot/Switch3.html
Normal file
@ -0,0 +1,92 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch3.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.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.lab8_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> Switch3 {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> dayOfWeekInt;
|
||||
String dayOfWeekString = <span class="string">"</span><span class="string">nullday</span><span class="string">"</span>,
|
||||
ordinal = <span class="string">"</span><span class="string">0th</span><span class="string">"</span>;
|
||||
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
<span class="comment">// Prompt for input</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a number that signifies a day of the week: </span><span class="string">"</span>);
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
<span class="comment">// Switch moment</span>
|
||||
<span class="literal">switch</span> (dayOfWeekInt) {
|
||||
<span class="literal">case</span> <span class="number">1</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Sunday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">1st</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Monday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">2nd</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">3</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Tuesday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">3rd</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">4</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Wednesday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">4th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">5</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Thursday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">5th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">6</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Friday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">6th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">7</span>:
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Saturday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">7th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
}
|
||||
<span class="comment">// Print output</span>
|
||||
<span class="literal">if</span> (dayOfWeekInt > <span class="number">7</span>)
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">That number is too high.</span><span class="string">"</span>);
|
||||
<span class="literal">else</span>
|
||||
System.<span class="ST2">out</span>.println(dayOfWeekString + <span class="string">"</span><span class="string"> is the </span><span class="string">"</span> + ordinal + <span class="string">"</span><span class="string"> day of the week.</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
86
lab8_CalebFontenot/Switch3ConvertedToIfElse.html
Normal file
86
lab8_CalebFontenot/Switch3ConvertedToIfElse.html
Normal file
@ -0,0 +1,86 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch3ConvertedToIfElse.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}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.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.lab8_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> Switch3ConvertedToIfElse {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
<span class="literal">int</span> dayOfWeekInt;
|
||||
String dayOfWeekString = <span class="string">"</span><span class="string">nullday</span><span class="string">"</span>,
|
||||
ordinal = <span class="string">"</span><span class="string">0th</span><span class="string">"</span>;
|
||||
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
<span class="comment">// Prompt for input</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a number that signifies a day of the week: </span><span class="string">"</span>);
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
<span class="comment">// No longer Switch moment</span>
|
||||
<span class="literal">if</span> (dayOfWeekInt == <span class="number">1</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Sunday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">1st</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">2</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Monday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">2nd</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">3</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Tuesday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">3rd</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">4</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Wednesday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">4th</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">5</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Thursday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">5th</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">6</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Friday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">6th</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (dayOfWeekInt == <span class="number">7</span>) {
|
||||
dayOfWeekString = <span class="string">"</span><span class="string">Saturday</span><span class="string">"</span>;
|
||||
ordinal = <span class="string">"</span><span class="string">7th</span><span class="string">"</span>;
|
||||
}
|
||||
|
||||
<span class="comment">// Print output</span>
|
||||
<span class="literal">if</span> (dayOfWeekInt > <span class="number">7</span>) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">That number is too high.</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> {
|
||||
System.<span class="ST2">out</span>.println(dayOfWeekString + <span class="string">"</span><span class="string"> is the </span><span class="string">"</span> + ordinal + <span class="string">"</span><span class="string"> day of the week.</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
80
lab8_CalebFontenot/Switch4.html
Normal file
80
lab8_CalebFontenot/Switch4.html
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Switch4.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}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.literal {color: #cc7832}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch4.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.lab8_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> Switch4 {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="comment">// Define vars</span>
|
||||
String dayOfWeekString = <span class="string">"</span><span class="string">Nullday</span><span class="string">"</span>,
|
||||
ordinal = <span class="string">"</span><span class="string">0th</span><span class="string">"</span>;
|
||||
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
|
||||
<span class="comment">// Prompt for input</span>
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a day of the week (Case-Sensitive): </span><span class="string">"</span>);
|
||||
dayOfWeekString = input.next();
|
||||
|
||||
<span class="comment">// Switch moment</span>
|
||||
<span class="literal">switch</span> (dayOfWeekString) {
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Sunday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">1st</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Monday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">2nd</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Tuesday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">3rd</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Wednesday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">4th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Thursday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">5th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Friday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">6th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="string">"</span><span class="string">Saturday</span><span class="string">"</span>:
|
||||
ordinal = <span class="string">"</span><span class="string">7th</span><span class="string">"</span>;
|
||||
<span class="literal">break</span>;
|
||||
}
|
||||
<span class="comment">// Print output</span>
|
||||
System.<span class="ST2">out</span>.println(dayOfWeekString + <span class="string">"</span><span class="string"> is the </span><span class="string">"</span> + ordinal + <span class="string">"</span><span class="string"> day of the week.</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
BIN
lab8_CalebFontenot/lab8-2-1.pdf
Normal file
BIN
lab8_CalebFontenot/lab8-2-1.pdf
Normal file
Binary file not shown.
14
lab8_CalebFontenot/pom.xml
Normal file
14
lab8_CalebFontenot/pom.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.calebfontenot</groupId>
|
||||
<artifactId>lab8_CalebFontenot</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<exec.mainClass>com.calebfontenot.lab8_calebfontenot.Lab8_CalebFontenot</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ConditionalOperator1 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
System.out.print("please enter an even number: ");
|
||||
int number = scan.nextInt();
|
||||
if ( number % 2 == 0 )
|
||||
System.out.print("\n" + number + " fufills the request!");
|
||||
else
|
||||
System.out.print("\n" + number + " does not fufill the request!");
|
||||
|
||||
System.out.println(number % 2 == 0 ? " yes sir!" : " no sir!");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ConditionalOperator2 {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
double x = input.nextDouble();
|
||||
double y = input.nextDouble();
|
||||
double z = input.nextDouble();
|
||||
System.out.println((x < y && y < z) ? "sorted" : "not sorted");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ConditionalOperator3 {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
double x = input.nextDouble();
|
||||
double y = input.nextDouble();
|
||||
double z = input.nextDouble();
|
||||
System.out.println((x < y && y < z) ? 100 : 200);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class ConditionalOperator4 {
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
|
||||
System.out.print("please enter an even number: ");
|
||||
int number = scan.nextInt();
|
||||
System.out.print("\n" + number + ( number % 2 == 0 ? " fufills the request!" : " does not fufill the request!"));
|
||||
|
||||
if (number % 2 == 0)
|
||||
System.out.println(" yes sir!");
|
||||
else
|
||||
System.out.println(" no sir!");
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DecimalToHex1 {
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int inputDecimal,
|
||||
outputHex = 0x0;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a decimal value (0-15): ");
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
switch (inputDecimal) {
|
||||
case 0:
|
||||
outputHex = 0x0; break;
|
||||
case 1:
|
||||
outputHex = 0x1; break;
|
||||
case 2:
|
||||
outputHex = 0x2; break;
|
||||
case 3:
|
||||
outputHex = 0x3; break;
|
||||
case 4:
|
||||
outputHex = 0x4; break;
|
||||
case 5:
|
||||
outputHex = 0x5; break;
|
||||
case 6:
|
||||
outputHex = 0x6; break;
|
||||
case 7:
|
||||
outputHex = 0x7; break;
|
||||
case 8:
|
||||
outputHex = 0x8; break;
|
||||
case 9:
|
||||
outputHex = 0x9; break;
|
||||
case 10:
|
||||
outputHex = 0xA; break;
|
||||
case 11:
|
||||
outputHex = 0xB; break;
|
||||
case 12:
|
||||
outputHex = 0xC; break;
|
||||
case 13:
|
||||
outputHex = 0xD; break;
|
||||
case 14:
|
||||
outputHex = 0xE; break;
|
||||
case 15:
|
||||
outputHex = 0xF; break;
|
||||
|
||||
}
|
||||
|
||||
// Output
|
||||
System.out.println("The hex value is " + String.format("%x", outputHex));
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DecimalToHex2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int inputDecimal,
|
||||
outputHex = 0x0;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a decimal value (0-15): ");
|
||||
inputDecimal = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
if (inputDecimal == 0) {
|
||||
outputHex = 0x0;
|
||||
} else if (inputDecimal == 1) {
|
||||
outputHex = 0x1;
|
||||
} else if (inputDecimal == 2) {
|
||||
outputHex = 0x2;
|
||||
} else if (inputDecimal == 3) {
|
||||
outputHex = 0x3;
|
||||
} else if (inputDecimal == 4) {
|
||||
outputHex = 0x4;
|
||||
} else if (inputDecimal == 5) {
|
||||
outputHex = 0x5;
|
||||
} else if (inputDecimal == 6) {
|
||||
outputHex = 0x6;
|
||||
} else if (inputDecimal == 7) {
|
||||
outputHex = 0x7;
|
||||
} else if (inputDecimal == 8) {
|
||||
outputHex = 0x8;
|
||||
} else if (inputDecimal == 9) {
|
||||
outputHex = 0x9;
|
||||
} else if (inputDecimal == 10) {
|
||||
outputHex = 0xA;
|
||||
} else if (inputDecimal == 11) {
|
||||
outputHex = 0xB;
|
||||
} else if (inputDecimal == 12) {
|
||||
outputHex = 0xC;
|
||||
} else if (inputDecimal == 13) {
|
||||
outputHex = 0xD;
|
||||
} else if (inputDecimal == 14) {
|
||||
outputHex = 0xE;
|
||||
} else if (inputDecimal == 15) {
|
||||
outputHex = 0xF;
|
||||
}
|
||||
|
||||
// Output
|
||||
System.out.println("The hex value is " + String.format("%x", outputHex));
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||
*/
|
||||
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Lab8_CalebFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch1 {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter a year to tell you a Chinese joke: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
switch (year % 12) {
|
||||
case 0: System.out.println("monkey"); break;
|
||||
case 1: System.out.println("rooster"); break;
|
||||
case 2: System.out.println("dog"); break;
|
||||
case 3: System.out.println("pig"); break;
|
||||
case 4: System.out.println("rat"); break;
|
||||
case 5: System.out.println("ox"); break;
|
||||
case 6: System.out.println("tiger"); break;
|
||||
case 7: System.out.println("rabbit"); break;
|
||||
case 8: System.out.println("dragon"); break;
|
||||
case 9: System.out.println("snake"); break;
|
||||
case 10: System.out.println("horse"); break;
|
||||
case 11: System.out.println("sheep"); break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch1ConvertedToIfElse {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
System.out.print("Enter a year to tell you a Chinese joke: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
if (year == 0)
|
||||
System.out.println("monkey");
|
||||
else if (year == 1)
|
||||
System.out.println("rooster");
|
||||
else if (year == 2)
|
||||
System.out.println("dog");
|
||||
else if (year == 3)
|
||||
System.out.println("pig");
|
||||
else if (year == 4)
|
||||
System.out.println("rat");
|
||||
else if (year == 5)
|
||||
System.out.println("ox");
|
||||
else if (year == 6)
|
||||
System.out.println("tiger");
|
||||
else if (year == 7)
|
||||
System.out.println("rabbit");
|
||||
else if (year == 8)
|
||||
System.out.println("dragon");
|
||||
else if (year == 9)
|
||||
System.out.println("snake");
|
||||
else if (year == 10)
|
||||
System.out.println("horse");
|
||||
else if (year == 11)
|
||||
System.out.println("sheep");
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch2 {
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int x = 1, a = 3;
|
||||
switch (a) {
|
||||
case 1: x += 5;
|
||||
case 2: x += 10;
|
||||
case 3: x += 16;
|
||||
case 4: x+= 34;
|
||||
}
|
||||
System.out.println(x + ", " + a);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int dayOfWeekInt;
|
||||
String dayOfWeekString = "nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a number that signifies a day of the week: ");
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfWeekInt) {
|
||||
case 1:
|
||||
dayOfWeekString = "Sunday";
|
||||
ordinal = "1st";
|
||||
break;
|
||||
case 2:
|
||||
dayOfWeekString = "Monday";
|
||||
ordinal = "2nd";
|
||||
break;
|
||||
case 3:
|
||||
dayOfWeekString = "Tuesday";
|
||||
ordinal = "3rd";
|
||||
break;
|
||||
case 4:
|
||||
dayOfWeekString = "Wednesday";
|
||||
ordinal = "4th";
|
||||
break;
|
||||
case 5:
|
||||
dayOfWeekString = "Thursday";
|
||||
ordinal = "5th";
|
||||
break;
|
||||
case 6:
|
||||
dayOfWeekString = "Friday";
|
||||
ordinal = "6th";
|
||||
break;
|
||||
case 7:
|
||||
dayOfWeekString = "Saturday";
|
||||
ordinal = "7th";
|
||||
break;
|
||||
}
|
||||
// Print output
|
||||
if (dayOfWeekInt > 7)
|
||||
System.out.println("That number is too high.");
|
||||
else
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch3ConvertedToIfElse {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
int dayOfWeekInt;
|
||||
String dayOfWeekString = "nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a number that signifies a day of the week: ");
|
||||
dayOfWeekInt = input.nextInt();
|
||||
|
||||
// No longer Switch moment
|
||||
if (dayOfWeekInt == 1) {
|
||||
dayOfWeekString = "Sunday";
|
||||
ordinal = "1st";
|
||||
} else if (dayOfWeekInt == 2) {
|
||||
dayOfWeekString = "Monday";
|
||||
ordinal = "2nd";
|
||||
} else if (dayOfWeekInt == 3) {
|
||||
dayOfWeekString = "Tuesday";
|
||||
ordinal = "3rd";
|
||||
} else if (dayOfWeekInt == 4) {
|
||||
dayOfWeekString = "Wednesday";
|
||||
ordinal = "4th";
|
||||
} else if (dayOfWeekInt == 5) {
|
||||
dayOfWeekString = "Thursday";
|
||||
ordinal = "5th";
|
||||
} else if (dayOfWeekInt == 6) {
|
||||
dayOfWeekString = "Friday";
|
||||
ordinal = "6th";
|
||||
} else if (dayOfWeekInt == 7) {
|
||||
dayOfWeekString = "Saturday";
|
||||
ordinal = "7th";
|
||||
}
|
||||
|
||||
// Print output
|
||||
if (dayOfWeekInt > 7) {
|
||||
System.out.println("That number is too high.");
|
||||
} else {
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab8_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Switch4 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Define vars
|
||||
String dayOfWeekString = "Nullday",
|
||||
ordinal = "0th";
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a day of the week (Case-Sensitive): ");
|
||||
dayOfWeekString = input.next();
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfWeekString) {
|
||||
case "Sunday":
|
||||
ordinal = "1st";
|
||||
break;
|
||||
case "Monday":
|
||||
ordinal = "2nd";
|
||||
break;
|
||||
case "Tuesday":
|
||||
ordinal = "3rd";
|
||||
break;
|
||||
case "Wednesday":
|
||||
ordinal = "4th";
|
||||
break;
|
||||
case "Thursday":
|
||||
ordinal = "5th";
|
||||
break;
|
||||
case "Friday":
|
||||
ordinal = "6th";
|
||||
break;
|
||||
case "Saturday":
|
||||
ordinal = "7th";
|
||||
break;
|
||||
}
|
||||
// Print output
|
||||
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user