\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Cassie3.14} \pdfinfo{ /Title (compsci-201-midterm-1.pdf) /Creator (Cheatography) /Author (Cassie3.14) /Subject (CompSci 201 Midterm 1 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{CompSci 201 Midterm 1 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Cassie3.14} via \textcolor{DarkBackground}{\uline{cheatography.com/68330/cs/17217/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Cassie3.14 \\ \uline{cheatography.com/cassie3-14} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 17th December, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Interface List\textless{}E\textgreater{}}} \tn % Row 0 \SetRowColor{LightBackground} add(E e) & appends the specified element to the end of this list \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} add(int index, E element) & inserts element at specified position \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{addAll(Collection} E) & adds all elements to end of list \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} clear() & removes all elements from the list \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{contains(Object} o) & returns true if it contains object \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{containsAll(Collection} c) & returns true if all elements of collection are contained \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} equals(Object o) & compares specified object within list for equality \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} get(int indedx) & returns element at specified position \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} hashCode() & returns hashCode value \tn % Row Count 20 (+ 1) % Row 9 \SetRowColor{white} indexOf(Object o) & returns first index of specified object \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} remove(int index) & removes element at specified position \tn % Row Count 24 (+ 2) % Row 11 \SetRowColor{white} set(int index, E element) & replaces element at specified index \tn % Row Count 26 (+ 2) % Row 12 \SetRowColor{LightBackground} toArray() & returns an array containing all the elements \tn % Row Count 28 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{-ordered collection \newline -user has control over where in the list each element is inserted \newline -ALLOW DUPLICATE ELEMENTS} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Definitions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{hashCode()} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}if two objects are equal according to .equals() must have same hashcode} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Interface Set\textless{}E\textgreater{}}} \tn % Row 0 \SetRowColor{LightBackground} add(E e) & Adds the specified element if not already present \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{addAll(Collection} c) & Adds all the elements if not already present \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} clear() & Removes the elements from this set \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{contains(Object} O) & Returns true if specified element is contained \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{equals(Object} O) & Compares specified Object \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} hashCode() & returns the hash code value for the set \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{remove(Object} O) & removes the specified object if present \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} size() & returns number of elements \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} toArray() & Returns an array containing the elements of the set \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{E - the type of elements maintained by the set \newline -contains no duplicate elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.32 cm} x{5.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Class HashSet\textless{}E\textgreater{}}} \tn % Row 0 \SetRowColor{LightBackground} add(E e) & adds the element if not already present \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clone() & shallow copy, elements themselves not cloned \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{remove(Object} o) & removes object if present \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} size() & returns number of elements \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{-no duplicates \newline -no guarantee as to the iteration order of the set} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Class String}} \tn % Row 0 \SetRowColor{LightBackground} charAt(int index) & returns the character at index \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} compareTo(String anotherString) & compares two strings alphabetically (caps matter) \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} contains(Char c) & returns true only if the character is contained \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} equals(Object anotherObject) & compares to another object \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} hashCode() & returns hashCode for the string \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} length() & returns the length of the string - counts each character including spaces \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} split(String regex) & splits the string at all point of the regex \tn % Row Count 18 (+ 2) % Row 7 \SetRowColor{white} toCharArray() & converts to a character array \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{toLowerCase()/toUpperCase()} & converts all characters to lower/upper case \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{-basically a character array. Below are equivalent \newline String str = "abc"; \newline char data{[}{]} = \{'a', 'b', 'c'\};} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Class Array}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{asList(...)} & returns a fixed size list \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{equals()} & returns true if the objects compared are equal to one another \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{hashCode()} & returns a hashcode based on the elements of the array \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{toString()} & returns a sting representation of the array \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Class ArrayList\textless{}E\textgreater{} and Class LinkedList\textless{}E\textgreater{}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{ArrayList \newline -resizeable array implementation of the List interface \newline -has just about all the methods defined in the List interface \newline \newline LinkedList \newline -implements nearly all List methods \newline -traverse list from beginning or end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Circles Country}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class CirclesCountry \{ \newline /{\emph{* \newline }} Returns true if a point is inside a circle and \newline {\emph{ returns false otherwise. \newline }} @param x is x-coordinate of point \newline {\emph{ @param y is y-coordinate of point \newline }} @param cx is center of circle x-coordinate \newline {\emph{ @param cy is center of circle y-coordinate \newline }} @param r is radius of circle \newline {\emph{ @return true if (x,y) is inside circle, returns \newline }} false if (x,y) is on or outside circle \newline {\emph{/ \newline public boolean isInside(int px, int py, int cx, int cy, int r)\{ \newline double dist; //distance from the center of the circle \newline dist = Math.pow((px - cx), 2) + Math.pow((py - cy), 2); \newline return dist \textless{} r}}r; \newline \} \newline \newline public int leastBorders(int{[}{]} x, int{[}{]} y, int{[}{]} r, \newline int x1, int y1, int x2, int y2) \{ \newline int crosses = 0; \newline \newline for(int k = 0; k \textless{} x.length; k += 1)\{ \newline if (isInside(x{[}k{]}, y{[}k{]}, x1, y1, r{[}k{]}) \&\& ! isInside(x{[}k{]},y{[}k{]}, x2, y2, r{[}k{]})) \{ \newline crosses += 1; \newline \} \newline if (isInside(x{[}k{]}, y{[}k{]}, x2, y2, r{[}k{]}) \&\& ! isInside(x{[}k{]},y{[}k{]}, x1, y1, r{[}k{]})) \{ \newline crosses += 1; \newline \} \newline \} \newline return crosses; \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Body}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class Body \{ \newline \newline {\emph{/declares all the instance variables as private doubles and String \newline \newline public Body(double xp, double yp, double xv, double yv, double mass, String filename) \{ \newline myXPos = xp; \newline myYPos = yp; \newline myXVel = xv; \newline myYVel = yv; \newline myMass = mass; \newline myFileName = filename; \newline \} \newline \newline /{\bf{ \newline }} Creates a body by copying parameters from another body \newline {\emph{ @param b \newline }}/ \newline public Body(Body b) \{ //FIXME \newline myXPos = b.getX(); \newline declares the rest of the instance variables with .get methods \newline \newline \} \newline \newline /}} \newline all the get methods just return the corresponding instance variable \newline {\bf{/ \newline \newline public double calcDistance(Body b) \{ \newline return \seqsplit{Math.sqrt((Math.pow(myXPos} - b.getX(), 2.0)+ Math.pow(myYPos - b.getY(), 2.0))); \newline \} \newline \newline {\emph{ Calculates the force exerted on this body by the body specified in the parameter}} \newline \newline public double calcForceExertedBy(Body p) \{ \newline double force; \newline double G = 6.67e-11; \newline force = (G{\emph{myMass }} p.getMass()) / \seqsplit{Math.pow(p.calcDistance(this)}, 2.0); \newline return force; \newline \} \newline \newline /}} \newline {\emph{ Calculates the X component of the force \newline }}/ \newline public double calcForceExertedByX(Body p) \{ \newline double dx; \newline double Fx; \newline dx = myXPos - p.getX(); \newline Fx = \seqsplit{p.calcForceExertedBy(this)} {\emph{ \seqsplit{(dx/(p.calcDistance(this)));} \newline return -Fx; \newline \} \newline \newline }} calculates the Y component of the net force \newline \newline public double calcForceExertedByY(Body p) \{ \newline /{\emph{ same as the X just different variables \newline \} \newline \newline /{\bf{ \newline }} calculates the net force in the x direction exerted on a body \newline {\emph{/ \newline public double \seqsplit{calcNetForceExertedByX(Body} {[}{]} bodies) \{ \newline double sum = 0; \newline for (Body b : bodies) \{ \newline if (!b.equals(this)) \{ \newline sum += b.calcForceExertedByX(this);\}\} \newline return -sum;\} \newline \newline /}} \newline }} calculates the net force in the y direction exerted on a body \newline {\emph{/ \newline public double \seqsplit{calcNetForceExertedByY(Body} {[}{]} bodies) \{ \newline double sum = 0; \newline for(Body b : bodies) \{ \newline if (!b.equals(this)) \{ \newline sum += \seqsplit{b.calcForceExertedByY(this);} \newline \} \newline \} \newline return -sum;\} \newline \newline /{\bf{ \newline }} updates the velocity, position, and time variables \newline {\emph{/ \newline public void update(double deltaT, double xforce, double yforce) \{ \newline double ax; \newline double ay; \newline \newline ax = xforce / this.getMass(); \newline ay = yforce / this.getMass(); \newline \newline myXVel = myXVel + deltaT}}ax; \newline myYVel = myYVel + deltaT{\emph{ay; \newline \newline myXPos = myXPos + deltaT}}myXVel; \newline myYPos = myYPos + deltaT{\emph{myYVel; \newline \newline \} \newline /}} \newline }} shows a non-moving image for each body in the simulation \newline */ \newline public void draw() \{ \newline StdDraw.picture(myXPos, myYPos, "images/"+myFileName); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Anonymous}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class Anonymous \{ \newline public int howMany(String{[}{]} headlines, String{[}{]} messages) \{ \newline \newline // counts{[}ch{]} is \# occurrences of ch in headlines \newline int counts{[}{]} = new int{[}256{]}; \newline for(String s : headlines) \{ \newline for(char ch : \seqsplit{s.toLowerCase().toCharArray())} \{ \newline if (ch == ' ') continue; \newline counts{[}ch{]} = counts{[}ch{]} + 1; \newline \} \newline \} \newline \newline int total = 0; \newline for(String s : messages) \{ \newline int{[}{]} mess = oneCount(s); \newline if (enoughLetters(mess,counts)) \{ \newline total += 1; \newline \} \newline \} \newline return total; \newline \} \newline \newline private boolean enoughLetters(int{[}{]} mess, int{[}{]} allLetters) \{ \newline boolean canCreate = true; \newline for(char ch='a'; ch \textless{}= 'z'; ch += 1) \{ \newline // do we have enough letters to create message? \newline if (mess{[}ch{]} \textgreater{} allLetters{[}ch{]}) \{ \newline return false; \newline \} \newline \} \newline return true; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{NBody}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class NBody \{ \newline \newline /{\bf{ \newline {\emph{ Read the specified file and return the radius \newline }} @param fname is name of file that can be open \newline {\emph{ @return the radius stored in the file \newline }} @throws FileNotFoundException if fname cannot be open \newline {\emph{/ \newline public static double readRadius(String fname) throws FileNotFoundException \{ \newline Scanner s = new Scanner(new File(fname)); \newline double radius; \newline radius = s.nextInt(); \newline radius = s.nextDouble(); \newline \newline s.close(); \newline return radius; \newline \} \newline \newline /}} \newline }} Read all data in file, return array of Celestial Bodies \newline {\emph{ read by creating an array of Body objects from data read. \newline }} @param fname is name of file that can be open \newline {\emph{ @return array of Body objects read \newline }} @throws FileNotFoundException if fname cannot be open \newline */ \newline public static Body{[}{]} readBodies(String fname) throws FileNotFoundException \{ \newline \newline Scanner s = new Scanner(new File(fname)); \newline \newline // TODO: read \# bodies, create array, ignore radius \newline int nb = 0; // \# bodies to be read \newline nb = s.nextInt(); \newline s.nextDouble(); \newline Body {[}{]} bodiesArray = new Body {[}nb{]}; \newline \newline for(int k=0; k \textless{} nb; k++) \{ \newline double xPos; \newline double yPos; \newline double xVel; \newline double yVel; \newline double mass; \newline String fileName; \newline \newline xPos = s.nextDouble(); \newline yPos = s.nextDouble(); \newline xVel = s.nextDouble(); \newline yVel = s.nextDouble(); \newline mass = s.nextDouble(); \newline fileName = s.next(); \newline \newline bodiesArray{[}k{]} = new Body(xPos, yPos, xVel, yVel, mass, fileName); \newline \newline \} \newline \newline s.close(); \newline \newline return bodiesArray; \newline \} \newline \newline public static void main(String{[}{]} args) throws FileNotFoundException\{ \newline double totalTime = 157788000.0; \newline double dt = 25000.0; \newline \newline String fname= "./data/planets.txt"; \newline if (args.length \textgreater{} 2) \{ \newline totalTime = Double.parseDouble(args{[}0{]}); \newline dt = Double.parseDouble(args{[}1{]}); \newline fname = args{[}2{]}; \newline \} \newline \newline Body{[}{]} bodies = readBodies(fname); \newline double radius = readRadius(fname); \newline \newline StdDraw.setScale(-radius, radius); \newline StdDraw.picture(0,0,"images/starfield.jpg"); \newline \newline for(double t = 0.0; t \textless{} totalTime; t += dt) \{ \newline \newline // TODO: create double arrays xforces and yforces \newline // to hold forces on each body \newline double xForces{[}{]} = new double {[}bodies.length{]}; \newline double yForces{[}{]} = new double {[}bodies.length{]}; \newline \newline // TODO: loop over all bodies, calculate \newline // net forces and store in xforces and yforces \newline for (int k = 0; k \textless{} bodies.length; k++) \{ \newline xForces{[}k{]} = bodies{[}k{]}.calcNetForceExertedByX(bodies); \newline yForces{[}k{]} = bodies{[}k{]}.calcNetForceExertedByY(bodies); \newline \newline \} \newline \newline // TODO: loop over all bodies and call update \newline // with dt and corresponding xforces, yforces values \newline for(int k = 0; k \textless{} bodies.length; k++) \{ \newline bodies{[}k{]}.update(dt, xForces{[}k{]}, yForces{[}k{]}); \newline \} \newline \newline StdDraw.picture(0,0,"images/starfield.jpg"); \newline \newline // TODO: loop over all bodies and call draw on each one \newline for (int k = 0; k \textless{} bodies.length; k++) \{ \newline bodies{[}k{]}.draw(); \newline \} \newline \newline StdDraw.show(10); \newline \} \newline \newline // prints final values after simulation \newline \newline System.out.printf("\%d\textbackslash{}n", bodies.length); \newline System.out.printf("\%.2e\textbackslash{}n", radius); \newline for (int i = 0; i \textless{} bodies.length; i++) \{ \newline \seqsplit{System.out.printf("\%11.4e} \%11.4e \%11.4e \%11.4e \%11.4e \%12s\textbackslash{}n", \newline bodies{[}i{]}.getX(), bodies{[}i{]}.getY(), \newline bodies{[}i{]}.getXVel(), bodies{[}i{]}.getYVel(), \newline bodies{[}i{]}.getMass(), bodies{[}i{]}.getName()); \newline \} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{MemberCheck}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public class MemberCheck \{ \newline public String{[}{]} whosDishonest(String{[}{]} club1, \newline String{[}{]} club2, \newline String{[}{]} club3) \{ \newline \newline Set\textless{}String\textgreater{} result = new HashSet\textless{}\textgreater{}(); //making these a set ensures that there's no duplicates \newline Set\textless{}String\textgreater{} s1 = new HashSet\textless{}\textgreater{}(Arrays.asList(club1)); \newline Set\textless{}String\textgreater{} s2 = new HashSet\textless{}\textgreater{}(Arrays.asList(club2)); \newline Set\textless{}String\textgreater{} s3 = new HashSet\textless{}\textgreater{}(Arrays.asList(club3)); \newline result.addAll(crossover(s1, s2)); \newline result.addAll(crossover(s1, s3)); \newline result.addAll(crossover(s2, s3)); \newline \newline String{[}{]} finalList = result.toArray(new String{[}0{]}); \newline Arrays.sort(finalList); \newline return finalList; \newline \} \newline \newline private Set crossover(Set club1, Set club2) \{ \newline Set\textless{}String\textgreater{} cloned = new HashSet\textless{}\textgreater{}(); \newline cloned.addAll(club1); \newline cloned.retainAll(club2); \newline return cloned; \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Queue}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{add(Element} e) & inserts the specified element into the queue \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} remove() & calls and removes the head of the queue \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PriorityQueue}} \tn % Row 0 \SetRowColor{LightBackground} Note*: & Head of the queue is the least element \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} add(Element e) & inserts specified element into priority queue \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{contains(Element} e) & returns true if PriorityQueue contains specified element \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{remove(Object} o) & removes single instance of the object \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} size() & returns number of elements in the PriorityQueue \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} peek() & retrieves but doesn't remove the head \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} poll() & retrieves and removes the head \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.56 cm} x{3.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Collections}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Collections.sort(ArrayList)} & sorts lowest to highest \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Collections.reverse(ArrayList)} & reverses the order \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arrays}} \tn % Row 0 \SetRowColor{LightBackground} Arrays.sort(int{[}{]} OR String{[}{]}) & sorts it from smallest to largest or alphabetically first to last \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Random Commands}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Integer.parseInt(String} s) & converts string to int \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{.split(" ")} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} .substring(start index, end index) & Includes start index, not end index \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Scanner}} \tn % Row 0 \SetRowColor{LightBackground} close() & closes the scanner \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} hasNext() & returns true if has another token \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{hasNextDouble()} & if it has another double, there are other - same for float, int, line, long \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} next() & returns the next token \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{nextDouble()} & returns the next double token - works for float, int, line, long \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} reset() & resets the scanner \tn % Row Count 11 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}