Rename year directories to allow natural ordering

This commit is contained in:
2023-12-20 03:57:27 +00:00
parent 0ab1f5ad3a
commit 1f7d812b98
1895 changed files with 0 additions and 7188 deletions

View File

@ -0,0 +1,95 @@
import java.util.*;
import java.io.*;
public class Alphabet {
// initialising a String containing all the letters of the alphabet and turning it into a character array (to save typing)
public static String alphabetString = "abcdefghijklmnopqrstuvwxyz";
public static char alphabet[] = alphabetString.toCharArray();
// declaring a Scanner object to use to scan in the user input
public static Scanner scanner = new Scanner(System.in);
public static void main(String args[]) {
System.out.println("Type the alphabet in order (lowercase).");
// prompting the user to enter 'f' or 'b' and scanning in the input (only scanning the 0th character of input)
System.out.println("Forwards or Backwards? (f/b): ");
char fb = scanner.next().charAt(0);
// switch statement to determine forward or backwards, or exit
switch(fb) {
case 'f':
System.out.println("Time taken: " + forwards() + "s");
break;
case 'b':
System.out.println("Time taken: " + backwards() + "s");
break;
default:
System.out.println("Invalid input!. You must enter either 'f' or 'b' to start.");
System.exit(1);
}
}
// method for going through the alphabet forwards
private static long forwards() {
// getting the time when the user started
long start = System.currentTimeMillis();
// looping for each of the 26 letters
int i = 0;
while (i < 26) {
// checking if the scanned in character was the correct one
// if the it was not, then i will not be incremented, and it will loop again on the same letter.
if (scanner.next().charAt(0) == alphabet[i]) {
if (i == 25) { // checking if it's the last letter, and if so, printing a special message
System.out.println("Correct! Well done!");
i++;
}
else { // otherwise, prompting the user to enter the next letter
System.out.println("[" + alphabet[i] + ": Correct! Now type '" + alphabet[++i] + "']"); // i gets incremented
}
}
}
// calculating the total time taken
long total = System.currentTimeMillis() - start;
// returning the total time taken in seconds (by dividing by 1000)
return total / 1000;
}
// method for going through the alphabet backwards
private static long backwards() {
// getting the time when the user started
long start = System.currentTimeMillis();
// looping for each of the 26 letters
int i = 25;
while (i >= 0) {
// checking if the scanned in character was the correct one
// if the it was not, then i will not be decremented, and it will loop again on the same letter.
if (scanner.next().charAt(0) == alphabet[i]) {
if (i == 0) { // checking if it's the last letter, and if so, printing a special message
System.out.println("Correct! Well done!");
i--;
}
else { // otherwise, prompting the user to enter the next letter
System.out.println("[" + alphabet[i] + ": Correct! Now type '" + alphabet[--i] + "']"); // i gets decremented
}
}
}
// calculating the total time taken
long total = System.currentTimeMillis() - start;
// returning the total time taken in seconds (by dividing by 1000)
return total / 1000;
}
}

View File

@ -0,0 +1,107 @@
import java.util.*;
import java.io.*;
public class Alphabet {
// declaring a Scanner object to use to scan in the user input
public static Scanner scanner = new Scanner(System.in);
public static void main(String args[]) {
System.out.println("Type the alphabet in order (lowercase).");
// prompting the user to enter 'f' or 'b' and scanning in the input (only scanning the 0th character of input)
System.out.println("Forwards or Backwards? (f/b): ");
char fb = scanner.next().charAt(0);
// switch statement to determine forward or backwards, or exit
switch(fb) {
case 'f':
boolean forwards = true;
break;
case 'b':
boolean forwards = false;
break;
default:
System.out.println("Invalid input!. You must enter either 'f' or 'b' to start.");
System.exit(1);
}
if (forwards) {
char c = 'a';
while (c < 'z') {
// checking if the scanned in character was the correct one
// if the it was not, then c will not be incremented, and it will loop again on the same letter.
if (scanner.next().charAt(0) == c) {
if (c == 'z') { // checking if it's the last letter, and if so, printing a special message
System.out.println("Correct! Well done!");
c++;
}
else { // otherwise, prompting the user to enter the next letter
System.out.println("[" + c + ": Correct! Now type '" + ++c + "']"); // c gets incremented
}
}
}
}
// method for going through the alphabet forwards
private static long forwards() {
// getting the time when the user started
long start = System.currentTimeMillis();
// looping for each of the 26 letters
int i = 0;
while (i < 26) {
// checking if the scanned in character was the correct one
// if the it was not, then i will not be incremented, and it will loop again on the same letter.
if (scanner.next().charAt(0) == alphabet[i]) {
if (i == 25) { // checking if it's the last letter, and if so, printing a special message
System.out.println("Correct! Well done!");
i++;
}
else { // otherwise, prompting the user to enter the next letter
System.out.println("[" + alphabet[i] + ": Correct! Now type '" + alphabet[++i] + "']"); // i gets incremented
}
}
}
// calculating the total time taken
long total = System.currentTimeMillis() - start;
// returning the total time taken in seconds (by dividing by 1000)
return total / 1000;
}
// method for going through the alphabet backwards
private static long backwards() {
// getting the time when the user started
long start = System.currentTimeMillis();
// looping for each of the 26 letters
int i = 25;
while (i >= 0) {
// checking if the scanned in character was the correct one
// if the it was not, then i will not be decremented, and it will loop again on the same letter.
if (scanner.next().charAt(0) == alphabet[i]) {
if (i == 0) { // checking if it's the last letter, and if so, printing a special message
System.out.println("Correct! Well done!");
i--;
}
else { // otherwise, prompting the user to enter the next letter
System.out.println("[" + alphabet[i] + ": Correct! Now type '" + alphabet[--i] + "']"); // i gets decremented
}
}
}
// calculating the total time taken
long total = System.currentTimeMillis() - start;
// returning the total time taken in seconds (by dividing by 1000)
return total / 1000;
}
}

View File

@ -0,0 +1,152 @@
\documentclass[11pt]{article}
\usepackage{report}
\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc} % use 8-bit T1 fonts
\usepackage[colorlinks=true, linkcolor=black, citecolor=blue, urlcolor=blue]{hyperref} % hyperlinks
\usepackage{url} % simple URL typesetting
\usepackage{booktabs} % professional-quality tables
\usepackage{amsfonts} % blackboard math symbols
\usepackage{nicefrac} % compact symbols for 1/2, etc.
\usepackage{listings}
\usepackage{microtype} % microtypography
\usepackage{lipsum} % Can be removed after putting your text content
\usepackage{graphicx}
\graphicspath{ {./images/} }
\usepackage{natbib}
\usepackage{doi}
\setcitestyle{aysep={,}}
\usepackage{array}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codeorange}{rgb}{1,0.49,0}
\definecolor{backcolour}{rgb}{0.95,0.95,0.96}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegray},
keywordstyle=\color{codeorange},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codegreen},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
xleftmargin=10pt,
}
\lstset{style=mystyle}
\title{CT2109 - Object-Oriented Programming: Data Structures \& Algorithms}
\author{Andrew Hayes\\
\AND
\AND
\AND
\AND
Student ID: 21321503 \\
\AND
2BCT\\
\AND
University of Galway\\
}
% Uncomment to remove the date
% \date{February 2022}
% Uncomment to override the `A preprint' in the header
\renewcommand{\undertitle}{Assignment 01}
\renewcommand{\headeright}{CT2109 Assignment 01}
\renewcommand{\shorttitle}{}
%%% Add PDF metadata to help others organize their library
%%% Once the PDF is generated, you can check the metadata with
%%% $ pdfinfo template.pdf
% \hypersetup{
% pdftitle={A template for the arxiv style},
% pdfsubject={q-bio.NC, q-bio.QM},
% pdfauthor={David S.~Hippocampus, Elias D.~Striatum},
% pdfkeywords={First keyword, Second keyword, More},
% }
\begin{document}
\maketitle
\newpage
\setcounter{page}{1}
\section{Problem Statement with Analysis \& Design Notes}
At its most basic, this assignment will require an array of all the letters of the alphabet, and two methods:
one to loop through the array in alphabetical order, and the other to loop it in counter-alphabetical order.
There will be a choice presented to the user whether to loop through the alphabet \textit{forwards} (alphabetical order)
or \textit{backwards} (counter-alphabetical) order.
To choose between these two options there will be a case statement.
A \verb|char| will be scanned in from the user.
If the \verb|char| is equal to \verb|'f'|, then the \verb|forwards()| method will be executed, and the time taken will be printed out.
If the \verb|char| is equal to \verb|'b'|, then the \verb|backwards()| method will be executed, and the time taken will be printed out.
The \verb|default| of the case statement will be to print an error message and exit with code \verb|1|.
While the use of two separate methods for the alphabetical \& counter-alphabetical versions is not the absolute most efficient option in terms of lines of code,
the use of separate functions enhances the readability of the code and allows for a cleaner implementation, at the cost of repeating only two or three lines of code.
It also reduces the need for nested if statements, which are both inefficient and often difficult to read.
The \verb|forwards()| \& \verb|backwards()| methods will be essentially the same.
They will both return the \verb|long| data type, which will be the time taken in seconds.
To calculate the time taken in seconds, before the ``game'' begins, the start time will be recorded with \verb|System.currentTimeMillis()|.
The end time will be recorded in a similar manner at the end, and the total will be calculated from subtracting one from the other.
This total will then be divided by 1000 (to convert from milliseconds to seconds) and then returned, where it will then be printed out.
The game itself will work in a similar manner in both methods: the array of the letters of the alphabet will be looped through using a \verb|while| loop
A character will be scanned in from the user.
If the character is correct, a success message will be printed and the index variable incremented or decremented as appropriate for the method.
Otherwise, the loop will be executed again on the same character, effectively ignoring the input, until the appropriate character is entered.
If the index is at the last character of either sequence (alphabetical or counter-alphabetical), a special message will be printed out if the answer is correct.
The only real difference between the two methods will be the way in which they loop through the alphabet array.
\verb|forwards()| will loop through the array in alphabetical order, starting at index \verb|0| and incrementing the index for each correct answer, with the loop condition \verb|while (i < 26)|.
\verb|backwards()| will loop the array in counter-alphabetical order, starting at index \verb|25| and decrementing the index for each correct answer, with the loop condition \verb|while (i >= 0)|.
\section{Code}
\lstinputlisting[language=Java, breaklines=true, caption={Alphabet.java}]{../code/Alphabet.java}
\section{Testing}
There are two main scenarios that must be tested for both the \verb|forwards()| \& \verb|backwards()| methods: correct input \& incorrect input.
Of these two main scenarios, we should test them at the first character of the sequence, the last character of the sequence, and some of the middle characters.
The main reason for this is that the first \& last characters are in a sense special, particularly the last one, so what may work for the ``middle'' characters may not work for the others.
Furthermore, the case statement to choose between forwards \& backwards should be tested with input \verb|f|, \verb|b|, and some incorrect, third option.
\begin{center}
\begin{figure}[htp]
\centering
\includegraphics[width=0.7\textwidth]{invalid_input.png}
\caption{Testing invalid input to the case statement}
\end{figure}
\end{center}
\begin{center}
\begin{figure}[htp]
\centering
\includegraphics[width=0.3\textwidth]{forwards.png}
\caption{Testing forwards with valid \& invalid, first, middle, \& last input}
\end{figure}
\end{center}
\begin{center}
\begin{figure}[htp]
\centering
\includegraphics[width=0.3\textwidth]{backwards.png}
\caption{Testing backwards with valid \& invalid, first, middle, \& last input}
\end{figure}
\end{center}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,264 @@
\NeedsTeXFormat{LaTeX2e}
\ProcessOptions\relax
% fonts
\renewcommand{\rmdefault}{ptm}
\renewcommand{\sfdefault}{phv}
% set page geometry
\usepackage[verbose=true,letterpaper]{geometry}
\AtBeginDocument{
\newgeometry{
textheight=9in,
textwidth=6.5in,
top=1in,
headheight=14pt,
headsep=25pt,
footskip=30pt
}
}
\widowpenalty=10000
\clubpenalty=10000
\flushbottom
\sloppy
\newcommand{\headeright}{Ph.D. Confirmation Report}
\newcommand{\undertitle}{Ph.D. Confirmation Report}
\newcommand{\shorttitle}{\@title}
\usepackage{fancyhdr}
\fancyhf{}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\fancyheadoffset{0pt}
\rhead{\scshape \footnotesize \headeright}
\chead{\shorttitle}
\cfoot{\thepage}
%Handling Keywords
\def\keywordname{{\bfseries \emph{Keywords}}}%
\def\keywords#1{\par\addvspace\medskipamount{\rightskip=0pt plus1cm
\def\and{\ifhmode\unskip\nobreak\fi\ $\cdot$
}\noindent\keywordname\enspace\ignorespaces#1\par}}
% font sizes with reduced leading
\renewcommand{\normalsize}{%
\@setfontsize\normalsize\@xipt\@xiipt
\abovedisplayskip 7\p@ \@plus 2\p@ \@minus 5\p@
\abovedisplayshortskip \z@ \@plus 3\p@
\belowdisplayskip \abovedisplayskip
\belowdisplayshortskip 4\p@ \@plus 3\p@ \@minus 3\p@
}
\normalsize
\renewcommand{\small}{%
\@setfontsize\small\@xpt\@xipt
\abovedisplayskip 6\p@ \@plus 1.5\p@ \@minus 4\p@
\abovedisplayshortskip \z@ \@plus 2\p@
\belowdisplayskip \abovedisplayskip
\belowdisplayshortskip 3\p@ \@plus 2\p@ \@minus 2\p@
}
\renewcommand{\footnotesize}{\@setfontsize\footnotesize\@ixpt\@xpt}
\renewcommand{\scriptsize}{\@setfontsize\scriptsize\@viipt\@viiipt}
\renewcommand{\tiny}{\@setfontsize\tiny\@vipt\@viipt}
\renewcommand{\large}{\@setfontsize\large\@xiipt{14}}
\renewcommand{\Large}{\@setfontsize\Large\@xivpt{16}}
\renewcommand{\LARGE}{\@setfontsize\LARGE\@xviipt{20}}
\renewcommand{\huge}{\@setfontsize\huge\@xxpt{23}}
\renewcommand{\Huge}{\@setfontsize\Huge\@xxvpt{28}}
% sections with less space
\providecommand{\section}{}
\renewcommand{\section}{%
\@startsection{section}{1}{\z@}%
{-2.0ex \@plus -0.5ex \@minus -0.2ex}%
{ 1.5ex \@plus 0.3ex \@minus 0.2ex}%
{\large\bf\raggedright}%
}
\providecommand{\subsection}{}
\renewcommand{\subsection}{%
\@startsection{subsection}{2}{\z@}%
{-1.8ex \@plus -0.5ex \@minus -0.2ex}%
{ 0.8ex \@plus 0.2ex}%
{\normalsize\bf\raggedright}%
}
\providecommand{\subsubsection}{}
\renewcommand{\subsubsection}{%
\@startsection{subsubsection}{3}{\z@}%
{-1.5ex \@plus -0.5ex \@minus -0.2ex}%
{ 0.5ex \@plus 0.2ex}%
{\normalsize\bf\raggedright}%
}
\providecommand{\paragraph}{}
\renewcommand{\paragraph}{%
\@startsection{paragraph}{4}{\z@}%
{1.5ex \@plus 0.5ex \@minus 0.2ex}%
{-1em}%
{\normalsize\bf}%
}
\providecommand{\subparagraph}{}
\renewcommand{\subparagraph}{%
\@startsection{subparagraph}{5}{\z@}%
{1.5ex \@plus 0.5ex \@minus 0.2ex}%
{-1em}%
{\normalsize\bf}%
}
\providecommand{\subsubsubsection}{}
\renewcommand{\subsubsubsection}{%
\vskip5pt{\noindent\normalsize\rm\raggedright}%
}
% float placement
\renewcommand{\topfraction }{0.85}
\renewcommand{\bottomfraction }{0.4}
\renewcommand{\textfraction }{0.1}
\renewcommand{\floatpagefraction}{0.7}
\newlength{\@abovecaptionskip}\setlength{\@abovecaptionskip}{7\p@}
\newlength{\@belowcaptionskip}\setlength{\@belowcaptionskip}{\z@}
\setlength{\abovecaptionskip}{\@abovecaptionskip}
\setlength{\belowcaptionskip}{\@belowcaptionskip}
% swap above/below caption skip lengths for tables
\renewenvironment{table}
{\setlength{\abovecaptionskip}{\@belowcaptionskip}%
\setlength{\belowcaptionskip}{\@abovecaptionskip}%
\@float{table}}
{\end@float}
% footnote formatting
\setlength{\footnotesep }{6.65\p@}
\setlength{\skip\footins}{9\p@ \@plus 4\p@ \@minus 2\p@}
\renewcommand{\footnoterule}{\kern-3\p@ \hrule width 12pc \kern 2.6\p@}
\setcounter{footnote}{0}
% paragraph formatting
\setlength{\parindent}{\z@}
\setlength{\parskip }{5.5\p@}
% list formatting
\setlength{\topsep }{4\p@ \@plus 1\p@ \@minus 2\p@}
\setlength{\partopsep }{1\p@ \@plus 0.5\p@ \@minus 0.5\p@}
\setlength{\itemsep }{2\p@ \@plus 1\p@ \@minus 0.5\p@}
\setlength{\parsep }{2\p@ \@plus 1\p@ \@minus 0.5\p@}
\setlength{\leftmargin }{3pc}
\setlength{\leftmargini }{\leftmargin}
\setlength{\leftmarginii }{2em}
\setlength{\leftmarginiii}{1.5em}
\setlength{\leftmarginiv }{1.0em}
\setlength{\leftmarginv }{0.5em}
\def\@listi {\leftmargin\leftmargini}
\def\@listii {\leftmargin\leftmarginii
\labelwidth\leftmarginii
\advance\labelwidth-\labelsep
\topsep 2\p@ \@plus 1\p@ \@minus 0.5\p@
\parsep 1\p@ \@plus 0.5\p@ \@minus 0.5\p@
\itemsep \parsep}
\def\@listiii{\leftmargin\leftmarginiii
\labelwidth\leftmarginiii
\advance\labelwidth-\labelsep
\topsep 1\p@ \@plus 0.5\p@ \@minus 0.5\p@
\parsep \z@
\partopsep 0.5\p@ \@plus 0\p@ \@minus 0.5\p@
\itemsep \topsep}
\def\@listiv {\leftmargin\leftmarginiv
\labelwidth\leftmarginiv
\advance\labelwidth-\labelsep}
\def\@listv {\leftmargin\leftmarginv
\labelwidth\leftmarginv
\advance\labelwidth-\labelsep}
\def\@listvi {\leftmargin\leftmarginvi
\labelwidth\leftmarginvi
\advance\labelwidth-\labelsep}
% create title
\providecommand{\maketitle}{}
\renewcommand{\maketitle}{%
\par
\begingroup
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
% for perfect author name centering
\renewcommand{\@makefnmark}{\hbox to \z@{$^{\@thefnmark}$\hss}}
% The footnote-mark was overlapping the footnote-text,
% added the following to fix this problem (MK)
\long\def\@makefntext##1{%
\parindent 1em\noindent
\hbox to 1.8em{\hss $\m@th ^{\@thefnmark}$}##1
}
\thispagestyle{empty}
\@maketitle
\@thanks
%\@notice
\endgroup
\let\maketitle\relax
\let\thanks\relax
}
% rules for title box at top of first page
\newcommand{\@toptitlebar}{
\hrule height 2\p@
\vskip 0.25in
\vskip -\parskip%
}
\newcommand{\@bottomtitlebar}{
\vskip 0.29in
\vskip -\parskip
\hrule height 2\p@
\vskip 0.09in%
}
% create title (includes both anonymized and non-anonymized versions)
\providecommand{\@maketitle}{}
\renewcommand{\@maketitle}{%
\vbox{%
\hsize\textwidth
\linewidth\hsize
\vskip 0.8in
\@toptitlebar
\centering
{\LARGE\sc \@title\par}
\@bottomtitlebar
\vskip 0.5in
\textsc{\Large\undertitle}\\
\vskip 2.0in
\def\And{%
\end{tabular}\hfil\linebreak[0]\hfil%
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\ignorespaces%
}
\def\AND{%
\end{tabular}\hfil\linebreak[4]\hfil%
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\large\ignorespaces%
}
\begin{tabular}[t]{c}\bf\rule{\z@}{24\p@}\Large\@author\end{tabular}%
\vskip 1.0in \@minus 0.1in \center{\large\@date} \vskip 0.2in
}
}
% add conference notice to bottom of first page
\newcommand{\ftype@noticebox}{8}
\newcommand{\@notice}{%
% give a bit of extra room back to authors on first page
\enlargethispage{2\baselineskip}%
\@float{noticebox}[b]%
\footnotesize\@noticestring%
\end@float%
}
% abstract styling
\renewenvironment{abstract}
{
\centerline
{\large \bfseries \scshape Abstract}
\begin{quote}
}
{
\end{quote}
}
\endinput