new semester, new repo structure

This commit is contained in:
2023-01-10 11:59:05 -06:00
parent 0a76658f85
commit ba6de6e18e
725 changed files with 1199 additions and 103 deletions

View File

@@ -0,0 +1,91 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArraysAndMethodsGames.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST1 {color: #969696; font-family: monospace; font-weight: bold}
.ST2 {font-family: monospace; font-weight: bold}
.comment {color: #969696}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
.ST5 {font-family: monospace; font-style: italic}
.ST6 {color: #ce54b8; font-family: monospace; font-style: italic}
.ST0 {color: #287bde}
.ST4 {color: #ce54b8}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.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.lab16_arrays2_calebfontenot;
<span class="literal">import</span> java.util.Scanner;
<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> <span class="ST2">ArraysAndMethodsGames</span> {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST3">min</span>(<span class="literal">double</span>[] array) {
<span class="comment">// pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.</span>
<span class="literal">double</span> lowest = array[0];
<span class="literal">for</span> (<span class="literal">int</span> i = 1; i &lt; (array.<span class="ST4">length</span> -1); i++) {
lowest = Math.<span class="ST5">min</span>(lowest, array[i]);
}
<span class="literal">return</span> lowest;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span>[] <span class="ST3">readArray</span>() {
<span class="comment">// Create a double array.</span>
<span class="literal">int</span> doublesRemaining = 10;
<span class="literal">double</span>[] returnArray = <span class="literal">new</span> <span class="literal">double</span>[doublesRemaining];
<span class="comment">// Create Scanner</span>
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST6">in</span>);
<span class="comment">// Read characters input and write them to an array.</span>
<span class="literal">int</span> i = 0;
<span class="literal">do</span> {
System.<span class="ST6">out</span>.print(<span class="string">&quot;</span><span class="string">Enter 10 doubles (</span><span class="string">&quot;</span> + doublesRemaining + <span class="string">&quot;</span><span class="string"> left ): </span><span class="string">&quot;</span>);
returnArray[i] = input.nextDouble();
i++;
doublesRemaining--;
} <span class="literal">while</span> (doublesRemaining != 0);
<span class="literal">return</span> returnArray;
}
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@param</span> array
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">Returns</span> <span class="comment">an</span> <span class="comment">average</span> <span class="comment">of</span> <span class="comment">an</span> <span class="comment">array</span><span class="comment">.</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST3">average</span>(<span class="literal">double</span>[] array) {
<span class="comment">// Iterate through array and add values together into double, then divide by the amount of items in the array.</span>
<span class="literal">double</span> returnDouble = 0.0;
<span class="literal">for</span> (<span class="literal">double</span> i: array) {
returnDouble += i;
}
returnDouble /= (<span class="literal">double</span>) array.<span class="ST4">length</span>;
<span class="literal">return</span> returnDouble;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
{
<span class="literal">double</span>[] doubleArray = <span class="literal">new</span> <span class="literal">double</span>[10];
doubleArray = <span class="ST5">readArray</span>();
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">average function returns: </span><span class="string">&quot;</span> + <span class="ST5">average</span>(doubleArray));
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">lowest function returns: </span><span class="string">&quot;</span> + <span class="ST5">min</span>(doubleArray));
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,56 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArrayCopy2.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
.comment {color: #969696}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy2.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ArrayCopy2 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="literal">int</span>[] sourceArray = {1, 2, 3, 4, 5};
<span class="literal">int</span>[] targetArray = <span class="literal">new</span> <span class="literal">int</span>[sourceArray.length];
<span class="comment">// Print the source array</span>
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; sourceArray.length; i++) {
System.out.print(sourceArray[i] + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="comment">// Copy the source array to the target array in reversed order</span>
<span class="literal">int</span> j = (sourceArray.length - 1);
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; sourceArray.length; i++) {
targetArray[i] = sourceArray[j];
j--;
}
<span class="comment">// Print the target array</span>
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; sourceArray.length; i++) {
System.out.print(targetArray[i] + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,52 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArrayCopy3.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
.comment {color: #969696}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy3.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ArrayCopy3 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="literal">int</span>[] sourceArray = {1, 2, 3, 4, 5};
<span class="literal">int</span>[] targetArray = <span class="literal">new</span> <span class="literal">int</span>[sourceArray.length];
<span class="comment">// Print the source array</span>
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; sourceArray.length; i++) {
System.out.print(sourceArray[i] + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="comment">// Copy the source array to the target array</span>
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
<span class="comment">// Print the target array</span>
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; sourceArray.length; i++) {
System.out.print(targetArray[i] + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArrayCopy4.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
.comment {color: #969696}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy4.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
<span class="literal">import</span> java.util.Arrays;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ArrayCopy4 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="literal">int</span>[] array = {1, 2, 3, 4, 5};
<span class="literal">int</span>[] array1 = Arrays.copyOfRange(array, 2, 5);
<span class="literal">int</span>[] array2 = <span class="literal">new</span> <span class="literal">int</span>[array.length - 2];
<span class="literal">int</span>[] array3 = <span class="literal">new</span> <span class="literal">int</span>[array.length];
System.out.println(<span class="string">&quot;</span><span class="string">array1: (copy with java.util.Arrays.copyOfRange(); )</span><span class="string">&quot;</span>);
<span class="literal">for</span> (<span class="literal">int</span> i: array1) {
System.out.print(i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="comment">// Copy array into array2 with a for loop and print it</span>
System.out.println(<span class="string">&quot;</span><span class="string">array2: (copy with System.arraycopy(); )</span><span class="string">&quot;</span>);
System.arraycopy(array, 2, array2, 0, 3);
<span class="literal">for</span> (<span class="literal">int</span> i : array2) {
System.out.print(i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="comment">// Copy array manually</span>
System.out.println(<span class="string">&quot;</span><span class="string">array3: (manually copy with for loop)</span><span class="string">&quot;</span>);
<span class="literal">for</span> (<span class="literal">int</span> i : array3) {
array[i] = array3[i];
}
<span class="literal">for</span> (<span class="literal">int</span> i : array1) {
System.out.print(i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,54 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArrayShift1.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
.comment {color: #969696}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift1.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ArrayShift1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="literal">int</span>[] ar = {1, 2, 3, 4, 5};
<span class="literal">int</span> temp = ar[0];
<span class="literal">for</span> (<span class="literal">int</span> value : ar) {
System.out.print(value + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="literal">for</span> (<span class="literal">int</span> i = 1; i &lt; ar.length; ++i) {
ar[i - 1] = ar[i];
}
ar[ar.length - 1] = temp;
<span class="literal">for</span> (<span class="literal">int</span> value : ar) {
System.out.print(value + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,55 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArrayShift2.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
.comment {color: #969696}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift2.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> ArrayShift2 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
<span class="literal">int</span>[] ar = {1, 2, 3, 4, 5};
<span class="literal">int</span> temp = ar[ar.length - 1];
<span class="literal">for</span> (<span class="literal">int</span> value : ar) {
System.out.print(value + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.out.println();
<span class="literal">for</span> (<span class="literal">int</span> i = (ar.length -1); i &gt; 0 ; --i) {
ar[i] = ar[i -1];
}
ar[0] = temp;
<span class="literal">for</span> (<span class="literal">int</span> value : ar) {
System.out.print(value + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,110 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArraysAndMethods.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST1 {color: #969696; font-family: monospace; font-weight: bold}
.ST2 {font-family: monospace; font-weight: bold}
.comment {color: #969696}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
.ST6 {font-family: monospace; font-style: italic}
.ST4 {color: #ce54b8; font-family: monospace; font-style: italic}
.ST0 {color: #287bde}
.ST5 {color: #ce54b8}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethods.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.lab16_arrays2_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> <span class="ST2">ArraysAndMethods</span> {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">printArray</span>(<span class="literal">int</span>[] arrayInput)
{
<span class="literal">for</span> (<span class="literal">int</span> i : arrayInput) {
System.<span class="ST4">out</span>.print(i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.<span class="ST4">out</span>.println();
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">printArray</span>(<span class="literal">char</span>[] arrayInput)
{
<span class="literal">for</span> (<span class="literal">int</span> i : arrayInput) {
System.<span class="ST4">out</span>.print((<span class="literal">char</span>) i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.<span class="ST4">out</span>.println();
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">printArray</span>(<span class="literal">double</span>[] arrayInput)
{
<span class="literal">for</span> (<span class="literal">double</span> i : arrayInput) {
System.<span class="ST4">out</span>.print(i + <span class="string">&quot;</span> <span class="string">&quot;</span>);
}
System.<span class="ST4">out</span>.println();
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span>[] <span class="ST3">reverse</span>(<span class="literal">int</span>[] arrayToReverse)
{
<span class="literal">int</span> arrayResult[] = <span class="literal">new</span> <span class="literal">int</span>[arrayToReverse.<span class="ST5">length</span>];
<span class="literal">int</span> j = (arrayToReverse.<span class="ST5">length</span> - 1);
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt;= arrayToReverse.<span class="ST5">length</span> - 1; i++) {
arrayResult[i] = arrayToReverse[j];
j--;
}
<span class="literal">return</span> arrayResult;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST3">linearSearch</span>(<span class="literal">int</span> list[], <span class="literal">int</span> key)
{
<span class="literal">int</span> indexFound = -1;
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i &lt; list.<span class="ST5">length</span>; ++i) {
<span class="literal">if</span> (list[i] == key) {
indexFound = i;
}
}
<span class="literal">return</span> indexFound;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
{
<span class="literal">int</span>[] array = {1, 2, 3, 4, 5};
<span class="ST6">printArray</span>(array);
<span class="ST6">printArray</span>(<span class="literal">new</span> <span class="literal">int</span>[]{3, 1, 2, 6, 4});
<span class="ST6">printArray</span>(<span class="ST6">r</span><span class="ST6">everse</span>(array));
System.<span class="ST4">out</span>.println(<span class="ST6">linearSearch</span>(array, 5) != 1
? <span class="string">&quot;</span><span class="string">found at index </span><span class="string">&quot;</span> + Integer.<span class="ST6">toString</span>(<span class="ST6">l</span><span class="ST6">inearSearch</span>(array, 5))
: <span class="string">&quot;</span><span class="string">not found at index </span><span class="string">&quot;</span> + Integer.<span class="ST6">toString</span>(<span class="ST6">l</span><span class="ST6">inearSearch</span>(array, 5))
);
<span class="literal">double</span>[] doubles = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
<span class="comment">// Use the built-in sort method to sort the double.</span>
java.util.Arrays.<span class="ST6">sort</span>(doubles);
<span class="literal">char</span>[] chars = {<span class="string">&#39;</span><span class="string">a</span><span class="string">&#39;</span>, <span class="string">&#39;</span><span class="string">A</span><span class="string">&#39;</span>, <span class="string">&#39;</span><span class="string">4</span><span class="string">&#39;</span>, <span class="string">&#39;</span><span class="string">F</span><span class="string">&#39;</span>, <span class="string">&#39;</span><span class="string">D</span><span class="string">&#39;</span>, <span class="string">&#39;</span><span class="string">P</span><span class="string">&#39;</span>,};
<span class="comment">//Sort again</span>
java.util.Arrays.<span class="ST6">sort</span>(chars);
<span class="comment">// Now print the sorted arrays.</span>
<span class="ST6">printArray</span>(doubles);
<span class="ST6">printArray</span>(chars);
}
}
</pre></body>
</html>

View File

@@ -0,0 +1,91 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ArraysAndMethodsGames.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST1 {color: #969696; font-family: monospace; font-weight: bold}
.ST2 {font-family: monospace; font-weight: bold}
.comment {color: #969696}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
.ST5 {font-family: monospace; font-style: italic}
.ST6 {color: #ce54b8; font-family: monospace; font-style: italic}
.ST0 {color: #287bde}
.ST4 {color: #ce54b8}
.string {color: #1e9347}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArraysAndMethodsGames.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.lab16_arrays2_calebfontenot;
<span class="literal">import</span> java.util.Scanner;
<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> <span class="ST2">ArraysAndMethodsGames</span> {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST3">min</span>(<span class="literal">double</span>[] array) {
<span class="comment">// pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.</span>
<span class="literal">double</span> lowest = array[0];
<span class="literal">for</span> (<span class="literal">int</span> i = 1; i &lt; (array.<span class="ST4">length</span> -1); i++) {
lowest = Math.<span class="ST5">min</span>(lowest, array[i]);
}
<span class="literal">return</span> lowest;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span>[] <span class="ST3">readArray</span>() {
<span class="comment">// Create a double array.</span>
<span class="literal">int</span> doublesRemaining = 10;
<span class="literal">double</span>[] returnArray = <span class="literal">new</span> <span class="literal">double</span>[doublesRemaining];
<span class="comment">// Create Scanner</span>
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST6">in</span>);
<span class="comment">// Read characters input and write them to an array.</span>
<span class="literal">int</span> i = 0;
<span class="literal">do</span> {
System.<span class="ST6">out</span>.print(<span class="string">&quot;</span><span class="string">Enter 10 doubles (</span><span class="string">&quot;</span> + doublesRemaining + <span class="string">&quot;</span><span class="string"> left ): </span><span class="string">&quot;</span>);
returnArray[i] = input.nextDouble();
i++;
doublesRemaining--;
} <span class="literal">while</span> (doublesRemaining != 0);
<span class="literal">return</span> returnArray;
}
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST1">@param</span> array
<span class="comment"> * </span><span class="ST1">@return</span> <span class="comment">Returns</span> <span class="comment">an</span> <span class="comment">average</span> <span class="comment">of</span> <span class="comment">an</span> <span class="comment">array</span><span class="comment">.</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">double</span> <span class="ST3">average</span>(<span class="literal">double</span>[] array) {
<span class="comment">// Iterate through array and add values together into double, then divide by the amount of items in the array.</span>
<span class="literal">double</span> returnDouble = 0.0;
<span class="literal">for</span> (<span class="literal">double</span> i: array) {
returnDouble += i;
}
returnDouble /= (<span class="literal">double</span>) array.<span class="ST4">length</span>;
<span class="literal">return</span> returnDouble;
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
{
<span class="literal">double</span>[] doubleArray = <span class="literal">new</span> <span class="literal">double</span>[10];
doubleArray = <span class="ST5">readArray</span>();
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">average function returns: </span><span class="string">&quot;</span> + <span class="ST5">average</span>(doubleArray));
System.<span class="ST6">out</span>.println(<span class="string">&quot;</span><span class="string">lowest function returns: </span><span class="string">&quot;</span> + <span class="ST5">min</span>(doubleArray));
}
}
</pre></body>
</html>

View 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>lab16_arrays2_CalebFontenot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<exec.mainClass>com.calebfontenot.lab16_arrays2_calebfontenot.Lab16_arrays2_CalebFontenot</exec.mainClass>
</properties>
</project>

View File

@@ -0,0 +1,31 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArrayCopy1 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array
for (int i = 0; i < sourceArray.length; i++) {
targetArray[i] = sourceArray[i];
}
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArrayCopy2 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array in reversed order
int j = (sourceArray.length - 1);
for (int i = 0; i < sourceArray.length; i++) {
targetArray[i] = sourceArray[j];
j--;
}
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArrayCopy3 {
public static void main(String[] args)
{
int[] sourceArray = {1, 2, 3, 4, 5};
int[] targetArray = new int[sourceArray.length];
// Print the source array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(sourceArray[i] + " ");
}
System.out.println();
// Copy the source array to the target array
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
// Print the target array
for (int i = 0; i < sourceArray.length; i++) {
System.out.print(targetArray[i] + " ");
}
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.lab16_arrays2_calebfontenot;
import java.util.Arrays;
/**
*
* @author caleb
*/
public class ArrayCopy4 {
public static void main(String[] args)
{
int[] array = {1, 2, 3, 4, 5};
int[] array1 = Arrays.copyOfRange(array, 2, 5);
int[] array2 = new int[array.length - 2];
int[] array3 = new int[array.length];
System.out.println("array1: (copy with java.util.Arrays.copyOfRange(); )");
for (int i: array1) {
System.out.print(i + " ");
}
System.out.println();
// Copy array into array2 with a for loop and print it
System.out.println("array2: (copy with System.arraycopy(); )");
System.arraycopy(array, 2, array2, 0, 3);
for (int i : array2) {
System.out.print(i + " ");
}
System.out.println();
// Copy array manually
System.out.println("array3: (manually copy with for loop)");
for (int i : array3) {
array[i] = array3[i];
}
for (int i : array1) {
System.out.print(i + " ");
}
System.out.println();
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArrayShift1 {
public static void main(String[] args)
{
int[] ar = {1, 2, 3, 4, 5};
int temp = ar[0];
for (int value : ar) {
System.out.print(value + " ");
}
System.out.println();
for (int i = 1; i < ar.length; ++i) {
ar[i - 1] = ar[i];
}
ar[ar.length - 1] = temp;
for (int value : ar) {
System.out.print(value + " ");
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArrayShift2 {
public static void main(String[] args)
{
int[] ar = {1, 2, 3, 4, 5};
int temp = ar[ar.length - 1];
for (int value : ar) {
System.out.print(value + " ");
}
System.out.println();
for (int i = (ar.length -1); i > 0 ; --i) {
ar[i] = ar[i -1];
}
ar[0] = temp;
for (int value : ar) {
System.out.print(value + " ");
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class ArraysAndMethods {
public static void printArray(int[] arrayInput)
{
for (int i : arrayInput) {
System.out.print(i + " ");
}
System.out.println();
}
public static void printArray(char[] arrayInput)
{
for (int i : arrayInput) {
System.out.print((char) i + " ");
}
System.out.println();
}
public static void printArray(double[] arrayInput)
{
for (double i : arrayInput) {
System.out.print(i + " ");
}
System.out.println();
}
public static int[] reverse(int[] arrayToReverse)
{
int arrayResult[] = new int[arrayToReverse.length];
int j = (arrayToReverse.length - 1);
for (int i = 0; i <= arrayToReverse.length - 1; i++) {
arrayResult[i] = arrayToReverse[j];
j--;
}
return arrayResult;
}
public static int linearSearch(int list[], int key)
{
int indexFound = -1;
for (int i = 0; i < list.length; ++i) {
if (list[i] == key) {
indexFound = i;
}
}
return indexFound;
}
public static void main(String[] args)
{
int[] array = {1, 2, 3, 4, 5};
printArray(array);
printArray(new int[]{3, 1, 2, 6, 4});
printArray(reverse(array));
System.out.println(linearSearch(array, 5) != 1
? "found at index " + Integer.toString(linearSearch(array, 5))
: "not found at index " + Integer.toString(linearSearch(array, 5))
);
double[] doubles = {6.0, 4.4, 1.9, 2.9, 3.4, 3.5};
// Use the built-in sort method to sort the double.
java.util.Arrays.sort(doubles);
char[] chars = {'a', 'A', '4', 'F', 'D', 'P',};
//Sort again
java.util.Arrays.sort(chars);
// Now print the sorted arrays.
printArray(doubles);
printArray(chars);
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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.lab16_arrays2_calebfontenot;
import java.util.Scanner;
/**
*
* @author caleb
*/
public class ArraysAndMethodsGames {
public static double min(double[] array) {
// pull the first number from the array, and compare that with the numbers in the rest of the array. If that number is less than the number in than the first number, set it to our lowest.
double lowest = array[0];
for (int i = 1; i < (array.length -1); i++) {
lowest = Math.min(lowest, array[i]);
}
return lowest;
}
public static double[] readArray() {
// Create a double array.
int doublesRemaining = 10;
double[] returnArray = new double[doublesRemaining];
// Create Scanner
Scanner input = new Scanner(System.in);
// Read characters input and write them to an array.
int i = 0;
do {
System.out.print("Enter 10 doubles (" + doublesRemaining + " left ): ");
returnArray[i] = input.nextDouble();
i++;
doublesRemaining--;
} while (doublesRemaining != 0);
return returnArray;
}
/**
*
* @param array
* @return Returns an average of an array.
*/
public static double average(double[] array) {
// Iterate through array and add values together into double, then divide by the amount of items in the array.
double returnDouble = 0.0;
for (double i: array) {
returnDouble += i;
}
returnDouble /= (double) array.length;
return returnDouble;
}
public static void main(String[] args)
{
double[] doubleArray = new double[10];
doubleArray = readArray();
System.out.println("average function returns: " + average(doubleArray));
System.out.println("lowest function returns: " + min(doubleArray));
}
}

View File

@@ -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.lab16_arrays2_calebfontenot;
/**
*
* @author caleb
*/
public class Lab16_arrays2_CalebFontenot {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}