73 lines
4.2 KiB
HTML
73 lines
4.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>A1.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.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}
|
|
.ST0 {color: #287bde}
|
|
.literal {color: #cc7832}
|
|
.ST5 {font-family: monospace; font-weight: bold; font-style: italic}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Semester 3/Assignments/JavaFXBallsWithComparator/src/main/java/edu/slcc/asdv/caleb/javafxballswithcomparator/A1.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> edu.slcc.asdv.caleb.javafxballswithcomparator;
|
|
|
|
<span class="literal">import</span> java.util.Arrays;
|
|
<span class="literal">import</span> java.util.Collections;
|
|
<span class="literal">import</span> java.util.List;
|
|
|
|
<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> A1 <span class="literal">implements</span> Comparable<A1> {
|
|
<span class="literal">int</span> <span class="ST1">x</span>;
|
|
<span class="literal">public</span> A1() {}
|
|
<span class="literal">public</span> A1(<span class="literal">int</span> x) {<span class="literal">this</span>.<span class="ST1">x</span> = x;}
|
|
@Override
|
|
<span class="literal">public</span> <span class="literal">int</span> <span class="ST2">compareTo</span>(A1 o)
|
|
{
|
|
<span class="literal">return</span> <span class="literal">this</span>.<span class="ST1">x</span> - o.<span class="ST1">x</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">A1{</span><span class="string">"</span> + <span class="string">"</span><span class="string">x=</span><span class="string">"</span> + <span class="ST1">x</span> + <span class="string">'</span><span class="string">}</span><span class="string">'</span>;
|
|
}
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args)
|
|
{
|
|
System.<span class="ST4">out</span>.println(<span class="string">"</span><span class="string">Sorting in ascending order</span><span class="string">"</span>);
|
|
List<A1> list1 = Arrays.<span class="ST5">asList</span>(<span class="literal">new</span> A1(<span class="number">3</span>), <span class="literal">new</span> A1(), <span class="literal">new</span> A1(<span class="number">2</span>));
|
|
|
|
Collections.<span class="ST5">sort</span>(list1);
|
|
System.<span class="ST4">out</span>.println(list1);
|
|
|
|
System.<span class="ST4">out</span>.println(<span class="string">"</span><span class="string">Sorting in descending order</span><span class="string">"</span>);
|
|
Collections.<span class="ST5">sort</span>(list1, Collections.<span class="ST5">reverseOrder</span>());
|
|
System.<span class="ST4">out</span>.println(list1);
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|