Inf1 OP : Sample Solutions for Lab Exercises
Sample Solutions

The following are sample solutions for all of the lab exercises.

Warning

You will find it much more useful to check these sample solutions after you have created your own working solution. Looking at the answers before figuring it out for yourself will greatly decrease your opportunity to learn.

Fundamentals
Lab Question Description Sample solution files
Week 1 Q1 Hello World HelloWorld.java
Q2 Personal Greeting PersonalGreeting.java
Q3 Adder Adder.java
Q4 Multiplier Multiplier.java
Week 2 Q1 Integer Distance Distance1.java
Distance2.java
Q2 Largest Double LargestDouble.java
Q3 Evaluating Boolean Values BooleanExpr.java
Q4 Face-Printing FacePrinter.java
Q5 Quadratic Equations QuadraticSolver.java
Q6 Polar Coordinates PolarCoordinates.java
Q7 Safer Fixed Divider FixedDivider.java
SaferDivider.java
Q8 Safer Quadratic Solver SaferQuadraticSolver.java
Q9 Squares Loop SquaresLoop.java
SquaresLoopRange.java
MultiplesLoopRange.java
Q10 Lopsided Number Triangle LopsidedNumberTriangle.java
Q11 Gambler's Ruin Gambler.java
Q12 Quadratic Solver With Imaginary Parts ImQuadraticSolver.java
Week 3 Q1 Floating point division FloatDiv.java
Q2 While loop example - arithmetic series ArithmeticSeries.java
Q3 ArrayRotate ArrayRotate.java
Q4 Mean and Variance MeanVariance.java
Q5 Median Temperature TempMedian.java
Q6 Mode Mode.java
Q7 Sieve of Eratosthenes Sieve.java
Week 4 Q1 Array Front ArrayFront9.java
Q2 Date Fashion DateFashion.java
Q3 No Triples NoTriples.java
Q4 Has 271 Has271.java
Q5 IsTriangular IsTriangular.java
Q6 NMax NMax.java
Q7 CoordinateConverter CoordinateConverter.java
Q8 ArrayOps ArrayOps.java
Q9 Factorial Recursion Factorial.java
Week 5 Q1 N-by-N Matrix NbyN.java
Q2 Nesting Nightmare PrintEvenNumbers.java
Q3 Path Names AbsolutePath.java
SplitPathName.java
Q4 Voronoi Diagram Point2D.java
Voronoi.java
Q5 One Time Pad OneTimePadEncipher.java
OneTimePadDecipher.java
Week 6 Q1 Daleks Dalek1.java
Dalek2.java
Q2 Arrays and Reference Types MusicTrack.java
Favourites.java
Q3 Make your Own CreditCard CreditCard.java
Q4 DNA Strand DNAStrand.java
DNAStrandTester.java
Q5 Vector3D Vector3D.java
Q6 Image Editor ImageEditor1.java
ImageEditor2.java
Week 7 Q1 Daleks Again Dalek3.java
Q2 Arrays and Reference Types music/MusicTrack.java
music/Favourites.java
Q3 Reading in files TestIn.java
Q4 Interval Interval.java
Q5 Shapes Point2DDouble.java
Circle.java
Rectangle.java
Q6 Text Analysis Tokenizer.java
WordCounter.java
Q7 Noughts-And-Crosses NoughtsAndCrosses.java
Week 8 Q1 Video Store Video.java
VideoStore.java
Q2 Binary Wffs and Inheritance PropVar.java
Operator.java
AndWff.java
BinaryWff.java
IfWff.java
Q3 Propositional Logic logic/AndWff.java
logic/BinaryWff.java
logic/IfWff.java
logic/NotWff.java
logic/Operator.java
logic/OrWff.java
logic/PropLogicLauncher.java
logic/PropVar.java
logic/Valuation.java
logic/Wff.java