stuff
This commit is contained in:
parent
1ff9001824
commit
c06148228b
@ -0,0 +1,81 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Circle.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST4 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST3 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/Circle.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.mp5_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> Circle <span class="literal">extends</span> GeometricObject {
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST1">diameter</span>;
|
||||
|
||||
<span class="literal">public</span> Circle(<span class="literal">double</span> diameter) {
|
||||
<span class="literal">this</span>.<span class="ST1">diameter</span> = diameter;
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Circle Diameter: </span><span class="string">"</span> + diameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getArea</span>() {
|
||||
<span class="literal">double</span> radius = <span class="ST1">diameter</span> / <span class="number">2</span>;
|
||||
<span class="literal">return</span> Math.<span class="ST2">PI</span> * Math.<span class="ST4">pow</span>(radius, <span class="number">2</span>);
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST3">getPerimeter</span>() {
|
||||
<span class="literal">return</span> Math.<span class="ST2">PI</span> * <span class="ST1">diameter</span>;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> String <span class="ST3">toString</span>() {
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">Circle{</span><span class="string">"</span> + <span class="string">"</span><span class="string">diameter=</span><span class="string">"</span> + <span class="ST1">diameter</span> + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compareTo</span>(Object t) {
|
||||
System.<span class="ST2">out</span>.println(<span class="literal">this</span>.getArea() + <span class="string">"</span><span class="string">, </span><span class="string">"</span> + ((Circle) t).getArea());
|
||||
<span class="literal">if</span> (<span class="literal">this</span>.getArea() < ((Circle) t).getArea()) {
|
||||
<span class="literal">return</span> -<span class="number">1</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (<span class="literal">this</span>.getArea() > ((Circle) t).getArea()) {
|
||||
<span class="literal">return</span> <span class="number">1</span>;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> <span class="number">0</span>;
|
||||
}
|
||||
}
|
||||
<span class="comment">// The compiler made me implement this, not sure why</span>
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST3">compareTo</span>() {
|
||||
<span class="literal">throw</span> <span class="literal">new</span> UnsupportedOperationException(<span class="string">"</span><span class="string">No compare object supplied!</span><span class="string">"</span>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,177 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Combinations.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST2 {color: #9876aa}
|
||||
.ST6 {color: #ffc66d}
|
||||
.ST5 {color: #8a653b}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST7 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST4 {color: #808080; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/Combinations.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.mp5_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">import</span> java.util.ArrayList;
|
||||
<span class="literal">import</span> java.util.Collections;
|
||||
<span class="literal">import</span> java.util.Comparator;
|
||||
<span class="literal">import</span> java.util.HashSet;
|
||||
<span class="literal">import</span> java.util.Iterator;
|
||||
<span class="literal">import</span> java.util.List;
|
||||
<span class="literal">import</span> java.util.Set;
|
||||
|
||||
<span class="literal">class</span> Combinations
|
||||
{
|
||||
|
||||
<span class="literal">private</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">findCombinations</span>(String[] A, <span class="literal">int</span> i, <span class="literal">int</span> k,
|
||||
Set<List<String>> subarrays,
|
||||
List<String> out)
|
||||
{
|
||||
<span class="literal">if</span> (A.<span class="ST2">length</span> == <span class="number">0</span> || k > A.<span class="ST2">length</span>)
|
||||
{
|
||||
<span class="literal">return</span>;
|
||||
}
|
||||
|
||||
<span class="comment">// base case: combination size is `k`</span>
|
||||
<span class="literal">if</span> (k == <span class="number">0</span>)
|
||||
{
|
||||
subarrays.add(<span class="literal">new</span> ArrayList<>(out));
|
||||
<span class="literal">return</span>;
|
||||
}
|
||||
|
||||
<span class="comment">// start from the next index till the last index</span>
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = i; j < A.<span class="ST2">length</span>; j++)
|
||||
{
|
||||
<span class="comment">// add current element `A[j]` to the solution and recur for next index</span>
|
||||
<span class="comment">// `j+1` with one less element `k-1`</span>
|
||||
out.add(A[j]);
|
||||
<span class="ST3">findCombinations</span>(A, j + <span class="number">1</span>, k - <span class="number">1</span>, subarrays, out);
|
||||
out.remove(out.size() - <span class="number">1</span>); <span class="comment">// backtrack</span>
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">private</span> <span class="literal">static</span> Set<List<String>> <span class="ST4">findCombinations</span>(String[] A, <span class="literal">int</span> k)
|
||||
{
|
||||
Set<List<String>> subarrays = <span class="literal">new</span> HashSet<>();
|
||||
<span class="ST3">findCombinations</span>(A, <span class="number">0</span>, k, subarrays, <span class="literal">new</span> ArrayList<>());
|
||||
<span class="literal">return</span> subarrays;
|
||||
}
|
||||
|
||||
<span class="literal">private</span> <span class="literal">static</span> Set<List<String>> <span class="ST1">findAllCombinations</span>(String[] A)
|
||||
{
|
||||
Set<List<String>> subarrays = <span class="literal">new</span> HashSet<>();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> k = <span class="number">1</span>; k <= A.<span class="ST2">length</span>; ++k)
|
||||
{
|
||||
<span class="ST3">findCombinations</span>(A, <span class="number">0</span>, k, subarrays, <span class="literal">new</span> ArrayList<>());
|
||||
}
|
||||
<span class="literal">return</span> subarrays;
|
||||
}
|
||||
<span class="comment">/**</span> <span class="comment">Finds</span> <span class="comment">all</span> <span class="comment">distinct</span> <span class="comment">combinations</span> <span class="comment">of</span> <span class="comment">all</span> <span class="comment">sizes</span> <span class="comment">for</span> <span class="comment">elements</span> <span class="comment">of</span> <span class="comment">array</span><span class="comment">.</span>
|
||||
<span class="comment"> * </span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST5">A</span> <span class="comment">the</span> <span class="comment">elements</span> <span class="comment">to</span> <span class="comment">find</span> <span class="comment">their</span> <span class="comment">combinations</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">all</span> <span class="comment">distinct</span> <span class="comment">combinations</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">elements</span><span class="comment">, </span><span class="comment">sorted</span> <span class="comment">by</span> <span class="comment">length</span><span class="comment">.</span> <span class="comment">ascending</span> <span class="comment">order</span><span class="comment">.</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> ArrayList<String> <span class="ST1">allCombinations</span>(String[] A)
|
||||
{
|
||||
Set<List<String>> set = <span class="ST3">findAllCombinations</span>(A);
|
||||
ArrayList<String> all = <span class="literal">new</span> ArrayList<String>();
|
||||
Iterator it = set.iterator();
|
||||
<span class="literal">while</span> (it.hasNext())
|
||||
{
|
||||
List<String> list = (List<String>) it.next();
|
||||
String s1 = <span class="string">""</span>;
|
||||
<span class="literal">for</span> (String s2 : list)
|
||||
{
|
||||
s1 += s2;
|
||||
}
|
||||
all.add(s1);
|
||||
}
|
||||
Collections.<span class="ST3">sort</span>(all, <span class="literal">new</span> Comparator<String>(){
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST6">compare</span>(String o1, String o2)
|
||||
{
|
||||
<span class="literal">return</span> o1.length() - o2.length();
|
||||
}
|
||||
});
|
||||
<span class="literal">return</span> all;
|
||||
}
|
||||
<span class="comment">/**</span> <span class="comment">Finds</span> <span class="comment">all</span> <span class="comment">distinct</span> <span class="comment">combinations</span> <span class="comment">of</span> <span class="comment">all</span> <span class="comment">sizes</span> <span class="comment">for</span> <span class="comment">chars</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">String</span><span class="comment">.</span>
|
||||
<span class="comment"> * </span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST5">A</span> <span class="comment">the</span> <span class="comment">characters</span> <span class="comment">to</span> <span class="comment">find</span> <span class="comment">their</span> <span class="comment">combinations</span><span class="comment">.</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">all</span> <span class="comment">distinct</span> <span class="comment">combinations</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">characters</span> <span class="comment">sorted</span> <span class="comment">by</span> <span class="comment">length</span><span class="comment">, </span><span class="comment">ascending</span> <span class="comment">order</span><span class="comment">.</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> ArrayList<String> <span class="ST1">allCombinations</span>(String a)
|
||||
{
|
||||
String[] A = <span class="literal">new</span> String[a.length()];
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < A.<span class="ST2">length</span>; ++i)
|
||||
{
|
||||
A[i] = Character.<span class="ST3">toString</span>(a.charAt(i));
|
||||
}
|
||||
Set<List<String>> set = <span class="ST3">findAllCombinations</span>(A);
|
||||
ArrayList<String> all = <span class="literal">new</span> ArrayList<String>();
|
||||
Iterator it = set.iterator();
|
||||
<span class="literal">while</span> (it.hasNext())
|
||||
{
|
||||
List<String> list = (List<String>) it.next();
|
||||
String s1 = <span class="string">""</span>;
|
||||
<span class="literal">for</span> (String s2 : list)
|
||||
{
|
||||
s1 += s2;
|
||||
}
|
||||
all.add(s1);
|
||||
}
|
||||
|
||||
Collections.<span class="ST3">sort</span>(all, <span class="literal">new</span> Comparator<String>(){
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST6">compare</span>(String o1, String o2)
|
||||
{
|
||||
<span class="literal">return</span> o1.length() - o2.length();
|
||||
}
|
||||
});
|
||||
<span class="literal">return</span> all;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args)
|
||||
{
|
||||
String[] A =
|
||||
{
|
||||
<span class="string">"</span><span class="string">1</span><span class="string">"</span>, <span class="string">"</span><span class="string">2</span><span class="string">"</span>, <span class="string">"</span><span class="string">3</span><span class="string">"</span>, <span class="string">"</span><span class="string">4</span><span class="string">"</span>
|
||||
};
|
||||
<span class="literal">int</span> <span class="comment">k</span> = <span class="number">2</span>;
|
||||
|
||||
<span class="comment">// process elements from left to right</span>
|
||||
System.<span class="ST7">out</span>.println(<span class="ST3">a</span><span class="ST3">llCombinations</span>(A));
|
||||
System.<span class="ST7">out</span>.println(<span class="ST3">a</span><span class="ST3">llCombinations</span>(<span class="string">"</span><span class="string">1234</span><span class="string">"</span>));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</pre></body>
|
||||
</html>
|
124
Semester 2/Assignments/MP5_CalebFontenot/Printed HTMLs/FD.html
Normal file
124
Semester 2/Assignments/MP5_CalebFontenot/Printed HTMLs/FD.html
Normal file
@ -0,0 +1,124 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>FD.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.string {color: #6a8759}
|
||||
.number {color: #6897bb}
|
||||
.ST0 {color: #9876aa}
|
||||
.ST2 {color: #ffc66d}
|
||||
.ST1 {color: #8a653b}
|
||||
.whitespace {color: #505050}
|
||||
.comment {color: #808080}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/FD.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="literal">package</span> com.calebfontenot.mp5_calebfontenot;
|
||||
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">ASDV2</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> FD
|
||||
{
|
||||
|
||||
<span class="literal">private</span> String <span class="ST0">lhs</span>;
|
||||
|
||||
<span class="literal">private</span> String <span class="ST0">rhs</span>;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">lhs</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">rhs</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span>
|
||||
<span class="comment"> * </span><span class="comment">@throws</span> <span class="comment">IllegalArgumentException</span> <span class="comment">if</span> <span class="comment">the</span> <span class="comment">length</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">or</span> <span class="comment">the</span> <span class="comment">length</span>
|
||||
<span class="comment"> * </span><span class="comment">of</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">are</span> <span class="comment">less</span> <span class="comment">than</span><span class="comment"> 1 </span><span class="comment">or</span> <span class="comment">if</span> <span class="comment">they</span> <span class="comment">are</span> <span class="comment">null</span><span class="comment">.</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> FD(String lhs, String rhs)
|
||||
<span class="literal">throws</span> IllegalArgumentException
|
||||
{
|
||||
<span class="literal">if</span> (lhs == <span class="literal">null</span> || rhs == <span class="literal">null</span> )
|
||||
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException( <span class="string">"</span><span class="string">the LHS and/or RHS cannot be null.</span><span class="string">"</span>);
|
||||
|
||||
<span class="literal">if</span> (lhs.length() < <span class="number">1</span> || rhs.length() < <span class="number">1</span> )
|
||||
<span class="literal">throw</span> <span class="literal">new</span> IllegalArgumentException( <span class="string">"</span><span class="string">the LHS and/or RHS cannot be of lenght less than 1.</span><span class="string">"</span>);
|
||||
|
||||
<span class="literal">this</span>.<span class="ST0">lhs</span> = lhs;
|
||||
<span class="literal">this</span>.<span class="ST0">rhs</span> = rhs;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> String <span class="ST2">getRhs</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST0">rhs</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">rhs</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">rhs</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setRhs</span>(String rhs)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST0">rhs</span> = rhs;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> String <span class="ST2">getLhs</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST0">lhs</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">the</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">lhs</span> <span class="comment">new</span> <span class="comment">value</span> <span class="comment">of</span> <span class="comment">lhs</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setLhs</span>(String lhs)
|
||||
{
|
||||
<span class="literal">this</span>.<span class="ST0">lhs</span> = lhs;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> String <span class="ST2">toString</span>()
|
||||
{
|
||||
<span class="literal">return</span> <span class="ST0">lhs</span> + <span class="string">"</span><span class="string"> -> </span><span class="string">"</span> + <span class="ST0">rhs</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Decomposes</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span> <span class="comment">into</span> <span class="comment">singletons</span><span class="comment">.</span> <span class="comment">where</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">is</span> <span class="comment">the</span> <span class="comment">same</span>
|
||||
<span class="comment"> * </span><span class="comment">as</span> <span class="comment">this</span> <span class="comment">FD</span> <span class="comment">and</span> <span class="comment">the</span> <span class="comment">RHS</span> <span class="comment">is</span><span class="comment"> 1 </span><span class="comment">character</span> <span class="comment">of</span> <span class="comment">each</span> <span class="comment">character</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">FD</span><span class="comment">.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">array</span> <span class="comment">of</span> <span class="comment">FD</span> <span class="comment">he</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> FD[] <span class="ST2">decomposeRightHandSide</span>()
|
||||
{
|
||||
FD[] fdDecomosition = <span class="literal">new</span> FD[<span class="literal">this</span>.<span class="ST0">rhs</span>.length()];
|
||||
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < <span class="literal">this</span>.<span class="ST0">rhs</span>.length(); ++i)
|
||||
{
|
||||
fdDecomosition[i] = <span class="literal">new</span> FD(<span class="literal">t</span><span class="literal">his</span>.<span class="ST0">lhs</span>, Character.<span class="ST3">toString</span>(<span class="ST0">r</span><span class="ST0">hs</span>.charAt(i)));
|
||||
}
|
||||
<span class="literal">return</span> fdDecomosition;
|
||||
}
|
||||
}
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,122 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>GeometricObject.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST2 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST3 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/GeometricObject.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.mp5_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">abstract</span> <span class="literal">class</span> GeometricObject <span class="literal">implements</span> Comparable {
|
||||
|
||||
<span class="literal">private</span> String <span class="ST1">color</span> = <span class="string">"</span><span class="string">white</span><span class="string">"</span>;
|
||||
<span class="literal">private</span> <span class="literal">boolean</span> <span class="ST1">filled</span>;
|
||||
<span class="literal">private</span> java.util.Date <span class="ST1">dateCreated</span>;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Construct</span> <span class="comment">a</span> <span class="comment">default</span> <span class="comment">geometric</span> <span class="comment">object</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">protected</span> GeometricObject() {
|
||||
<span class="ST1">dateCreated</span> = <span class="literal">new</span> java.util.Date();
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Construct</span> <span class="comment">a</span> <span class="comment">geometric</span> <span class="comment">object</span> <span class="comment">with</span> <span class="comment">color</span> <span class="comment">and</span> <span class="comment">filled</span> <span class="comment">value</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">protected</span> GeometricObject(String color, <span class="literal">boolean</span> filled) {
|
||||
<span class="ST1">dateCreated</span> = <span class="literal">new</span> java.util.Date();
|
||||
<span class="literal">this</span>.<span class="ST1">color</span> = color;
|
||||
<span class="literal">this</span>.<span class="ST1">filled</span> = filled;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Return</span> <span class="comment">color</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> String <span class="ST2">getColor</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">color</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">color</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setColor</span>(String color) {
|
||||
<span class="literal">this</span>.<span class="ST1">color</span> = color;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Return</span> <span class="comment">filled</span><span class="comment">.</span> <span class="comment">Since</span> <span class="comment">filled</span> <span class="comment">is</span> <span class="comment">boolean</span><span class="comment">, </span><span class="comment">the</span> <span class="comment">get</span> <span class="comment">method</span> <span class="comment">is</span> <span class="comment">named</span> <span class="comment">isFilled</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">isFilled</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">filled</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Set</span> <span class="comment">a</span> <span class="comment">new</span> <span class="comment">filled</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setFilled</span>(<span class="literal">boolean</span> filled) {
|
||||
<span class="literal">this</span>.<span class="ST1">filled</span> = filled;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Get</span> <span class="comment">dateCreated</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> java.util.Date <span class="ST2">getDateCreated</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">dateCreated</span>;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> String <span class="ST2">toString</span>() {
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">created on </span><span class="string">"</span> + <span class="ST1">dateCreated</span> + <span class="string">"</span><span class="literal">\n</span><span class="string">color: </span><span class="string">"</span> + <span class="ST1">color</span>
|
||||
+ <span class="string">"</span><span class="string"> and filled: </span><span class="string">"</span> + <span class="ST1">filled</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Abstract</span> <span class="comment">method</span> <span class="comment">getArea</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">abstract</span> <span class="literal">double</span> <span class="ST2">getArea</span>();
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Abstract</span> <span class="comment">method</span> <span class="comment">getPerimeter</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">abstract</span> <span class="literal">double</span> <span class="ST2">getPerimeter</span>();
|
||||
|
||||
<span class="comment">// Additional code below</span>
|
||||
<span class="literal">public</span> <span class="literal">abstract</span> <span class="literal">int</span> <span class="ST2">compareTo</span>(GeometricObject t);
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> GeometricObject <span class="ST3">max</span>(GeometricObject o1, GeometricObject o2) {
|
||||
<span class="literal">if</span> (o1.getArea() >= o2.getArea()) {
|
||||
<span class="literal">return</span> o1;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> o2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,72 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Large.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.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}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/Large.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.mp5_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.io.File;
|
||||
<span class="comment">import</span> <span class="comment">java</span><span class="comment">.</span><span class="comment">io</span><span class="comment">.</span><span class="comment">FileNotFoundException</span><span class="comment">;</span>
|
||||
<span class="literal">import</span> java.util.ArrayList;
|
||||
<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> Large {
|
||||
<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">// Read data file</span>
|
||||
<span class="comment">// ArrayLists</span>
|
||||
ArrayList firstNameArr = <span class="literal">new</span> ArrayList();
|
||||
ArrayList lastNameArr = <span class="literal">new</span> ArrayList();
|
||||
ArrayList jobTitleArr = <span class="literal">new</span> ArrayList();
|
||||
ArrayList salaryArr = <span class="literal">new</span> ArrayList();
|
||||
|
||||
File file = <span class="literal">new</span> File(<span class="string">"</span><span class="string">Salary.txt</span><span class="string">"</span>);
|
||||
<span class="literal">try</span> (Scanner fileScanner = <span class="literal">new</span> Scanner(file)) {
|
||||
<span class="literal">while</span> (fileScanner.hasNext()) {
|
||||
firstNameArr.add(fileScanner.next());
|
||||
lastNameArr.add(fileScanner.next());
|
||||
jobTitleArr.add(fileScanner.next());
|
||||
salaryArr.add(fileScanner.next());
|
||||
fileScanner.nextLine(); <span class="comment">// consume newline</span>
|
||||
}
|
||||
} <span class="literal">catch</span> (Exception ex) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Unable to read file</span><span class="string">"</span>);
|
||||
}
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < firstNameArr.size(); ++i) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">first name :</span><span class="string">"</span> + firstNameArr.get(i));
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">last name: </span><span class="string">"</span> + lastNameArr.get(i));
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">job title: </span><span class="string">"</span> + jobTitleArr.get(i));
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">salary: </span><span class="string">"</span> + salaryArr.get(i));
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">--------------------------------------</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,39 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>MP5_CalebFontenot.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.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"> */</span>
|
||||
|
||||
<span class="literal">package</span> com.calebfontenot.mp5_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> MP5_CalebFontenot {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
System.out.println(<span class="string">"</span><span class="string">Hello World!</span><span class="string">"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,91 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>MyStack.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST2 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST3 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST4 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MyStack.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.mp5_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">import</span> java.util.ArrayList;
|
||||
|
||||
<span class="literal">public</span> <span class="literal">class</span> MyStack <span class="literal">implements</span> Cloneable {
|
||||
<span class="literal">private</span> ArrayList<Object> <span class="ST1">list</span> = <span class="literal">new</span> ArrayList<>();
|
||||
|
||||
<span class="literal">public</span> <span class="literal">boolean</span> <span class="ST2">isEmpty</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">list</span>.isEmpty();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">getSize</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">list</span>.size();
|
||||
}
|
||||
|
||||
<span class="literal">public</span> Object <span class="ST2">peek</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">list</span>.get(getSize() - <span class="number">1</span>);
|
||||
}
|
||||
|
||||
<span class="literal">public</span> Object <span class="ST2">pop</span>() {
|
||||
Object o = <span class="ST1">list</span>.get(getSize() - <span class="number">1</span>);
|
||||
<span class="ST1">list</span>.remove(getSize() - <span class="number">1</span>);
|
||||
<span class="literal">return</span> o;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">push</span>(Object o) {
|
||||
<span class="ST1">list</span>.add(o);
|
||||
}
|
||||
|
||||
@Override <span class="comment">/**</span> <span class="comment">Override</span> <span class="comment">the</span> <span class="comment">toString</span> <span class="comment">in</span> <span class="comment">the</span> <span class="comment">Object</span> <span class="comment">class</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> String <span class="ST2">toString</span>() {
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">stack: </span><span class="string">"</span> + <span class="ST1">list</span>.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> Object <span class="ST2">clone</span>() <span class="literal">throws</span> CloneNotSupportedException {
|
||||
MyStack clonedStack = (MyStack) <span class="literal">super</span>.clone();
|
||||
ArrayList<Object> newList = <span class="literal">new</span> ArrayList<>(<span class="ST1">l</span><span class="ST1">ist</span>);
|
||||
clonedStack.<span class="ST1">list</span> = newList;
|
||||
<span class="literal">return</span> clonedStack;
|
||||
}
|
||||
|
||||
<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">throws</span> CloneNotSupportedException {
|
||||
MyStack stack = <span class="literal">new</span> MyStack();
|
||||
<span class="literal">final</span> <span class="literal">int</span> STACK_SIZE = <span class="number">50</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < STACK_SIZE; ++i) {
|
||||
stack.push(i + <span class="number">1</span>); <span class="comment">// Fill Stack with sequential numbers.</span>
|
||||
<span class="comment">//System.out.println(stack.peek());</span>
|
||||
}
|
||||
System.<span class="ST4">out</span>.println(stack.peek());
|
||||
MyStack clonedStack = (MyStack) stack.clone();
|
||||
System.<span class="ST4">out</span>.println(clonedStack.peek());
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,203 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>NormalizeDatabase.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST4 {color: #9876aa}
|
||||
.ST1 {color: #8a653b}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST2 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST5 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/NormalizeDatabase.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.mp5_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="comment">/*</span>
|
||||
<span class="comment"> * To change this license header, choose License Headers in Project Properties.</span>
|
||||
<span class="comment"> * To change this template file, choose Tools | Templates</span>
|
||||
<span class="comment"> * and open the template in the editor.</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">import</span> java.util.ArrayList;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">ASDV2</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> NormalizeDatabase
|
||||
{
|
||||
<span class="comment">/**</span><span class="comment">Finds</span> <span class="comment">the</span> <span class="comment">closure</span> <span class="comment">of</span> <span class="comment">a</span> <span class="comment">set</span> <span class="comment">of</span> <span class="comment">attributes</span> <span class="comment">given</span> <span class="comment">a</span> <span class="comment">set</span> <span class="comment">of</span> <span class="comment">FDs</span> <span class="comment">of</span> <span class="comment">a</span> <span class="comment">relation</span> <span class="comment">R</span>
|
||||
<span class="comment"> * </span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">attributes</span> <span class="comment">attributes</span> <span class="comment">to</span> <span class="comment">find</span> <span class="comment">their</span> <span class="comment">closure</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">fds</span> <span class="comment">set</span> <span class="comment">of</span> <span class="comment">FDs</span> <span class="comment">of</span> <span class="comment">relation</span> <span class="comment">R</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">the</span> <span class="comment">closure</span> <span class="comment">of</span> <span class="comment">the</span> <span class="comment">parameter</span> <span class="comment">attributes</span><span class="comment">.</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> String <span class="ST2">closure</span>(String attributes, ArrayList<FD> fds )
|
||||
{
|
||||
attributes = attributes.toUpperCase();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < fds.size(); ++j)
|
||||
{
|
||||
FD capitalsFD = <span class="literal">new</span> FD(fds.get(j).getLhs().toUpperCase(),
|
||||
fds.get(j).getRhs().toUpperCase());
|
||||
fds.set(j, capitalsFD);
|
||||
}
|
||||
<span class="comment">// 1. Set x+ = x</span>
|
||||
String closure = attributes;
|
||||
String closurePreveious = attributes;
|
||||
<span class="comment">// 2. Starting with x+ apply each FD xF —> y in F where</span>
|
||||
<span class="comment">// xF belongs in closure x+ but but the rhs y is not already in x+, to find determined</span>
|
||||
<span class="comment">// attributes y</span>
|
||||
<span class="comment">// 3. x+ = x+ U y</span>
|
||||
|
||||
<span class="literal">while</span> (<span class="literal">true</span>)
|
||||
{
|
||||
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < fds.size(); ++i)
|
||||
{
|
||||
<span class="literal">if</span> (closure.contains(fds.get(i).getRhs()))
|
||||
<span class="literal">continue</span>;
|
||||
<span class="comment">// if the left hand side of the FD is contained in the closure</span>
|
||||
<span class="comment">// then add to the closure the RHS of the FD</span>
|
||||
<span class="literal">if</span> (closure.contains(fds.get(i).getLhs()))
|
||||
closure += fds.get(i).getRhs();
|
||||
}
|
||||
<span class="literal">if</span> (closurePreveious.equals(closure))
|
||||
<span class="literal">break</span>;
|
||||
<span class="literal">else</span>
|
||||
closurePreveious = closure;
|
||||
}
|
||||
|
||||
<span class="comment">// 4, If y not empty goto (2)</span>
|
||||
<span class="comment">// 5. Return x+</span>
|
||||
<span class="literal">return</span> closure;
|
||||
|
||||
}
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> * </span><span class="comment">Eliminates</span> <span class="comment">redundant</span> <span class="comment">attributes</span> <span class="comment">from</span> <span class="comment">the</span> <span class="comment">LHS</span> <span class="comment">of</span> <span class="comment">each</span> <span class="comment">FD</span> <span class="comment">of</span> <span class="comment">a</span> <span class="comment">set</span> <span class="comment">of</span> <span class="comment">FDs</span>
|
||||
<span class="comment"> * </span><span class="comment">given</span> <span class="comment">as</span> <span class="comment">parameters</span><span class="comment">.</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="comment">@param</span> <span class="ST1">fds</span> <span class="comment">the</span> <span class="comment">set</span> <span class="comment">of</span> <span class="comment">FDs</span> <span class="comment">to</span> <span class="comment">eliminate</span> <span class="comment">the</span> <span class="comment">redundancy</span>
|
||||
<span class="comment"> * </span><span class="comment">@return</span> <span class="comment">and</span> <span class="comment">ArrayList</span> <span class="comment">with</span> <span class="comment">no</span> <span class="comment">redundancy</span> <span class="comment">on</span> <span class="comment">LHS</span> <span class="comment">of</span> <span class="comment">each</span> <span class="comment">FD</span><span class="comment">.</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> ArrayList<FD> <span class="ST2">eliminateRedundantAttributes</span>(ArrayList<FD> fds)
|
||||
{
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < fds.size(); ++j)
|
||||
{
|
||||
<span class="literal">int</span> s = fds.get(j).getLhs().length();
|
||||
<span class="literal">if</span> (s < <span class="number">2</span>)
|
||||
{
|
||||
<span class="literal">continue</span>;
|
||||
}
|
||||
<span class="literal">else</span>
|
||||
{
|
||||
String fl = fds.get(j).getLhs().substring(<span class="number">0</span>, <span class="number">1</span>);
|
||||
ArrayList<FD> <span class="comment">fFD</span> = <span class="literal">new</span> ArrayList<FD>();
|
||||
String s1 = <span class="string">"</span> <span class="string">"</span>;
|
||||
<span class="literal">if</span> (fds.get(j).getLhs().length() == <span class="number">2</span>)
|
||||
{
|
||||
s1 = fds.get(j).getLhs().substring(<span class="number">1</span>);
|
||||
<span class="literal">if</span> (<span class="ST3">closure</span>(s1,fds).contains(fl))
|
||||
{
|
||||
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">1</span>, <span class="number">2</span>), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
|
||||
}
|
||||
}
|
||||
<span class="literal">else</span> <span class="literal">if</span> (fds.get(j).getLhs().charAt(<span class="number">1</span>) == <span class="number">3</span>)
|
||||
{
|
||||
s1 = fds.get(j).getLhs().substring(<span class="number">1</span>);
|
||||
<span class="literal">if</span> (<span class="ST3">closure</span>(s1,fds).contains(fl))
|
||||
{
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">1</span>, <span class="number">2</span>), fds.get(j).getRhs()));
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">2</span>, <span class="number">3</span>), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
}
|
||||
}
|
||||
<span class="literal">else</span> <span class="literal">if</span> (fds.get(j).getLhs().charAt(<span class="number">1</span>) == <span class="number">4</span>)
|
||||
{
|
||||
s1 = fds.get(j).getLhs().substring(<span class="number">1</span>);
|
||||
<span class="literal">if</span> (<span class="ST3">closure</span>(s1,fds).contains(fl))
|
||||
{
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">1</span>, <span class="number">2</span>), fds.get(j).getRhs()));
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">2</span>, <span class="number">3</span>), fds.get(j).getRhs()));
|
||||
fds.add(<span class="literal">new</span> FD (fds.get(j).getLhs().substring(<span class="number">3</span>, <span class="number">4</span>), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">else</span>
|
||||
{
|
||||
<span class="literal">return</span> fds;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">return</span> fds;
|
||||
}
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
|
||||
{
|
||||
ArrayList<FD> fds = <span class="literal">new</span> ArrayList<FD>();
|
||||
FD fd = <span class="literal">new</span> FD(<span class="string">"</span><span class="string">a</span><span class="string">"</span>, <span class="string">"</span><span class="string">BC</span><span class="string">"</span>);
|
||||
FD[] fdDecomposed = fd.decomposeRightHandSide();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < fdDecomposed.<span class="ST4">length</span>; ++i)
|
||||
{
|
||||
fds.add( <span class="literal">new</span> FD(fdDecomposed[i].getLhs(), fdDecomposed[i].getRhs()));
|
||||
}
|
||||
|
||||
fds.add(<span class="literal">new</span> FD(<span class="string">"</span><span class="string">B</span><span class="string">"</span>, <span class="string">"</span><span class="string">C</span><span class="string">"</span>));
|
||||
fds.add(<span class="literal">new</span> FD(<span class="string">"</span><span class="string">AB</span><span class="string">"</span>, <span class="string">"</span><span class="string">B</span><span class="string">"</span>));
|
||||
fds.add(<span class="literal">new</span> FD(<span class="string">"</span><span class="string">C</span><span class="string">"</span>, <span class="string">"</span><span class="string">A</span><span class="string">"</span>));
|
||||
System.<span class="ST5">out</span>.println(fds);
|
||||
System.<span class="ST5">out</span>.println(<span class="ST3">c</span><span class="ST3">losure</span>(<span class="string">"</span><span class="string">b</span><span class="string">"</span>, fds));
|
||||
System.<span class="ST5">out</span>.println(<span class="ST3">e</span><span class="ST3">liminateRedundantAttributes</span>(fds));
|
||||
<span class="comment">/* TEST it with </span>
|
||||
<span class="comment"> Let F1 = {1. A -> BC </span>
|
||||
<span class="comment"> 2. B -> C, </span>
|
||||
<span class="comment"> 3. AB -> D }. </span>
|
||||
<span class="comment"> Attribute B is extraneous in FD 3 AB -> D</span>
|
||||
|
||||
<span class="comment"> */</span>
|
||||
|
||||
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> F2 = { 1. AB -> C, </span>
|
||||
<span class="comment"> 2. C -> A, </span>
|
||||
<span class="comment"> 3. BC -> D, </span>
|
||||
<span class="comment"> 4. ACD -> B, </span>
|
||||
<span class="comment"> 5. D -> E, </span>
|
||||
<span class="comment"> 6. D -> G, </span>
|
||||
<span class="comment"> 7. BE -> C, </span>
|
||||
<span class="comment"> 8. CG -> B,</span>
|
||||
<span class="comment"> 9. CG -> D, </span>
|
||||
<span class="comment"> 10. CE -> A, </span>
|
||||
<span class="comment"> 11. CE -> G}</span>
|
||||
<span class="comment"> */</span>
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,188 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>PrintCalendar.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.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}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/PrintCalendar.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.mp5_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">import</span> java.util.Calendar;
|
||||
<span class="literal">import</span> java.util.Scanner;
|
||||
<span class="literal">import</span> java.util.Date;
|
||||
<span class="literal">import</span> java.util.GregorianCalendar;
|
||||
|
||||
<span class="literal">public</span> <span class="literal">class</span> PrintCalendar {
|
||||
<span class="comment">/**</span> <span class="comment">Main</span> <span class="comment">method</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||
<span class="literal">int</span> year, month;
|
||||
String userInput;
|
||||
|
||||
<span class="literal">do</span> {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">What would you like to do?</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">1. Print today's date.</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">2. Print a specified date.</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Q/q. Quit.</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Respond with 1, 2 or Q/q: </span><span class="string">"</span>);
|
||||
userInput = input.next();
|
||||
<span class="literal">if</span> (userInput.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">q</span><span class="string">'</span>) {
|
||||
System.<span class="ST3">exit</span>(<span class="number">0</span>);
|
||||
}
|
||||
<span class="literal">if</span> (Integer.<span class="ST3">parseInt</span>(userInput) < <span class="number">0</span> || Integer.<span class="ST3">parseInt</span>(userInput) > <span class="number">2</span>) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Invalid input!</span><span class="string">"</span>);
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">if</span> (Integer.<span class="ST3">parseInt</span>(userInput) == <span class="number">1</span>) {
|
||||
Date date = <span class="literal">new</span> Date();
|
||||
<span class="ST3">printMonth</span>((date.getYear() + <span class="number">1900</span>), date.getMonth());
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (Integer.<span class="ST3">parseInt</span>(userInput) == <span class="number">2</span>) {
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a month (1-12): </span><span class="string">"</span>);
|
||||
month = (input.nextInt() + <span class="number">1</span>);
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter a year: </span><span class="string">"</span>);
|
||||
year = (input.nextInt());
|
||||
GregorianCalendar date = <span class="literal">new</span> GregorianCalendar(year, month, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);
|
||||
<span class="ST3">printMonth</span>(date.get(Calendar.<span class="ST2">YEAR</span>), date.get(Calendar.<span class="ST2">MONTH</span>));
|
||||
}
|
||||
}
|
||||
} <span class="literal">while</span> (<span class="literal">true</span>);
|
||||
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Print</span> <span class="comment">the</span> <span class="comment">calendar</span> <span class="comment">for</span> <span class="comment">a</span> <span class="comment">month</span> <span class="comment">in</span> <span class="comment">a</span> <span class="comment">year</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printMonth</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
<span class="comment">// Print the headings of the calendar</span>
|
||||
<span class="ST3">printMonthTitle</span>(year, month);
|
||||
|
||||
<span class="comment">// Print the body of the calendar</span>
|
||||
<span class="ST3">printMonthBody</span>(year, month);
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Print</span> <span class="comment">the</span> <span class="comment">month</span> <span class="comment">title</span><span class="comment">, </span><span class="comment">e</span><span class="comment">.</span><span class="comment">g</span><span class="comment">.</span><span class="comment">, </span><span class="comment">May</span><span class="comment">, 1999 </span><span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printMonthTitle</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span> <span class="string">"</span> + <span class="ST3">getMonthName</span>(month)
|
||||
+ <span class="string">"</span> <span class="string">"</span> + year);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">-----------------------------</span><span class="string">"</span>);
|
||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string"> Sun Mon Tue Wed Thu Fri Sat</span><span class="string">"</span>);
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Get</span> <span class="comment">the</span> <span class="comment">English</span> <span class="comment">name</span> <span class="comment">for</span> <span class="comment">the</span> <span class="comment">month</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> String <span class="ST1">getMonthName</span>(<span class="literal">int</span> month) {
|
||||
String monthName = <span class="string">""</span>;
|
||||
<span class="literal">switch</span> (month) {
|
||||
<span class="literal">case</span> <span class="number">1</span>: monthName = <span class="string">"</span><span class="string">January</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">2</span>: monthName = <span class="string">"</span><span class="string">February</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">3</span>: monthName = <span class="string">"</span><span class="string">March</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">4</span>: monthName = <span class="string">"</span><span class="string">April</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">5</span>: monthName = <span class="string">"</span><span class="string">May</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">6</span>: monthName = <span class="string">"</span><span class="string">June</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">7</span>: monthName = <span class="string">"</span><span class="string">July</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">8</span>: monthName = <span class="string">"</span><span class="string">August</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">9</span>: monthName = <span class="string">"</span><span class="string">September</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">10</span>: monthName = <span class="string">"</span><span class="string">October</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">11</span>: monthName = <span class="string">"</span><span class="string">November</span><span class="string">"</span>; <span class="literal">break</span>;
|
||||
<span class="literal">case</span> <span class="number">12</span>: monthName = <span class="string">"</span><span class="string">December</span><span class="string">"</span>;
|
||||
}
|
||||
|
||||
<span class="literal">return</span> monthName;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Print</span> <span class="comment">month</span> <span class="comment">body</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">printMonthBody</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
<span class="comment">// Get start day of the week for the first date in the month</span>
|
||||
<span class="literal">int</span> startDay = <span class="ST3">getStartDay</span>(year, month);
|
||||
|
||||
<span class="comment">// Get number of days in the month</span>
|
||||
<span class="literal">int</span> numberOfDaysInMonth = <span class="ST3">getNumberOfDaysInMonth</span>(year, month);
|
||||
|
||||
<span class="comment">// Pad space before the first day of the month</span>
|
||||
<span class="literal">int</span> i = <span class="number">0</span>;
|
||||
<span class="literal">for</span> (i = <span class="number">0</span>; i < startDay; i++)
|
||||
System.<span class="ST2">out</span>.print(<span class="string">"</span> <span class="string">"</span>);
|
||||
|
||||
<span class="literal">for</span> (i = <span class="number">1</span>; i <= numberOfDaysInMonth; i++) {
|
||||
System.<span class="ST2">out</span>.printf(<span class="string">"</span><span class="string">%4d</span><span class="string">"</span>, i);
|
||||
|
||||
<span class="literal">if</span> ((i + startDay) % <span class="number">7</span> == <span class="number">0</span>)
|
||||
System.<span class="ST2">out</span>.println();
|
||||
}
|
||||
|
||||
System.<span class="ST2">out</span>.println();
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Get</span> <span class="comment">the</span> <span class="comment">start</span> <span class="comment">day</span> <span class="comment">of</span> <span class="comment">month</span><span class="comment">/1/</span><span class="comment">year</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST1">getStartDay</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
<span class="literal">final</span> <span class="literal">int</span> START_DAY_FOR_JAN_1_1800 = <span class="number">3</span>;
|
||||
<span class="comment">// Get total number of days from 1/1/1800 to month/1/year</span>
|
||||
<span class="literal">int</span> totalNumberOfDays = <span class="ST3">getTotalNumberOfDays</span>(year, month);
|
||||
|
||||
<span class="comment">// Return the start day for month/1/year</span>
|
||||
<span class="literal">return</span> (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % <span class="number">7</span>;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Get</span> <span class="comment">the</span> <span class="comment">total</span> <span class="comment">number</span> <span class="comment">of</span> <span class="comment">days</span> <span class="comment">since</span> <span class="comment">January</span><span class="comment"> 1, 1800 </span><span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST1">getTotalNumberOfDays</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
<span class="literal">int</span> total = <span class="number">0</span>;
|
||||
|
||||
<span class="comment">// Get the total days from 1800 to 1/1/year</span>
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">1800</span>; i < year; i++)
|
||||
<span class="literal">if</span> (<span class="ST3">isLeapYear</span>(i))
|
||||
total = total + <span class="number">366</span>;
|
||||
<span class="literal">else</span>
|
||||
total = total + <span class="number">365</span>;
|
||||
|
||||
<span class="comment">// Add days from Jan to the month prior to the calendar month</span>
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">1</span>; i < month; i++)
|
||||
total = total + <span class="ST3">getNumberOfDaysInMonth</span>(year, i);
|
||||
|
||||
<span class="literal">return</span> total;
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Get</span> <span class="comment">the</span> <span class="comment">number</span> <span class="comment">of</span> <span class="comment">days</span> <span class="comment">in</span> <span class="comment">a</span> <span class="comment">month</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">int</span> <span class="ST1">getNumberOfDaysInMonth</span>(<span class="literal">int</span> year, <span class="literal">int</span> month) {
|
||||
<span class="literal">if</span> (month == <span class="number">1</span> || month == <span class="number">3</span> || month == <span class="number">5</span> || month == <span class="number">7</span> ||
|
||||
month == <span class="number">8</span> || month == <span class="number">10</span> || month == <span class="number">12</span>)
|
||||
<span class="literal">return</span> <span class="number">31</span>;
|
||||
|
||||
<span class="literal">if</span> (month == <span class="number">4</span> || month == <span class="number">6</span> || month == <span class="number">9</span> || month == <span class="number">11</span>)
|
||||
<span class="literal">return</span> <span class="number">30</span>;
|
||||
|
||||
<span class="literal">if</span> (month == <span class="number">2</span>) <span class="literal">return</span> <span class="ST3">isLeapYear</span>(year) ? <span class="number">29</span> : <span class="number">28</span>;
|
||||
|
||||
<span class="literal">return</span> <span class="number">0</span>; <span class="comment">// If month is incorrect</span>
|
||||
}
|
||||
|
||||
<span class="comment">/**</span> <span class="comment">Determine</span> <span class="comment">if</span> <span class="comment">it</span> <span class="comment">is</span> <span class="comment">a</span> <span class="comment">leap</span> <span class="comment">year</span> <span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">boolean</span> <span class="ST1">isLeapYear</span>(<span class="literal">int</span> year) {
|
||||
<span class="literal">return</span> year % <span class="number">400</span> == <span class="number">0</span> || (year % <span class="number">4</span> == <span class="number">0</span> && year % <span class="number">100</span> != <span class="number">0</span>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,95 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Rectangle.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.ST1 {color: #9876aa}
|
||||
.ST2 {color: #ffc66d}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/Rectangle.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.mp5_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> Rectangle <span class="literal">extends</span> GeometricObject{
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST1">width</span>;
|
||||
<span class="literal">private</span> <span class="literal">double</span> <span class="ST1">height</span>;
|
||||
|
||||
<span class="literal">public</span> Rectangle() {
|
||||
|
||||
}
|
||||
|
||||
<span class="literal">public</span> Rectangle(<span class="literal">double</span> width, <span class="literal">double</span> height) {
|
||||
<span class="literal">this</span>.<span class="ST1">width</span> = width;
|
||||
<span class="literal">this</span>.<span class="ST1">height</span> = height;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST2">getWidth</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">width</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setWidth</span>(<span class="literal">double</span> width) {
|
||||
<span class="literal">this</span>.<span class="ST1">width</span> = width;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST2">getHeight</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">height</span>;
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">void</span> <span class="ST2">setHeight</span>(<span class="literal">double</span> height) {
|
||||
<span class="literal">this</span>.<span class="ST1">height</span> = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST2">getArea</span>() {
|
||||
<span class="literal">return</span> <span class="ST1">width</span> * <span class="ST1">height</span>;
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">double</span> <span class="ST2">getPerimeter</span>() {
|
||||
<span class="literal">return</span> <span class="number">2</span> * (<span class="ST1">width</span> + <span class="ST1">height</span>);
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compareTo</span>(GeometricObject t) {
|
||||
System.<span class="ST3">out</span>.println(<span class="literal">this</span>.getArea() + <span class="string">"</span><span class="string">, </span><span class="string">"</span> + (t).getArea());
|
||||
<span class="literal">if</span> (<span class="literal">this</span>.getArea() < (t).getArea()) {
|
||||
<span class="literal">return</span> -<span class="number">1</span>;
|
||||
} <span class="literal">else</span> <span class="literal">if</span> (<span class="literal">this</span>.getArea() > (t).getArea()) {
|
||||
<span class="literal">return</span> <span class="number">1</span>;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> <span class="number">0</span>;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compareTo</span>(Object t) {
|
||||
<span class="literal">throw</span> <span class="literal">new</span> UnsupportedOperationException(<span class="string">"</span><span class="string">Not supported yet.</span><span class="string">"</span>); <span class="comment">// Generated from </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody</span>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>ShuffleArrayList.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.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}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/ShuffleArrayList.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.mp5_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.*;
|
||||
|
||||
<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> ShuffleArrayList {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">shuffle</span>(ArrayList<Number> list) {
|
||||
<span class="comment">// Create a new Random object.</span>
|
||||
Random rng = <span class="literal">new</span> Random();
|
||||
<span class="comment">// Create an ArrayList to store the indices of the elements that have been selected.</span>
|
||||
ArrayList<Integer> selectedIndices = <span class="literal">new</span> ArrayList<Integer>();
|
||||
|
||||
<span class="comment">// Loop through each element in the list.</span>
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < list.size(); ++i) {
|
||||
<span class="comment">// Generate a random index that has not been selected before.</span>
|
||||
<span class="literal">int</span> randomIndex;
|
||||
<span class="literal">do</span> {
|
||||
randomIndex = rng.nextInt(list.size()); <span class="comment">// Generate a random integer between 0 (inclusive) and the size of the list (exclusive).</span>
|
||||
} <span class="literal">while</span> (selectedIndices.contains(randomIndex)); <span class="comment">// Repeat until an unselected index is found.</span>
|
||||
selectedIndices.add(randomIndex); <span class="comment">// Add the selected index to the list of selected indices.</span>
|
||||
<span class="comment">//System.out.println(randomIndex + ", " + i);</span>
|
||||
<span class="comment">// Swap the element at the random index with the element at the current index of the loop.</span>
|
||||
<span class="comment">// This shuffles the list by randomly selecting an element to swap with the current element at each iteration.</span>
|
||||
Number temp = list.get(randomIndex); <span class="comment">// Save the element at the random index to a temporary variable.</span>
|
||||
list.set(randomIndex, list.get(i)); <span class="comment">// Overwrite the element at the random index with the element at the current index of the loop.</span>
|
||||
list.set(i, temp); <span class="comment">// Set the current index of the loop to the saved element, effectively swapping the two elements.</span>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> String <span class="ST1">checkForDuplicates</span>(ArrayList<Number> list) {
|
||||
<span class="comment">// Ensure Array does not include repeat numbers.</span>
|
||||
<span class="literal">boolean</span> repeatNumber = <span class="literal">false</span>;
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < list.size(); ++i) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = <span class="number">0</span>; j < list.size(); ++j) {
|
||||
<span class="literal">if</span> (i != j) {
|
||||
<span class="comment">//System.out.println("Checking " + list.get(i) + " and " + list.get(j));</span>
|
||||
<span class="literal">if</span> (list.get(i) == list.get(j)) {
|
||||
repeatNumber = <span class="literal">true</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class="literal">if</span> (repeatNumber) {
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">Numbers repeat in ArrayList.</span><span class="string">"</span>;
|
||||
} <span class="literal">else</span> {
|
||||
<span class="literal">return</span> <span class="string">"</span><span class="string">Numbers do not repeat in ArrayList.</span><span class="string">"</span>;
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="literal">final</span> <span class="literal">int</span> ARRAY_SIZE = <span class="number">50</span>;
|
||||
ArrayList<Number> list = <span class="literal">new</span> ArrayList<>();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < ARRAY_SIZE; ++i) {
|
||||
list.add(i + <span class="number">1</span>); <span class="comment">// Fill ArrayList with sequential numbers.</span>
|
||||
}
|
||||
|
||||
System.<span class="ST2">out</span>.println(list);
|
||||
System.<span class="ST2">out</span>.println(<span class="ST3">c</span><span class="ST3">heckForDuplicates</span>(list));
|
||||
<span class="ST3">shuffle</span>(list);
|
||||
System.<span class="ST2">out</span>.println(list);
|
||||
System.<span class="ST2">out</span>.println(<span class="ST3">c</span><span class="ST3">heckForDuplicates</span>(list));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,74 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>SortArrayList.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST2 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/SortArrayList.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.mp5_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.math.BigDecimal;
|
||||
<span class="literal">import</span> java.util.ArrayList;
|
||||
|
||||
<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> SortArrayList {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">sort</span>(ArrayList<Number> list) {
|
||||
<span class="comment">// Selection sort implementation for ArrayLists.</span>
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < list.size(); ++i) {
|
||||
<span class="literal">for</span> (<span class="literal">int</span> j = i + <span class="number">1</span>; j < list.size(); ++j) {
|
||||
<span class="comment">// BigDecimal should work for any type. Have not confirmed this.</span>
|
||||
Number numI = list.get(i);
|
||||
Number numJ = list.get(j);
|
||||
BigDecimal bigNumI = <span class="literal">new</span> BigDecimal(list.get(i).toString());
|
||||
BigDecimal bigNumJ = <span class="literal">new</span> BigDecimal(list.get(j).toString());
|
||||
<span class="literal">if</span> (bigNumI.compareTo(bigNumJ) == <span class="number">1</span>) {
|
||||
Number tmp = numI;
|
||||
list.set(i, numJ);
|
||||
list.set(j, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
<span class="literal">final</span> <span class="literal">int</span> ARRAY_SIZE = <span class="number">50</span>;
|
||||
ArrayList<Number> list = <span class="literal">new</span> ArrayList<>();
|
||||
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i < ARRAY_SIZE; ++i) {
|
||||
list.add((i) + Math.<span class="ST2">random</span>()); <span class="comment">// Fill ArrayList with sequential numbers.</span>
|
||||
}
|
||||
System.<span class="ST3">out</span>.println(list);
|
||||
ShuffleArrayList.<span class="ST2">shuffle</span>(list); <span class="comment">// Use our shuffle method from earlier</span>
|
||||
System.<span class="ST3">out</span>.println(list);
|
||||
<span class="ST2">sort</span>(list);
|
||||
System.<span class="ST3">out</span>.println(list);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>TestCircle.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST0 {color: #287bde}
|
||||
.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}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/TestCircle.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.mp5_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> TestCircle {
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||
Circle circle1 = <span class="literal">new</span> Circle(<span class="number">5</span>);
|
||||
Circle circle2 = <span class="literal">new</span> Circle(<span class="number">1</span><span class="number">0</span>);
|
||||
System.<span class="ST2">out</span>.println(circle1.compareTo(circle2));
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,60 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>TestGeometricObject.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||
.literal {color: #cc7832}
|
||||
.ST2 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST0 {color: #287bde}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
.ST3 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/TestGeometricObject.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.mp5_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> TestGeometricObject {
|
||||
<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 two comparable Circles</span>
|
||||
Circle circle1 = <span class="literal">new</span> Circle(<span class="number">5</span>);
|
||||
Circle circle2 = <span class="literal">new</span> Circle(<span class="number">4</span>);
|
||||
|
||||
<span class="comment">// Display the max Circle</span>
|
||||
Circle circle = (Circle) GeometricObject.<span class="ST2">max</span>(circle1, circle2);
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">The max Circle's radius is </span><span class="string">"</span> + circle.getRadius());
|
||||
System.<span class="ST3">out</span>.println(circle);
|
||||
|
||||
<span class="comment">// Create two comparable rectangles</span>
|
||||
Rectangle r1 = <span class="literal">new</span> Rectangle(<span class="number">5</span>, <span class="number">4</span>);
|
||||
Rectangle r2 = <span class="literal">new</span> Rectangle(<span class="number">4</span>, <span class="number">5</span>);
|
||||
|
||||
System.<span class="ST3">out</span>.println(r1.compareTo(r2));
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">The max rectangle is </span><span class="string">"</span> + (Rectangle) Rectangle.<span class="ST2">max</span>(r1, r2));
|
||||
|
||||
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">The max geometric object is </span><span class="string">"</span> + GeometricObject.<span class="ST2">max</span>(circle1, r2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</pre></body>
|
||||
</html>
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Circle extends GeometricObject {
|
||||
private double diameter;
|
||||
|
||||
public Circle(double diameter) {
|
||||
this.diameter = diameter;
|
||||
System.out.println("Circle Diameter: " + diameter);
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return diameter / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
double radius = diameter / 2;
|
||||
return Math.PI * Math.pow(radius, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPerimeter() {
|
||||
return Math.PI * diameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Circle{" + "diameter=" + diameter + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GeometricObject t) {
|
||||
System.out.println(this.getArea() + ", " + (t).getArea());
|
||||
if (this.getArea() < (t).getArea()) {
|
||||
return -1;
|
||||
} else if (this.getArea() > (t).getArea()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object t) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public abstract class GeometricObject implements Comparable {
|
||||
|
||||
private String color = "white";
|
||||
private boolean filled;
|
||||
private java.util.Date dateCreated;
|
||||
|
||||
/**
|
||||
* Construct a default geometric object
|
||||
*/
|
||||
protected GeometricObject() {
|
||||
dateCreated = new java.util.Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a geometric object with color and filled value
|
||||
*/
|
||||
protected GeometricObject(String color, boolean filled) {
|
||||
dateCreated = new java.util.Date();
|
||||
this.color = color;
|
||||
this.filled = filled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return color
|
||||
*/
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new color
|
||||
*/
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return filled. Since filled is boolean, the get method is named isFilled
|
||||
*/
|
||||
public boolean isFilled() {
|
||||
return filled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new filled
|
||||
*/
|
||||
public void setFilled(boolean filled) {
|
||||
this.filled = filled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dateCreated
|
||||
*/
|
||||
public java.util.Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "created on " + dateCreated + "\ncolor: " + color
|
||||
+ " and filled: " + filled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method getArea
|
||||
*/
|
||||
public abstract double getArea();
|
||||
|
||||
/**
|
||||
* Abstract method getPerimeter
|
||||
*/
|
||||
public abstract double getPerimeter();
|
||||
|
||||
// Additional code below
|
||||
public abstract int compareTo(GeometricObject t);
|
||||
|
||||
public static GeometricObject max(GeometricObject o1, GeometricObject o2) {
|
||||
if (o1.getArea() >= o2.getArea()) {
|
||||
return o1;
|
||||
} else {
|
||||
return o2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MyStack implements Cloneable {
|
||||
private ArrayList<Object> list = new ArrayList<>();
|
||||
|
||||
public boolean isEmpty() {
|
||||
return list.isEmpty();
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
public Object peek() {
|
||||
return list.get(getSize() - 1);
|
||||
}
|
||||
|
||||
public Object pop() {
|
||||
Object o = list.get(getSize() - 1);
|
||||
list.remove(getSize() - 1);
|
||||
return o;
|
||||
}
|
||||
|
||||
public void push(Object o) {
|
||||
list.add(o);
|
||||
}
|
||||
|
||||
@Override /** Override the toString in the Object class */
|
||||
public String toString() {
|
||||
return "stack: " + list.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
MyStack clonedStack = (MyStack) super.clone();
|
||||
ArrayList<Object> newList = new ArrayList<>(list);
|
||||
clonedStack.list = newList;
|
||||
return clonedStack;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws CloneNotSupportedException {
|
||||
MyStack stack = new MyStack();
|
||||
final int STACK_SIZE = 50;
|
||||
for (int i = 0; i < STACK_SIZE; ++i) {
|
||||
stack.push(i + 1); // Fill Stack with sequential numbers.
|
||||
//System.out.println(stack.peek());
|
||||
}
|
||||
System.out.println(stack.peek());
|
||||
MyStack clonedStack = (MyStack) stack.clone();
|
||||
System.out.println(clonedStack.peek());
|
||||
}
|
||||
}
|
@ -14,7 +14,6 @@ package com.calebfontenot.mp5_calebfontenot;
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -86,40 +85,51 @@ public class NormalizeDatabase
|
||||
}
|
||||
else
|
||||
{
|
||||
String fl = fds.get(j).getLhs().substring(0);
|
||||
String fl = fds.get(j).getLhs().substring(0, 1);
|
||||
ArrayList<FD> fFD = new ArrayList<FD>();
|
||||
String s1 = " ";
|
||||
if (fds.get(j).getLhs().length() == 2)
|
||||
{
|
||||
|
||||
{
|
||||
s1 = fds.get(j).getLhs().substring(1);
|
||||
fFD.add(new FD (fds.get(j).getLhs().substring(1), fds.get(j).getLhs()));
|
||||
System.out.println("closure " + closure(s1, fds));
|
||||
System.out.println("Attribute " + s1);
|
||||
System.out.println("final (removed " + fFD);
|
||||
if (closure(s1,fds).contains(fl))
|
||||
{
|
||||
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
|
||||
}
|
||||
}
|
||||
// else if (fds.get(j).getLhs().charAt(1) == 3)
|
||||
// {
|
||||
// lFD.add(fds.get(j).getLhs().charAt(1));
|
||||
// lFD.add(fds.get(j).getLhs().charAt(2));
|
||||
// }
|
||||
// else if (fds.get(j).getLhs().charAt(1) == 4)
|
||||
// {
|
||||
// lFD.add(fds.get(j).getLhs().charAt(1));
|
||||
// lFD.add(fds.get(j).getLhs().charAt(2));
|
||||
// lFD.add(fds.get(j).getLhs().charAt(3));
|
||||
// }
|
||||
if (closure(s1, fds).contains(fl))
|
||||
else if (fds.get(j).getLhs().charAt(1) == 3)
|
||||
{
|
||||
return fFD;
|
||||
s1 = fds.get(j).getLhs().substring(1);
|
||||
if (closure(s1,fds).contains(fl))
|
||||
{
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(2, 3), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
}
|
||||
}
|
||||
else if (fds.get(j).getLhs().charAt(1) == 4)
|
||||
{
|
||||
s1 = fds.get(j).getLhs().substring(1);
|
||||
if (closure(s1,fds).contains(fl))
|
||||
{
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(1, 2), fds.get(j).getRhs()));
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(2, 3), fds.get(j).getRhs()));
|
||||
fds.add(new FD (fds.get(j).getLhs().substring(3, 4), fds.get(j).getRhs()));
|
||||
fds.remove(j);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return fds;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
return fds;
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
import java.util.Calendar;
|
||||
import java.util.Scanner;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class PrintCalendar {
|
||||
/** Main method */
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
int year, month;
|
||||
String userInput;
|
||||
|
||||
do {
|
||||
System.out.println("What would you like to do?");
|
||||
System.out.println("1. Print today's date.");
|
||||
System.out.println("2. Print a specified date.");
|
||||
System.out.println("Q/q. Quit.");
|
||||
System.out.print("Respond with 1, 2 or Q/q: ");
|
||||
userInput = input.next();
|
||||
if (userInput.toLowerCase().charAt(0) == 'q') {
|
||||
System.exit(0);
|
||||
}
|
||||
if (Integer.parseInt(userInput) < 0 || Integer.parseInt(userInput) > 2) {
|
||||
System.out.println("Invalid input!");
|
||||
} else {
|
||||
if (Integer.parseInt(userInput) == 1) {
|
||||
Date date = new Date();
|
||||
printMonth((date.getYear() + 1900), date.getMonth());
|
||||
} else if (Integer.parseInt(userInput) == 2) {
|
||||
System.out.print("Enter a month (1-12): ");
|
||||
month = (input.nextInt() + 1);
|
||||
System.out.print("Enter a year: ");
|
||||
year = (input.nextInt());
|
||||
GregorianCalendar date = new GregorianCalendar(year, month, 0, 0, 0);
|
||||
printMonth(date.get(Calendar.YEAR), date.get(Calendar.MONTH));
|
||||
}
|
||||
}
|
||||
} while (true);
|
||||
|
||||
}
|
||||
|
||||
/** Print the calendar for a month in a year */
|
||||
public static void printMonth(int year, int month) {
|
||||
// Print the headings of the calendar
|
||||
printMonthTitle(year, month);
|
||||
|
||||
// Print the body of the calendar
|
||||
printMonthBody(year, month);
|
||||
}
|
||||
|
||||
/** Print the month title, e.g., May, 1999 */
|
||||
public static void printMonthTitle(int year, int month) {
|
||||
System.out.println(" " + getMonthName(month)
|
||||
+ " " + year);
|
||||
System.out.println("-----------------------------");
|
||||
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
|
||||
}
|
||||
|
||||
/** Get the English name for the month */
|
||||
public static String getMonthName(int month) {
|
||||
String monthName = "";
|
||||
switch (month) {
|
||||
case 1: monthName = "January"; break;
|
||||
case 2: monthName = "February"; break;
|
||||
case 3: monthName = "March"; break;
|
||||
case 4: monthName = "April"; break;
|
||||
case 5: monthName = "May"; break;
|
||||
case 6: monthName = "June"; break;
|
||||
case 7: monthName = "July"; break;
|
||||
case 8: monthName = "August"; break;
|
||||
case 9: monthName = "September"; break;
|
||||
case 10: monthName = "October"; break;
|
||||
case 11: monthName = "November"; break;
|
||||
case 12: monthName = "December";
|
||||
}
|
||||
|
||||
return monthName;
|
||||
}
|
||||
|
||||
/** Print month body */
|
||||
public static void printMonthBody(int year, int month) {
|
||||
// Get start day of the week for the first date in the month
|
||||
int startDay = getStartDay(year, month);
|
||||
|
||||
// Get number of days in the month
|
||||
int numberOfDaysInMonth = getNumberOfDaysInMonth(year, month);
|
||||
|
||||
// Pad space before the first day of the month
|
||||
int i = 0;
|
||||
for (i = 0; i < startDay; i++)
|
||||
System.out.print(" ");
|
||||
|
||||
for (i = 1; i <= numberOfDaysInMonth; i++) {
|
||||
System.out.printf("%4d", i);
|
||||
|
||||
if ((i + startDay) % 7 == 0)
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/** Get the start day of month/1/year */
|
||||
public static int getStartDay(int year, int month) {
|
||||
final int START_DAY_FOR_JAN_1_1800 = 3;
|
||||
// Get total number of days from 1/1/1800 to month/1/year
|
||||
int totalNumberOfDays = getTotalNumberOfDays(year, month);
|
||||
|
||||
// Return the start day for month/1/year
|
||||
return (totalNumberOfDays + START_DAY_FOR_JAN_1_1800) % 7;
|
||||
}
|
||||
|
||||
/** Get the total number of days since January 1, 1800 */
|
||||
public static int getTotalNumberOfDays(int year, int month) {
|
||||
int total = 0;
|
||||
|
||||
// Get the total days from 1800 to 1/1/year
|
||||
for (int i = 1800; i < year; i++)
|
||||
if (isLeapYear(i))
|
||||
total = total + 366;
|
||||
else
|
||||
total = total + 365;
|
||||
|
||||
// Add days from Jan to the month prior to the calendar month
|
||||
for (int i = 1; i < month; i++)
|
||||
total = total + getNumberOfDaysInMonth(year, i);
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/** Get the number of days in a month */
|
||||
public static int getNumberOfDaysInMonth(int year, int month) {
|
||||
if (month == 1 || month == 3 || month == 5 || month == 7 ||
|
||||
month == 8 || month == 10 || month == 12)
|
||||
return 31;
|
||||
|
||||
if (month == 4 || month == 6 || month == 9 || month == 11)
|
||||
return 30;
|
||||
|
||||
if (month == 2) return isLeapYear(year) ? 29 : 28;
|
||||
|
||||
return 0; // If month is incorrect
|
||||
}
|
||||
|
||||
/** Determine if it is a leap year */
|
||||
public static boolean isLeapYear(int year) {
|
||||
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class Rectangle extends GeometricObject{
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public Rectangle() {
|
||||
|
||||
}
|
||||
|
||||
public Rectangle(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(double width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(double height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPerimeter() {
|
||||
return 2 * (width + height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GeometricObject t) {
|
||||
System.out.println(this.getArea() + ", " + (t).getArea());
|
||||
if (this.getArea() < (t).getArea()) {
|
||||
return -1;
|
||||
} else if (this.getArea() > (t).getArea()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object t) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
}
|
@ -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.mp5_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class TestGeometricObject {
|
||||
public static void main(String[] args) {
|
||||
// Create two comparable Circles
|
||||
Circle circle1 = new Circle(5);
|
||||
Circle circle2 = new Circle(4);
|
||||
|
||||
// Display the max Circle
|
||||
Circle circle = (Circle) GeometricObject.max(circle1, circle2);
|
||||
System.out.println("The max Circle's radius is " + circle.getRadius());
|
||||
System.out.println(circle);
|
||||
|
||||
// Create two comparable rectangles
|
||||
Rectangle r1 = new Rectangle(5, 4);
|
||||
Rectangle r2 = new Rectangle(4, 5);
|
||||
|
||||
System.out.println(r1.compareTo(r2));
|
||||
System.out.println("The max rectangle is " + (Rectangle) Rectangle.max(r1, r2));
|
||||
|
||||
System.out.println("The max geometric object is " + GeometricObject.max(circle1, r2));
|
||||
}
|
||||
}
|
||||
|
BIN
Semester 2/ZIPs/MP5_CalebFontenot.zip
Normal file
BIN
Semester 2/ZIPs/MP5_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user