ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/Printed HTMLs/FanList.html
2023-02-09 13:49:46 -06:00

105 lines
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>FanList.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
table {color: #888888; background-color: #313335; font-family: monospace}
.number {color: #6897bb}
.string {color: #6a8759}
.comment {color: #808080}
.whitespace {color: #505050}
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 2/Assignments/lab3_CalebFontenot/src/main/java/com/calebfontenot/lab3_calebfontenot/FanList.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab3_calebfontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> FanList {
<span class="literal">private</span> Fan[] list;
<span class="comment">// A constructor that creates a list of type fan</span>
<span class="literal">public</span> FanList(<span class="literal">int</span> listSize)
{
list = <span class="literal">new</span> Fan[listSize];
createListObjects();
}
<span class="comment">// Creates a list of Fan objects from User&#39;s input</span>
<span class="literal">private</span> <span class="literal">void</span> createListObjects()
{
Scanner scan = <span class="literal">new</span> Scanner(System.in);
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; list.length; ++i) {
Fan fan = <span class="literal">new</span> Fan();
System.out.println(<span class="string">&quot;</span><span class="string">Enter FAN data for fan </span><span class="string">&quot;</span> + (i + <span class="number">1</span>)
+ <span class="string">&quot;</span><span class="string">: color, radius, speed(1, 2 or 3) and if on (t, f)</span><span class="string">&quot;</span>);
String color = scan.next();
<span class="literal">int</span> radius = scan.nextInt();
<span class="literal">int</span> speed = scan.nextInt();
String on = scan.next();
fan.setSpeed(speed);
fan.setRadius(radius);
fan.setColor(color);
<span class="literal">if</span> (<span class="string">&quot;</span><span class="string">t</span><span class="string">&quot;</span>.compareToIgnoreCase(on) == <span class="number">0</span>) {
fan.setOn(<span class="literal">true</span>);
} <span class="literal">else</span> {
fan.setOn(<span class="literal">false</span>);
}
list[i] = fan;
System.out.println(<span class="string">&quot;</span><span class="string">----------------------------------------</span><span class="string">&quot;</span>);
}
}
@Override
<span class="literal">public</span> String toString()
{
String s = <span class="string">&quot;</span><span class="string">FanList{</span><span class="string">&quot;</span> + <span class="string">&quot;</span><span class="string">list=</span><span class="literal">\n</span><span class="string">&quot;</span>;
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; list.length; ++i) {
s += list[i].toString() + <span class="string">&quot;</span><span class="literal">\n</span><span class="string">-----------------------</span><span class="literal">\n</span><span class="string">&quot;</span>;
}
s += <span class="string">&#39;</span><span class="string">}</span><span class="string">&#39;</span>;
<span class="literal">return</span> s;
}
<span class="literal">public</span> <span class="literal">void</span> sortListByRadius()
{
<span class="literal">for</span> (<span class="literal">int</span> i = <span class="number">0</span>; i &lt; list.length - <span class="number">1</span>; ++i) {
<span class="literal">for</span> (<span class="literal">int</span> j = i + <span class="number">1</span>; j &lt; list.length; ++j) {
<span class="literal">if</span> (list[i].getRadius() &gt; list[j].getRadius()) {
Fan temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
}
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
FanList fanList = <span class="literal">new</span> FanList(<span class="number">3</span>);
System.out.println(fanList);
fanList.sortListByRadius();
System.out.println(fanList.toString());
}
}
</pre></body>
</html>