├── .gitignore └── mooc-java-programming-i ├── part01-Part01_01.Sandbox ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Sandbox.java │ └── test │ └── java │ └── SandboxTest.java ├── part01-Part01_02.AdaLovelace ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AdaLovelace.java │ └── test │ └── java │ └── AdaLovelaceTest.java ├── part01-Part01_03.OnceUponATime ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── OnceUponATime.java │ └── test │ └── java │ └── OnceUponATimeTest.java ├── part01-Part01_04.Dinosaur ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Dinosaur.java │ └── test │ └── java │ └── DinosaurTest.java ├── part01-Part01_05.Message ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Message.java │ └── test │ └── java │ └── MessageTest.java ├── part01-Part01_06.HiAdaLovelace ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── HiAdaLovelace.java │ └── test │ └── java │ └── HiAdaLovelaceTest.java ├── part01-Part01_07.MessageThreeTimes ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── MessageThreeTimes.java │ └── test │ └── java │ └── MessageThreeTimesTest.java ├── part01-Part01_08.Greeting ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Greeting.java │ └── test │ └── java │ └── GreetingTest.java ├── part01-Part01_09.Conversation ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Conversation.java │ └── test │ └── java │ └── ConversationTest.java ├── part01-Part01_10.Story ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Story.java │ └── test │ └── java │ └── StoryTest.java ├── part01-Part01_11.VariousVariables ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── VariousVariables.java │ └── test │ └── java │ └── VariousVariablesTest.java ├── part01-Part01_12.IntegerInput ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IntegerInput.java │ └── test │ └── java │ └── IntegerInputTest.java ├── part01-Part01_13.DoubleInput ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── DoubleInput.java │ └── test │ └── java │ └── DoubleInputTest.java ├── part01-Part01_14.BooleanInput ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── BooleanInput.java │ └── test │ └── java │ └── BooleanInputTest.java ├── part01-Part01_15.DifferentTypesOfInput ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── DifferentTypesOfInput.java │ └── test │ └── java │ └── DifferentTypesOfInputTest.java ├── part01-Part01_16.SecondsInADay ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SecondsInADay.java │ └── test │ └── java │ └── SecondsInADayTest.java ├── part01-Part01_17.SumOfTwoNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfTwoNumbers.java │ └── test │ └── java │ └── SumOfTwoNumbersTest.java ├── part01-Part01_18.SumOfThreeNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfThreeNumbers.java │ └── test │ └── java │ └── SumOfThreeNumbersTest.java ├── part01-Part01_19.AdditionFormula ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AdditionFormula.java │ └── test │ └── java │ └── AdditionFormulaTest.java ├── part01-Part01_20.MultiplicationFormula ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── MultiplicationFormula.java │ └── test │ └── java │ └── MultiplicationFormulaTest.java ├── part01-Part01_21.AverageOfTwoNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AverageOfTwoNumbers.java │ └── test │ └── java │ └── AverageOfTwoNumbersTest.java ├── part01-Part01_22.AverageOfThreeNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AverageOfThreeNumbers.java │ └── test │ └── java │ └── AverageOfThreeNumbersTest.java ├── part01-Part01_23.SimpleCalculator ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SimpleCalculator.java │ └── test │ └── java │ └── SimpleCalculatorTest.java ├── part01-Part01_24.SpeedingTicket ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SpeedingTicket.java │ └── test │ └── java │ └── SpeedingTicketTest.java ├── part01-Part01_25.CheckYourIndentation ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── CheckYourIndentation.java │ └── test │ └── java │ └── CheckYourIndentationTest.java ├── part01-Part01_26.Orwell ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Orwell.java │ └── test │ └── java │ └── OrwellTest.java ├── part01-Part01_27.Ancient ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Ancient.java │ └── test │ └── java │ └── AncientTest.java ├── part01-Part01_28.Positivity ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Positivity.java │ └── test │ └── java │ └── PositivityTest.java ├── part01-Part01_29.Adulthood ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Adulthood.java │ └── test │ └── java │ └── AdulthoodTest.java ├── part01-Part01_30.LargerThanOrEqualTo ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LargerThanOrEqualTo.java │ └── test │ └── java │ └── LargerThanOrEqualToTest.java ├── part01-Part01_31.GradesAndPoints ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── GradesAndPoints.java │ └── test │ └── java │ └── GradesAndPointsTest.java ├── part01-Part01_32.OddOrEven ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── OddOrEven.java │ └── test │ └── java │ └── OddOrEvenTest.java ├── part01-Part01_33.Password ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Password.java │ └── test │ └── java │ └── PasswordTest.java ├── part01-Part01_34.Same ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Same.java │ └── test │ └── java │ └── SameTest.java ├── part01-Part01_35.CheckingTheAge ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── CheckingTheAge.java │ └── test │ └── java │ └── CheckingTheAgeTest.java ├── part01-Part01_36.LeapYear ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LeapYear.java │ └── test │ └── java │ └── LeapYearTest.java ├── part01-Part01_37.GiftTax ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── GiftTax.java │ └── test │ └── java │ └── GiftTaxTest.java ├── part02-Part02_01.Squared ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Squared.java │ └── test │ └── java │ └── SquaredTest.java ├── part02-Part02_02.SquareRootOfSum ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SquareRootOfSum.java │ └── test │ └── java │ └── SquareRootOfSumTest.java ├── part02-Part02_03.AbsoluteValue ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AbsoluteValue.java │ └── test │ └── java │ └── AbsoluteValueTest.java ├── part02-Part02_04.ComparingNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── ComparingNumbers.java │ └── test │ └── java │ └── ComparingNumbersTest.java ├── part02-Part02_05.CarryOn ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── CarryOn.java │ └── test │ └── java │ └── CarryOnTest.java ├── part02-Part02_06.AreWeThereYet ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AreWeThereYet.java │ └── test │ └── java │ └── AreWeThereYetTest.java ├── part02-Part02_07.OnlyPositives ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── OnlyPositives.java │ └── test │ └── java │ └── OnlyPositivesTest.java ├── part02-Part02_08.NumberOfNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumberOfNumbers.java │ └── test │ └── java │ └── NumberOfNumbersTest.java ├── part02-Part02_09.NumberOfNegativeNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumberOfNegativeNumbers.java │ └── test │ └── java │ └── NumberOfNegativeNumbersTest.java ├── part02-Part02_10.SumOfNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfNumbers.java │ └── test │ └── java │ └── SumOfNumbersTest.java ├── part02-Part02_11.NumberAndSumOfNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumberAndSumOfNumbers.java │ └── test │ └── java │ └── NumberAndSumOfNumbersTest.java ├── part02-Part02_12.AverageOfNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AverageOfNumbers.java │ └── test │ └── java │ └── AverageOfNumbersTest.java ├── part02-Part02_13.AverageOfPositiveNumbers ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AverageOfPositiveNumbers.java │ └── test │ └── java │ └── AverageOfPositiveNumbersTest.java ├── part02-Part02_14.Counting ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Counting.java │ └── test │ └── java │ └── CountingTest.java ├── part02-Part02_15.CountingToHundred ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── CountingToHundred.java │ └── test │ └── java │ └── CountingToHundredTest.java ├── part02-Part02_16.FromWhereToWhere ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── FromWhereToWhere.java │ └── test │ └── java │ ├── WhereFromTest.java │ └── WhereToTest.java ├── part02-Part02_17.SumOfASequence ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfASequence.java │ └── test │ └── java │ └── SumOfASequenceTest.java ├── part02-Part02_18.SumOfASequenceTheSequel ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfASequenceTheSequel.java │ └── test │ └── java │ └── SumOfASequenceTheSequelTest.java ├── part02-Part02_19.Factorial ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Factorial.java │ └── test │ └── java │ └── FactorialTest.java ├── part02-Part02_20.RepeatingBreakingAndRemembering ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── RepeatingBreakingAndRemembering.java │ └── test │ └── java │ ├── Osa2Test.java │ ├── Part1Test.java │ ├── Part3Test.java │ ├── Part4Test.java │ ├── Part5Test.java │ └── Part5bTest.java ├── part02-Part02_21.InAHoleInTheGround ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── InAHoleInTheGround.java │ └── test │ └── java │ └── InAHoleInTheGroundTest.java ├── part02-Part02_22.Reprint ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Reprint.java │ └── test │ └── java │ └── ReprintTest.java ├── part02-Part02_23.FromOneToParameter ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── FromOneToParameter.java │ └── test │ └── java │ └── FromOneToParameterTest.java ├── part02-Part02_24.FromParameterToOne ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── FromParameterToOne.java │ └── test │ └── java │ └── FromParameterToOneTest.java ├── part02-Part02_25.Division ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Division.java │ └── test │ └── java │ └── DivisionTest.java ├── part02-Part02_26.DivisibleByThree ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── DivisibleByThree.java │ └── test │ └── java │ └── DivisibleByThreeTest.java ├── part02-Part02_27.NumberUno ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumberUno.java │ └── test │ └── java │ └── NumberUnoTest.java ├── part02-Part02_28.Word ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Word.java │ └── test │ └── java │ └── WordTest.java ├── part02-Part02_29.Summation ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Summation.java │ └── test │ └── java │ └── SummationTest.java ├── part02-Part02_30.Smallest ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Smallest.java │ └── test │ └── java │ └── SmallestTest.java ├── part02-Part02_31.Greatest ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Greatest.java │ └── test │ └── java │ └── GreatestTest.java ├── part02-Part02_32.Averaging ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Averaging.java │ └── test │ └── java │ └── AveragingTest.java ├── part02-Part02_33.StarSign ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── StarSign.java │ └── test │ └── java │ └── StarSignTest.java ├── part02-Part02_34.AdvancedAstrology ├── .checkstyle.xml ├── .tmcproject.json ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AdvancedAstrology.java │ └── test │ └── java │ └── AdvancedAstrologyTest.java ├── part03-Part03_01.ThirdElement ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── ThirdElement.java │ └── test │ └── java │ └── ThirdElementTest.java ├── part03-Part03_02.SecondPlusThird ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SecondPlusThird.java │ └── test │ └── java │ └── SecondPlusThirdTest.java ├── part03-Part03_03.IndexOutOfBoundsException ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IoobProgram.java │ └── test │ └── java │ └── IoobProgramTest.java ├── part03-Part03_04.ListSize ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── ListSize.java │ └── test │ └── java │ └── ListSizeTest.java ├── part03-Part03_05.LastInList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LastInList.java │ └── test │ └── java │ └── LastInListTest.java ├── part03-Part03_06.FirstAndLast ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── FirstAndLast.java │ └── test │ └── java │ └── FirstAndLastTest.java ├── part03-Part03_07.RememberTheseNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── RememberTheseNumbers.java │ └── test │ └── java │ └── RememberTheseNumbersTest.java ├── part03-Part03_08.OnlyTheseNumbers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── OnlyTheseNumbers.java │ └── test │ └── java │ └── OnlyTheseNumbersTest.java ├── part03-Part03_09.GreatestInList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── GreatestInList.java │ └── test │ └── java │ └── GreatestInListTest.java ├── part03-Part03_10.IndexOf ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IndexOf.java │ └── test │ └── java │ └── IndexOfTest.java ├── part03-Part03_11.IndexOfSmallest ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IndexOfSmallest.java │ └── test │ └── java │ └── IndexOfSmallestTest.java ├── part03-Part03_12.SumOfAList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfAList.java │ └── test │ └── java │ └── SumOfAListTest.java ├── part03-Part03_13.AverageOfAList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AverageOfAList.java │ └── test │ └── java │ └── AverageOfAListTest.java ├── part03-Part03_14.OnTheList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── OnTheList.java │ └── test │ └── java │ └── OnTheListTest.java ├── part03-Part03_15.PrintInRange ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── PrintInRange.java │ └── test │ └── java │ └── PrintInRangeTest.java ├── part03-Part03_16.Sum ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Sum.java │ └── test │ └── java │ └── SumTest.java ├── part03-Part03_17.RemoveLast ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── RemoveLast.java │ └── test │ └── java │ └── RemoveLastTest.java ├── part03-Part03_18.Swap ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Swap.java │ └── test │ └── java │ └── SwapTest.java ├── part03-Part03_19.IndexWasNotFound ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IndexWasNotFound.java │ └── test │ └── java │ └── IndexWasNotFoundTest.java ├── part03-Part03_20.SumOfArray ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── SumOfArray.java │ └── test │ └── java │ └── SumOfArrayTest.java ├── part03-Part03_21.PrintNeatly ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── ArrayPrinter.java │ └── test │ └── java │ └── ArrayPrinterTest.java ├── part03-Part03_22.PrintInStars ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Printer.java │ └── test │ └── java │ └── PrinterTest.java ├── part03-Part03_23.PrintThrice ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── PrintThrice.java │ └── test │ └── java │ └── PrintThriceTest.java ├── part03-Part03_24.IsItTrue ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── IsItTrue.java │ └── test │ └── java │ └── IsItTrueTest.java ├── part03-Part03_25.Login ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Login.java │ └── test │ └── java │ └── LoginTest.java ├── part03-Part03_26.LineByLine ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LineByLine.java │ └── test │ └── java │ └── LineByLineTest.java ├── part03-Part03_27.AVClub ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AVClub.java │ └── test │ └── java │ └── AVClubTest.java ├── part03-Part03_28.FirstWords ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── FirstWords.java │ └── test │ └── java │ └── FirstWordsTest.java ├── part03-Part03_29.LastWords ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LastWords.java │ └── test │ └── java │ └── LastWordsTest.java ├── part03-Part03_30.AgeOfTheOldest ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── AgeOfTheOldest.java │ └── test │ └── java │ └── AgeOfTheOldestTest.java ├── part03-Part03_31.NameOfTheOldest ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NameOfTheOldest.java │ └── test │ └── java │ └── NameOfTheOldestTest.java ├── part03-Part03_32.PersonalDetails ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── PersonalDetails.java │ └── test │ └── java │ └── HenkilotietojenTarkasteluTest.java ├── part04-Part04_01.YourFirstAccount ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Account.java │ │ └── YourFirstAccount.java │ └── test │ └── java │ ├── MockInOut.java │ └── YourFirstAccountTest.java ├── part04-Part04_02.YourFirstBankTransfer ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Account.java │ │ └── YourFirstBankTransfer.java │ └── test │ └── java │ ├── MockInOut.java │ └── YourFirstBankTransferTest.java ├── part04-Part04_03.DogAttributes ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Dog.java │ │ └── DogAttributes.java │ └── test │ └── java │ └── DogTest.java ├── part04-Part04_04.Room ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ └── Room.java │ └── test │ └── java │ └── RoomTest.java ├── part04-Part04_05.Whistle ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Whistle.java │ └── test │ └── java │ └── WhistleTest.java ├── part04-Part04_06.Door ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Door.java │ │ └── Main.java │ └── test │ └── java │ └── DoorTest.java ├── part04-Part04_07.Product ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Product.java │ └── test │ └── java │ └── ProductTest.java ├── part04-Part04_08.DecreasingCounter ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── DecreasingCounter.java │ │ └── MainProgram.java │ └── test │ └── java │ └── DecreasingCounterTest.java ├── part04-Part04_09.Debt ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Debt.java │ │ └── Main.java │ └── test │ └── java │ └── DebtTest.java ├── part04-Part04_10.Song ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Song.java │ └── test │ └── java │ └── SongTest.java ├── part04-Part04_11.Film ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Film.java │ │ └── Main.java │ └── test │ └── java │ └── FilmTest.java ├── part04-Part04_12.Gauge ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Gauge.java │ │ └── Main.java │ └── test │ └── java │ └── GaugeTest.java ├── part04-Part04_13.Agent ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Agent.java │ └── test │ └── java │ └── AgentTest.java ├── part04-Part04_14.Multiplier ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Multiplier.java │ └── test │ └── java │ └── MultiplierTest.java ├── part04-Part04_15.NumberStatistics ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ └── Statistics.java │ └── test │ └── java │ ├── StatisticsATest.java │ └── StatisticsBTest.java ├── part04-Part04_16.PaymentCard ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ └── PaymentCard.java │ └── test │ └── java │ └── PaymentCardTest.java ├── part04-Part04_17.Items ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Item.java │ │ └── Items.java │ └── test │ └── java │ └── ItemsTest.java ├── part04-Part04_18.PersonalInformation ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── PersonalInformation.java │ │ └── PersonalInformationCollection.java │ └── test │ └── java │ └── PersonalInformationCollectionTest.java ├── part04-Part04_19.TelevisionPrograms ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── TelevisionProgram.java │ └── test │ └── java │ └── TelevisionProgramTest.java ├── part04-Part04_20.Books ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Book.java │ │ └── Main.java │ └── test │ └── java │ └── BooksTest.java ├── part04-Part04_21.NumberOfStrings ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumberOfStrings.java │ └── test │ └── java │ └── NumberOfStringsTest.java ├── part04-Part04_22.Cubes ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Cubes.java │ └── test │ └── java │ └── CubestTest.java ├── part04-Part04_23.CreatingANewFile ├── .tmcproject.yml ├── file.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── Program.java │ └── test │ └── java │ └── CreatingANewFileTest.java ├── part04-Part04_24.PrintingAFile ├── .tmcproject.yml ├── data.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── PrintingAFile.java │ └── test │ └── java │ └── PrintingAFileTest.java ├── part04-Part04_25.PrintingASpecifiedFile ├── .tmcproject.yml ├── data.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── PrintingASpecifiedFile.java │ └── test │ └── java │ └── PrintingASpecifiedFileTest.java ├── part04-Part04_26.GuestListFromAFile ├── .tmcproject.yml ├── names.txt ├── other-names.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── GuestListFromAFile.java │ └── test │ └── java │ └── GuestListFromAFileTest.java ├── part04-Part04_27.IsItInTheFile ├── .tmcproject.yml ├── names.txt ├── other-names.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── IsItInTheFile.java │ └── test │ └── java │ └── IsItInTheFileTest.java ├── part04-Part04_28.NumbersFromAFile ├── .tmcproject.yml ├── numbers-1.txt ├── numbers-2.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── NumbersFromAFile.java │ └── test │ └── java │ └── NumbersFromAFileTest.java ├── part04-Part04_29.RecordsFromAFile ├── .tmcproject.yml ├── data.txt ├── pom.xml └── src │ ├── main │ └── java │ │ └── RecordsFromAFile.java │ └── test │ └── java │ └── RecordsFromAFileTest.java ├── part04-Part04_30.StoringRecords ├── .tmcproject.yml ├── data.txt ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ ├── Person.java │ │ │ └── StoringRecords.java │ └── test │ │ └── java │ │ └── StoringRecordsTest.java ├── tiedosto1.txt └── tiedosto2.txt ├── part04-Part04_31.SportStatistics ├── .tmcproject.yml ├── data.csv ├── pom.xml └── src │ ├── main │ └── java │ │ ├── SportStatistics.java │ │ └── Team.java │ └── test │ └── java │ └── SportStatisticTest.java ├── part05-Part05_01.OneMinute ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── ClockHand.java │ │ ├── Program.java │ │ └── Timer.java │ └── test │ └── java │ └── TimerTest.java ├── part05-Part05_02.Book ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Book.java │ │ └── Program.java │ └── test │ └── java │ └── BookTest.java ├── part05-Part05_03.Cube ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Cube.java │ │ └── Program.java │ └── test │ └── java │ └── CubeTest.java ├── part05-Part05_04.FitByte ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Fitbyte.java │ │ └── Program.java │ └── test │ └── java │ └── FitbyteTest.java ├── part05-Part05_05.ConstructorOverload ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ └── Product.java │ └── test │ └── java │ └── ConstructorOverloadTest.java ├── part05-Part05_06.OverloadedCounter ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Counter.java │ │ └── MainProgram.java │ └── test │ └── java │ ├── ConstructorSignature.java │ ├── CounterTest.java │ ├── MethodSignature.java │ └── Utils.java ├── part05-Part05_07.NullPointerException ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── NullPointerExceptionProgram.java │ └── test │ └── java │ └── NPEErrorTest.java ├── part05-Part05_08.BiggestPetShop ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ ├── Person.java │ │ └── Pet.java │ └── test │ └── java │ └── TheBiggestPetShopTest.java ├── part05-Part05_09.HealthStation ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── HealthStation.java │ │ ├── Main.java │ │ └── Person.java │ └── test │ └── java │ └── HealthStationTest.java ├── part05-Part05_10.CardPayments ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── PaymentCard.java │ │ └── PaymentTerminal.java │ └── test │ └── java │ └── CardPaymentsTest.java ├── part05-Part05_11.ComparingApartments ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Apartment.java │ │ └── Main.java │ └── test │ └── java │ └── ApartmentTest.java ├── part05-Part05_12.Song ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Song.java │ └── test │ └── java │ └── SongTest.java ├── part05-Part05_13.IdenticalTwins ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── Person.java │ │ └── SimpleDate.java │ └── test │ └── java │ └── IdenticalTwinsTest.java ├── part05-Part05_14.Books ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Book.java │ │ └── Main.java │ └── test │ └── java │ └── BooksTest.java ├── part05-Part05_15.Archive ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Archive.java │ │ └── Main.java │ └── test │ └── java │ └── ArchiveTest.java ├── part05-Part05_16.DatingApp ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── SimpleDate.java │ └── test │ └── java │ ├── A_DatingAppTest.java │ └── B_DatingAppTest.java ├── part05-Part05_17.Money ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── MainProgram.java │ │ └── Money.java │ └── test │ └── java │ └── MoneyTest.java ├── part06-Part06_01.Menu ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Menu.java │ └── test │ └── java │ └── MenuTest.java ├── part06-Part06_02.Stack ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── Stack.java │ └── test │ └── java │ └── StackTest.java ├── part06-Part06_03.MessagingService ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── Message.java │ │ └── MessagingService.java │ └── test │ └── java │ └── MessagingServiceTest.java ├── part06-Part06_04.PrintingACollection ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── SimpleCollection.java │ └── test │ └── java │ └── PrintingACollectionTest.java ├── part06-Part06_05.SantasWorkshop ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Gift.java │ │ ├── Main.java │ │ └── Package.java │ └── test │ └── java │ ├── A_GiftTest.java │ └── B_PackageTest.java ├── part06-Part06_06.LongestInCollection ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ └── SimpleCollection.java │ └── test │ └── java │ └── LongestInCollectionTest.java ├── part06-Part06_07.HeightOrder ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── Person.java │ │ └── Room.java │ └── test │ └── java │ └── HeightOrderTest.java ├── part06-Part06_08.CargoHold ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Hold.java │ │ ├── Item.java │ │ ├── Main.java │ │ └── Suitcase.java │ └── test │ └── java │ ├── A_ItemTest.java │ ├── B_SuitcaseTest.java │ └── C_HoldTest.java ├── part06-Part06_09.SimpleDictionary ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── SimpleDictionary.java │ │ └── TextUI.java │ └── test │ └── java │ └── TextUITest.java ├── part06-Part06_10.TodoList ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Main.java │ │ ├── TodoList.java │ │ └── UserInterface.java │ └── test │ └── java │ └── TodoListTest.java ├── part06-Part06_11.Averages ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── GradeRegister.java │ │ ├── Program.java │ │ └── UserInterface.java │ └── test │ └── java │ └── AveragesTest.java ├── part06-Part06_12.JokeManager ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── JokeManager.java │ │ ├── Program.java │ │ └── UserInterface.java │ └── test │ └── java │ └── JokeManagerTest.java ├── part06-Part06_13.Exercises ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Exercise.java │ │ ├── ExerciseManagement.java │ │ └── MainProgram.java │ └── test │ └── java │ └── ExerciseManagementTest.java ├── part07-Part07_01.LiquidContainers ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── LiquidContainers.java │ └── test │ └── java │ └── LiquidContainersTest.java ├── part07-Part07_02.LiquidContainers2 ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Container.java │ │ ├── LiquidContainers2.java │ │ └── UserInterface.java │ └── test │ └── java │ └── LiquidContainers2Test.java ├── part07-Part07_03.Sorting ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── MainProgram.java │ └── test │ └── java │ └── SortingTest.java ├── part07-Part07_04.ReadymadeSortingAlgorithms ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ └── Main.java │ └── test │ └── java │ └── ReadymadeSortingAlgorithmsTest.java ├── part07-Part07_05.Searching ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── Book.java │ │ └── Searching.java │ └── test │ └── java │ └── SearchingTest.java ├── part07-Part07_06.GradeStatistics ├── .tmcproject.yml ├── pom.xml └── src │ ├── main │ └── java │ │ ├── GradeRegister.java │ │ ├── Main.java │ │ └── UserInterface.java │ └── test │ └── java │ └── GradeStatisticsTest.java ├── part07-Part07_07.RecipeSearch ├── .tmcproject.yml ├── pom.xml ├── recipes.txt └── src │ ├── main │ └── java │ │ └── RecipeSearch.java │ └── test │ └── java │ └── RecipeSearchTest.java └── part07-Part07_08.BigYear ├── .tmcproject.yml ├── pom.xml └── src ├── main └── java │ └── mainProgram.java └── test └── java └── BirdDatabaseTest.java /mooc-java-programming-i/part01-Part01_01.Sandbox/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_01.Sandbox/src/main/java/Sandbox.java: -------------------------------------------------------------------------------- 1 | 2 | public class Sandbox { 3 | 4 | public static void main(String[] args) { 5 | // Write your program here 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_01.Sandbox/src/test/java/SandboxTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.MockStdio; 3 | import fi.helsinki.cs.tmc.edutestutils.Points; 4 | import org.junit.*; 5 | 6 | @Points("01-01") 7 | public class SandboxTest { 8 | 9 | @Rule 10 | public MockStdio io = new MockStdio(); 11 | 12 | @Test 13 | public void freePoints() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_02.AdaLovelace/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_02.AdaLovelace/src/main/java/AdaLovelace.java: -------------------------------------------------------------------------------- 1 | 2 | public class AdaLovelace { 3 | 4 | public static void main(String[] args) { 5 | // Write your program here 6 | System.out.println("Ada Lovelace"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_02.AdaLovelace/src/test/java/AdaLovelaceTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.MockStdio; 3 | import fi.helsinki.cs.tmc.edutestutils.Points; 4 | import org.junit.*; 5 | import static org.junit.Assert.assertEquals; 6 | 7 | @Points("01-02") 8 | public class AdaLovelaceTest { 9 | 10 | @Rule 11 | public MockStdio io = new MockStdio(); 12 | 13 | @Test 14 | public void outputIsCorrect() { 15 | AdaLovelace.main(new String[]{}); 16 | assertEquals("Ada Lovelace", io.getSysOut().trim()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_03.OnceUponATime/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_03.OnceUponATime/src/main/java/OnceUponATime.java: -------------------------------------------------------------------------------- 1 | 2 | public class OnceUponATime { 3 | 4 | public static void main(String[] args) { 5 | // Write your program here 6 | System.out.println("Once upon a time"); 7 | System.out.println("there was"); 8 | System.out.println("a program"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_04.Dinosaur/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_04.Dinosaur/src/main/java/Dinosaur.java: -------------------------------------------------------------------------------- 1 | 2 | public class Dinosaur { 3 | 4 | public static void main(String[] args) { 5 | // Write your program here 6 | System.out.println("Once upon a time"); 7 | System.out.println("there was"); 8 | System.out.println("a dinosaur"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_05.Message/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_05.Message/src/main/java/Message.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Message { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | System.out.println("Write a message:"); 10 | // Write your program here 11 | String message = scanner.nextLine(); 12 | 13 | System.out.println(message); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_06.HiAdaLovelace/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_06.HiAdaLovelace/src/main/java/HiAdaLovelace.java: -------------------------------------------------------------------------------- 1 | 2 | public class HiAdaLovelace { 3 | 4 | public static void main(String[] args) { 5 | String name = "Ada Lovelace"; 6 | System.out.println("Hi " + name + "!"); 7 | 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_07.MessageThreeTimes/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_07.MessageThreeTimes/src/main/java/MessageThreeTimes.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class MessageThreeTimes { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | System.out.println("Write a message:"); 10 | // Write your program here 11 | String oi = scanner.nextLine(); 12 | 13 | System.out.println(oi); 14 | System.out.println(oi); 15 | System.out.println(oi); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_08.Greeting/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_08.Greeting/src/main/java/Greeting.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Greeting { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("What's your name?"); 11 | String name = scanner.nextLine(); 12 | 13 | System.out.println("Hi " + name); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_09.Conversation/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_09.Conversation/src/main/java/Conversation.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Conversation { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Greetings! How are you doing?"); 11 | String first = scanner.nextLine(); 12 | //System.out.println(first); 13 | System.out.println("Oh, how interesting. Tell me more!"); 14 | String second = scanner.nextLine(); 15 | //System.out.println(second); 16 | System.out.println("Thanks for sharing!"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_10.Story/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_10.Story/src/main/java/Story.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Story { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("I will tell you a story, but I need some information first."); 11 | System.out.println("What is the main character called?"); 12 | String name = scanner.nextLine(); 13 | System.out.println("What is their job?"); 14 | String job = scanner.nextLine(); 15 | System.out.println("Here is the story:"); 16 | System.out.println("Once upon a time there was " + name + "," + " who was " + job + "."); 17 | System.out.println("On the way to work, " + name + " reflected on life."); 18 | System.out.println("Perhaps " + name + " will not be " + job + " forever."); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_11.VariousVariables/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_11.VariousVariables/src/main/java/VariousVariables.java: -------------------------------------------------------------------------------- 1 | 2 | public class VariousVariables { 3 | 4 | public static void main(String[] args) { 5 | // MODIFY THESE: 6 | 7 | int numberOfChicken = 9000; 8 | double baconWeight = 0.1; 9 | String tractor = "Zetor"; 10 | 11 | // DON'T MODIFY THESE: 12 | System.out.println("Chicken:"); 13 | System.out.println(numberOfChicken); 14 | System.out.println("Bacon (kg):"); 15 | System.out.println(baconWeight); 16 | System.out.println("Tractor:"); 17 | System.out.println(tractor); 18 | System.out.println(""); 19 | System.out.println("And finally, a summary:"); 20 | System.out.println(numberOfChicken); 21 | System.out.println(baconWeight); 22 | System.out.println(tractor); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_12.IntegerInput/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_12.IntegerInput/src/main/java/IntegerInput.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class IntegerInput { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // write your program here 10 | System.out.println("Give a number:"); 11 | int value = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("You gave the number " + value); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_13.DoubleInput/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_13.DoubleInput/src/main/java/DoubleInput.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class DoubleInput { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // write your program here 10 | System.out.println("Give a number:"); 11 | double myDouble = Double.valueOf(scanner.nextLine()); 12 | System.out.println("You gave the number " + myDouble); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_14.BooleanInput/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_14.BooleanInput/src/main/java/BooleanInput.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class BooleanInput { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // write your program here 10 | System.out.println("Write something:"); 11 | boolean something = Boolean.valueOf(scanner.nextLine()); 12 | System.out.println("True or false? " + something); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_15.DifferentTypesOfInput/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_15.DifferentTypesOfInput/src/main/java/DifferentTypesOfInput.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class DifferentTypesOfInput { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give a string:"); 11 | String myString = scan.nextLine(); 12 | System.out.println("Give an integer:"); 13 | int myInt = Integer.valueOf(scan.nextLine()); 14 | System.out.println("Give a double:"); 15 | double myDouble = Double.valueOf(scan.nextLine()); 16 | System.out.println("Give a boolean:"); 17 | boolean myBool = Boolean.valueOf(scan.nextLine()); 18 | 19 | System.out.println("You gave the string " + myString); 20 | System.out.println("You gave the integer " + myInt); 21 | System.out.println("You gave the double " + myDouble); 22 | System.out.println("You gave the boolean " + myBool); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_16.SecondsInADay/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_16.SecondsInADay/src/main/java/SecondsInADay.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SecondsInADay { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("How many days would you like to convert to seconds?"); 11 | int days = Integer.valueOf(scanner.nextLine()); 12 | int seconds = days * 24 * 60 * 60; 13 | System.out.println(seconds); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_17.SumOfTwoNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_17.SumOfTwoNumbers/src/main/java/SumOfTwoNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SumOfTwoNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int firstNumber = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int secondNumber = Integer.valueOf(scanner.nextLine()); 14 | System.out.println("The sum of the numbers is " + (firstNumber + secondNumber)); 15 | 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_18.SumOfThreeNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_18.SumOfThreeNumbers/src/main/java/SumOfThreeNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SumOfThreeNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int firstNumber = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int secondNumber = Integer.valueOf(scanner.nextLine()); 14 | System.out.println("Give the third number:"); 15 | int thirdNumber = Integer.valueOf(scanner.nextLine()); 16 | System.out.println("The sum of the numbers is " + (firstNumber + secondNumber + thirdNumber)); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_19.AdditionFormula/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_19.AdditionFormula/src/main/java/AdditionFormula.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AdditionFormula { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // write your program here 10 | System.out.println("Give the first number:"); 11 | int first = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int second = Integer.valueOf(scanner.nextLine()); 14 | int total = first + second; 15 | System.out.println(first + " + " + second + " = " + total); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_20.MultiplicationFormula/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_20.MultiplicationFormula/src/main/java/MultiplicationFormula.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class MultiplicationFormula { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int first = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int second = Integer.valueOf(scanner.nextLine()); 14 | int total = first * second; 15 | System.out.println(first + " * " + second + " = " + total); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_21.AverageOfTwoNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_21.AverageOfTwoNumbers/src/main/java/AverageOfTwoNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AverageOfTwoNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int first = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int second = Integer.valueOf(scanner.nextLine()); 14 | double average = 1.0 * (first + second) / 2; 15 | System.out.println("The average is " + average); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_22.AverageOfThreeNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_22.AverageOfThreeNumbers/src/main/java/AverageOfThreeNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AverageOfThreeNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int first = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int second = Integer.valueOf(scanner.nextLine()); 14 | System.out.println("Give the third number:"); 15 | int third = Integer.valueOf(scanner.nextLine()); 16 | double average = 1.0 * (first + second + third) / 3; 17 | System.out.println("The average is " + average); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_23.SimpleCalculator/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_23.SimpleCalculator/src/main/java/SimpleCalculator.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SimpleCalculator { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give the first number:"); 11 | int first = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Give the second number:"); 13 | int second = Integer.valueOf(scanner.nextLine()); 14 | 15 | System.out.println(first + " + " + second + " = " + (first + second)); 16 | System.out.println(first + " - " + second + " = " + (first - second)); 17 | System.out.println(first + " * " + second + " = " + (first * second)); 18 | System.out.println(first + " / " + second + " = " + (first / (second * 1.0))); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_24.SpeedingTicket/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_24.SpeedingTicket/src/main/java/SpeedingTicket.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SpeedingTicket { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here. 10 | System.out.println("Give speed:"); 11 | int speed = Integer.valueOf(scanner.nextLine()); 12 | 13 | if(speed > 120) { 14 | System.out.println("Speeding ticket!"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_25.CheckYourIndentation/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_25.CheckYourIndentation/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_25.CheckYourIndentation/src/main/java/CheckYourIndentation.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class CheckYourIndentation { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("Give a number: "); 10 | int first = Integer.valueOf(scan.nextLine()); 11 | System.out.println("Give another number: "); 12 | int second = Integer.valueOf(scan.nextLine()); 13 | if (first == second) { 14 | System.out.println("Same!"); 15 | } else if (first > second) { 16 | System.out.println("The first was larger than the second!"); 17 | } else { 18 | System.out.println("The second was larger than the first!"); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_25.CheckYourIndentation/src/test/java/CheckYourIndentationTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.MockStdio; 3 | import fi.helsinki.cs.tmc.edutestutils.Points; 4 | import org.junit.Rule; 5 | import org.junit.Test; 6 | 7 | @Points("01-25") 8 | public class CheckYourIndentationTest { 9 | 10 | @Rule 11 | public MockStdio io = new MockStdio(); 12 | 13 | @Test 14 | public void noTests() { 15 | // checks that the indentations are correct 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_26.Orwell/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_26.Orwell/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_26.Orwell/src/main/java/Orwell.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Orwell { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give a number:"); 11 | int number = Integer.valueOf(scan.nextLine()); 12 | 13 | if (number == 1984) { 14 | System.out.println("Orwell"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_27.Ancient/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_27.Ancient/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_27.Ancient/src/main/java/Ancient.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Ancient { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give a year:"); 11 | int year = Integer.valueOf(scan.nextLine()); 12 | 13 | if (year < 2015) { 14 | System.out.println("Ancient history!"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_28.Positivity/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_28.Positivity/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_28.Positivity/src/main/java/Positivity.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Positivity { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Give a number:"); 11 | int number = Integer.valueOf(scan.nextLine()); 12 | 13 | if (number > 0) { 14 | System.out.println("The number is positive."); 15 | } else { 16 | System.out.println("The number is not positive."); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_29.Adulthood/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_29.Adulthood/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_29.Adulthood/src/main/java/Adulthood.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Adulthood { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("How old are you?"); 11 | int age = Integer.valueOf(scan.nextLine()); 12 | 13 | if (age >= 18) { 14 | System.out.println("You are an adult"); 15 | } else { 16 | System.out.println("You are not an adult"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_30.LargerThanOrEqualTo/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_30.LargerThanOrEqualTo/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_30.LargerThanOrEqualTo/src/main/java/LargerThanOrEqualTo.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class LargerThanOrEqualTo { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("Give the first number:"); 10 | int first = Integer.valueOf(scan.nextLine()); 11 | System.out.println("Give the second number:"); 12 | int second = Integer.valueOf(scan.nextLine()); 13 | 14 | if (first > second) { 15 | System.out.println("Larger number is: " + first); 16 | } else if (second > first) { 17 | System.out.println("Larger number is: " + second); 18 | } else { 19 | System.out.println("The numbers are equal!"); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_31.GradesAndPoints/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_31.GradesAndPoints/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_31.GradesAndPoints/src/main/java/GradesAndPoints.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class GradesAndPoints { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("Give points [0 - 100]"); 10 | int points = Integer.valueOf(scan.nextLine()); 11 | 12 | if (points > 100) { 13 | System.out.println("Grade: Incredible!"); 14 | } else if (points >= 90) { 15 | System.out.println("Grade: 5"); 16 | } else if (points >= 80) { 17 | System.out.println("Grade: 4"); 18 | } else if (points >= 70) { 19 | System.out.println("Grade: 3"); 20 | } else if (points >= 60) { 21 | System.out.println("Grade: 2"); 22 | } else if (points >= 50) { 23 | System.out.println("Grade: 1"); 24 | } else if (points >= 0) { 25 | System.out.println("Grade: failed"); 26 | } else { 27 | System.out.println("Grade: Impossible!"); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_32.OddOrEven/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_32.OddOrEven/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_33.Password/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_33.Password/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_33.Password/src/main/java/Password.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Password { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Password?"); 11 | String password = scan.nextLine(); 12 | 13 | if (password.equals("Caput Draconis")) { 14 | System.out.println("Welcome!"); 15 | } else { 16 | System.out.println("Off with you!"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_34.Same/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_34.Same/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_34.Same/src/main/java/Same.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Same { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here. 10 | System.out.println("Enter first string:"); 11 | String first = scan.nextLine(); 12 | System.out.println("Enter second string:"); 13 | String second = scan.nextLine(); 14 | 15 | if (first.equals(second)) { 16 | System.out.println("Same"); 17 | } else { 18 | System.out.println("Different"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_35.CheckingTheAge/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_35.CheckingTheAge/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_35.CheckingTheAge/src/main/java/CheckingTheAge.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class CheckingTheAge { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("How old are you?"); 10 | int age = Integer.valueOf(scan.nextLine()); 11 | 12 | if (age >= 0 && age <= 120) { 13 | System.out.println("OK"); 14 | } else { 15 | System.out.println("Impossible!"); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_36.LeapYear/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_36.LeapYear/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_36.LeapYear/src/main/java/LeapYear.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class LeapYear { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("Give a year:"); 10 | int year = Integer.valueOf(scan.nextLine()); 11 | 12 | if (year % 4 != 0) { 13 | System.out.println("The year is not a leap year."); 14 | } else if (year % 100 == 0 && year % 400 == 0) { 15 | System.out.println("The year is a leap year"); 16 | } else if (year % 100 == 0 && year % 400 != 0) { 17 | System.out.println("The year is not a leap year."); 18 | } else { 19 | System.out.println("The year is a leap year."); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_37.GiftTax/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part01-Part01_37.GiftTax/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_01.Squared/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_01.Squared/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_01.Squared/src/main/java/Squared.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Squared { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int x = Integer.valueOf(scanner.nextLine()); 10 | 11 | int squared = x * x; 12 | 13 | System.out.println(squared); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_02.SquareRootOfSum/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_02.SquareRootOfSum/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_02.SquareRootOfSum/src/main/java/SquareRootOfSum.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SquareRootOfSum { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int x = Integer.valueOf(scanner.nextLine()); 10 | 11 | int y = Integer.valueOf(scanner.nextLine()); 12 | 13 | int sum = x + y; 14 | 15 | double squareRoot = Math.sqrt(sum); 16 | 17 | System.out.println(squareRoot); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_03.AbsoluteValue/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_03.AbsoluteValue/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_03.AbsoluteValue/src/main/java/AbsoluteValue.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AbsoluteValue { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int x = Integer.valueOf(scanner.nextLine()); 10 | 11 | if (x < 0) { 12 | System.out.println(x * -1); 13 | } else { 14 | System.out.println(x); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_04.ComparingNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_04.ComparingNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_04.ComparingNumbers/src/main/java/ComparingNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class ComparingNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int x = Integer.valueOf(scanner.nextLine()); 10 | int y = Integer.valueOf(scanner.nextLine()); 11 | 12 | if (x > y) { 13 | System.out.println(x + " is greater than " + y); 14 | } else if (x < y) { 15 | System.out.println(x + " is smaller than " + y); 16 | } else { 17 | System.out.println(x + " is equal to " + y); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_05.CarryOn/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_05.CarryOn/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_05.CarryOn/src/main/java/CarryOn.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class CarryOn { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | System.out.println("Carry on?"); 11 | String input = scanner.nextLine(); 12 | 13 | if (input.equals("no")) { 14 | break; 15 | } 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_06.AreWeThereYet/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_06.AreWeThereYet/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_06.AreWeThereYet/src/main/java/AreWeThereYet.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AreWeThereYet { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | System.out.println("Give a number:"); 11 | int number = Integer.valueOf(scanner.nextLine()); 12 | 13 | if (number == 4) { 14 | break; 15 | } 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_07.OnlyPositives/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_07.OnlyPositives/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_07.OnlyPositives/src/main/java/OnlyPositives.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class OnlyPositives { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | System.out.println("Give a number:"); 11 | int number = Integer.valueOf(scanner.nextLine()); 12 | 13 | if (number == 0) { 14 | break; 15 | } else if (number < 0) { 16 | System.out.println("Unsuitable number"); 17 | continue; 18 | } 19 | 20 | System.out.println(number * number); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_08.NumberOfNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_08.NumberOfNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_08.NumberOfNumbers/src/main/java/NumberOfNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NumberOfNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int inputs = 0; 10 | 11 | while (true) { 12 | System.out.println("Give a number:"); 13 | int number = Integer.valueOf(scanner.nextLine()); 14 | 15 | if (number == 0) { 16 | break; 17 | } 18 | 19 | if (number != 0) { 20 | inputs = inputs + 1; 21 | } 22 | } 23 | 24 | System.out.println("Number of numbers: " + inputs); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_09.NumberOfNegativeNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_09.NumberOfNegativeNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_09.NumberOfNegativeNumbers/src/main/java/NumberOfNegativeNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NumberOfNegativeNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int inputs = 0; 10 | 11 | while (true) { 12 | System.out.println("Give a number:"); 13 | int number = Integer.valueOf(scanner.nextLine()); 14 | 15 | if (number == 0) { 16 | break; 17 | } 18 | 19 | if (number < 0) { 20 | inputs = inputs + 1; 21 | } 22 | } 23 | 24 | System.out.println("Number of negative numbers: " + inputs); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_10.SumOfNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_10.SumOfNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_10.SumOfNumbers/src/main/java/SumOfNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SumOfNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int sum = 0; 10 | 11 | while (true) { 12 | System.out.println("Give a number:"); 13 | int number = Integer.valueOf(scanner.nextLine()); 14 | 15 | if (number == 0) { 16 | break; 17 | } 18 | 19 | if (number != 0) { 20 | sum = sum + number; 21 | } 22 | } 23 | 24 | System.out.println("Sum of the numbers: " + sum); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_11.NumberAndSumOfNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_11.NumberAndSumOfNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_11.NumberAndSumOfNumbers/src/main/java/NumberAndSumOfNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NumberAndSumOfNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int values = 0; 10 | int sum = 0; 11 | 12 | while (true) { 13 | System.out.println("Give a number:"); 14 | int number = Integer.valueOf(scanner.nextLine()); 15 | 16 | if (number == 0) { 17 | break; 18 | } 19 | 20 | if (number != 0) { 21 | values = values + 1; 22 | sum = sum + number; 23 | } 24 | } 25 | 26 | System.out.println("Number of numbers: " + values); 27 | System.out.println("Sum of the numbers: " + sum); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_12.AverageOfNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_12.AverageOfNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_12.AverageOfNumbers/src/main/java/AverageOfNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AverageOfNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int values = 0; 10 | int sum = 0; 11 | 12 | while (true) { 13 | System.out.println("Give a number:"); 14 | int number = Integer.valueOf(scanner.nextLine()); 15 | 16 | if (number == 0) { 17 | break; 18 | } 19 | 20 | if (number != 0) { 21 | values = values + 1; 22 | sum = sum + number; 23 | } 24 | } 25 | 26 | double average = (sum * 1.0) / values; 27 | System.out.println("Average of the numbers: " + average); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_13.AverageOfPositiveNumbers/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_13.AverageOfPositiveNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_13.AverageOfPositiveNumbers/src/main/java/AverageOfPositiveNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AverageOfPositiveNumbers { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int values = 0; 10 | int sum = 0; 11 | 12 | while (true) { 13 | System.out.println("Give a number:"); 14 | int number = Integer.valueOf(scanner.nextLine()); 15 | 16 | if (values == 0 && number <= 0) { 17 | System.out.println("Cannot calculate the average"); 18 | } 19 | 20 | if (number == 0) { 21 | break; 22 | } 23 | 24 | if (values >= 0 && number > 0) { 25 | values = values + 1; 26 | sum = sum + number; 27 | } 28 | } 29 | 30 | double average = (sum * 1.0) / values; 31 | System.out.println("Average of the numbers: " + average); 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_14.Counting/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_14.Counting/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_14.Counting/src/main/java/Counting.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Counting { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int num = Integer.valueOf(scanner.nextLine()); 10 | 11 | for (int i = 0; i <= num; i++) { 12 | System.out.println(i); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_15.CountingToHundred/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_15.CountingToHundred/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_15.CountingToHundred/src/main/java/CountingToHundred.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class CountingToHundred { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int num = Integer.valueOf(scanner.nextLine()); 10 | 11 | for (int i = num; i <= 100; i++) { 12 | System.out.println(i); 13 | } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_16.FromWhereToWhere/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_16.FromWhereToWhere/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_16.FromWhereToWhere/src/main/java/FromWhereToWhere.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class FromWhereToWhere { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.println("Where to?"); 11 | int num1 = Integer.valueOf(scanner.nextLine()); 12 | 13 | // for (int i = 1; i <= num1; i++) { 14 | // System.out.println(i); 15 | // } 16 | 17 | System.out.println("Where from?"); 18 | int num2 = Integer.valueOf(scanner.nextLine()); 19 | 20 | if (num2 <= num1) { 21 | for (int i = num2; i <= num1; i++) { 22 | System.out.println(i); 23 | } 24 | } else { 25 | System.out.println(""); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_17.SumOfASequence/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_17.SumOfASequence/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_17.SumOfASequence/src/main/java/SumOfASequence.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SumOfASequence { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | System.out.println("Last number?"); 10 | int limit = Integer.valueOf(scanner.nextLine()); 11 | 12 | int sum = 0; 13 | 14 | for (int i = 1; i <= limit; i++) { 15 | sum += i; 16 | } 17 | 18 | System.out.println("The sum is " + sum); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_18.SumOfASequenceTheSequel/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_18.SumOfASequenceTheSequel/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_18.SumOfASequenceTheSequel/src/main/java/SumOfASequenceTheSequel.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class SumOfASequenceTheSequel { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | System.out.println("First number?"); 10 | int start = Integer.valueOf(scanner.nextLine()); 11 | 12 | System.out.println("Last number?"); 13 | int limit = Integer.valueOf(scanner.nextLine()); 14 | 15 | int sum = 0; 16 | 17 | for (int i = start; i <= limit; i++) { 18 | sum += i; 19 | } 20 | 21 | System.out.println("The sum is " + sum); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_19.Factorial/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_19.Factorial/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_19.Factorial/src/main/java/Factorial.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Factorial { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | System.out.println("Give a number:"); 10 | int number = Integer.valueOf(scanner.nextLine()); 11 | int total = 1; 12 | 13 | for (int i = 1; i <= number; i++) { 14 | total *= i; 15 | } 16 | 17 | System.out.println("Factorial: " + total); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_20.RepeatingBreakingAndRemembering/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_20.RepeatingBreakingAndRemembering/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_21.InAHoleInTheGround/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_21.InAHoleInTheGround/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_21.InAHoleInTheGround/src/main/java/InAHoleInTheGround.java: -------------------------------------------------------------------------------- 1 | public class InAHoleInTheGround { 2 | 3 | public static void main(String[] args) { 4 | printText(); 5 | } 6 | 7 | public static void printText() { 8 | // Write some code in here 9 | System.out.println("In a hole in the ground there lived a method"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_22.Reprint/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_22.Reprint/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_22.Reprint/src/main/java/Reprint.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Reprint { 5 | 6 | public static void main(String[] args) { 7 | // ask the user for how many times should the text be printed 8 | // then call the printText-method multiple times with a while-loop 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | System.out.println("How many times?"); 12 | int times = Integer.valueOf(scanner.nextLine()); 13 | int counter = 0; 14 | 15 | while (counter < times) { 16 | printText(); 17 | counter++; 18 | } 19 | } 20 | 21 | // Don't change the next line that defines the method! 22 | // (We aren't giving a method a parameter yet) 23 | public static void printText() { 24 | // write some code here 25 | System.out.println("In a hole in the ground there lived a method"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_23.FromOneToParameter/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_23.FromOneToParameter/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_23.FromOneToParameter/src/main/java/FromOneToParameter.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class FromOneToParameter { 4 | 5 | public static void main(String[] args) { 6 | printUntilNumber(5); 7 | 8 | } 9 | 10 | public static void printUntilNumber(int number) { 11 | for (int i = 1; i <= number; i++) { 12 | System.out.println(i); 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_24.FromParameterToOne/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_24.FromParameterToOne/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_24.FromParameterToOne/src/main/java/FromParameterToOne.java: -------------------------------------------------------------------------------- 1 | 2 | public class FromParameterToOne { 3 | 4 | public static void main(String[] args) { 5 | printFromNumberToOne(7); 6 | 7 | } 8 | 9 | public static void printFromNumberToOne(int number) { 10 | for (int i = number; i >= 1; i--) { 11 | System.out.println(i); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_25.Division/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_25.Division/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_25.Division/src/main/java/Division.java: -------------------------------------------------------------------------------- 1 | 2 | public class Division { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Once you have implemented the division method, you can 7 | // try it out here. Fopr example division(3,5); 8 | // should print "0.6" 9 | division(3, 5); 10 | } 11 | 12 | // implement the method here 13 | public static void division(int numerator, int denominator) { 14 | double answer = (double) numerator / (double) denominator; 15 | System.out.println(answer); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_26.DivisibleByThree/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_26.DivisibleByThree/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_26.DivisibleByThree/src/main/java/DivisibleByThree.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class DivisibleByThree { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | divisibleByThreeInRange(3, 81); 9 | 10 | } 11 | 12 | public static void divisibleByThreeInRange(int beginning, int end) { 13 | for (int i = beginning; i <= end; i++) { 14 | if (i % 3 == 0) { 15 | System.out.println(i); 16 | } 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_27.NumberUno/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_27.NumberUno/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_27.NumberUno/src/main/java/NumberUno.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NumberUno { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | } 10 | 11 | public static int numberUno() { 12 | return 1; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_27.NumberUno/src/test/java/NumberUnoTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import fi.helsinki.cs.tmc.edutestutils.Reflex; 4 | import org.junit.*; 5 | import static org.junit.Assert.*; 6 | 7 | @Points("02-27") 8 | public class NumberUnoTest { 9 | 10 | @Test(timeout = 1000) 11 | public void test1() throws Throwable { 12 | int number = Reflex.reflect(NumberUno.class).staticMethod("numberUno").returning(int.class).takingNoParams().invoke(); 13 | assertEquals("The 'numberUno' method should return the value 1.", 1, number); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_28.Word/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_28.Word/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_28.Word/src/main/java/Word.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Word { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | } 10 | 11 | public static String word() { 12 | return "Hello, world"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_28.Word/src/test/java/WordTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import fi.helsinki.cs.tmc.edutestutils.Reflex; 4 | import org.junit.*; 5 | 6 | @Points("02-28") 7 | public class WordTest { 8 | 9 | @Test(timeout = 1000) 10 | public void test1() throws Throwable { 11 | String returnValue = Reflex.reflect(Word.class).staticMethod("word").returning(String.class).takingNoParams().invoke(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_29.Summation/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_29.Summation/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_29.Summation/src/main/java/Summation.java: -------------------------------------------------------------------------------- 1 | public class Summation { 2 | 3 | public static int sum(int num1, int num2, int num3, int num4) { 4 | // write some code here 5 | return num1 + num2 + num3 + num4; 6 | } 7 | 8 | public static void main(String[] args) { 9 | int result = sum(4, 3, 6, 1); 10 | System.out.println("Sum: " + result); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_29.Summation/src/test/java/SummationTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import org.junit.*; 4 | import static org.junit.Assert.*; 5 | 6 | @Points("02-29") 7 | public class SummationTest { 8 | 9 | @Test 10 | public void addingPositiveNumbers() { 11 | assertEquals("Doesn't work when the input is 1,2,2,1", 6, Summation.sum(1, 2, 2, 1)); 12 | } 13 | 14 | @Test 15 | public void addingNegativeNumbers() { 16 | assertEquals("Doesn't work when the input is 1,2,-1,1", 3, Summation.sum(1, 2, -1, 1)); 17 | } 18 | 19 | @Test 20 | public void testMethod() { 21 | test("Doesn't work when the input is 1,2,3,4", 10, new int[]{1, 2, 3, 4}); 22 | } 23 | 24 | @Test 25 | public void addingGrandNumbers(){ 26 | test("Doesn't work when the input is 0,0,0,2147483647",Integer.MAX_VALUE,new int[]{0,0,0,Integer.MAX_VALUE}); 27 | } 28 | 29 | 30 | private void test(String message, int expected, int[] numbers) { 31 | assertEquals(message, expected, Summation.sum(numbers[0], numbers[1], numbers[2], numbers[3])); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_30.Smallest/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_30.Smallest/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_30.Smallest/src/main/java/Smallest.java: -------------------------------------------------------------------------------- 1 | 2 | public class Smallest { 3 | 4 | public static int smallest(int number1, int number2) { 5 | // Write some code here 6 | if (number1 < number2) { 7 | return number1; 8 | } 9 | // don't print anything inside this method 10 | // there must be a return in the end of the method 11 | return number2; 12 | } 13 | 14 | public static void main(String[] args) { 15 | int result = smallest(2, 7); 16 | System.out.println("Smallest: " + result); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_30.Smallest/src/test/java/SmallestTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import org.junit.*; 4 | import static org.junit.Assert.*; 5 | 6 | @Points("02-30") 7 | public class SmallestTest { 8 | 9 | @Test 10 | public void normalCase() { 11 | test(2, 7, 2); 12 | } 13 | 14 | @Test 15 | public void oneIsNegative() { 16 | test(-5, 4, -5); 17 | } 18 | 19 | @Test 20 | public void veryLargeValues() { 21 | test(Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE); 22 | } 23 | 24 | @Test 25 | public void normalCaseReversed() { 26 | test(7, 2, 2); 27 | } 28 | 29 | private void test(int num1, int num2, int expected) { 30 | assertEquals(getError(num1, num2), expected, Smallest.smallest(num1, num2)); 31 | } 32 | 33 | private String getError(int num1, int num2) { 34 | return "Wrong result when number1=" + num1 + " and nsumber2=" + num2; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_31.Greatest/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_31.Greatest/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_31.Greatest/src/main/java/Greatest.java: -------------------------------------------------------------------------------- 1 | 2 | public class Greatest { 3 | 4 | public static int greatest(int number1, int number2, int number3) { 5 | //write some code here 6 | if (number1 > number2 && number1 > number3) { 7 | return number1; 8 | } else if (number2 > number1 && number2 > number3) { 9 | return number2; 10 | } else { 11 | return number3; 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | int result = greatest(2, 7, 3); 17 | System.out.println("Greatest: " + result); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_32.Averaging/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_32.Averaging/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_32.Averaging/src/main/java/Averaging.java: -------------------------------------------------------------------------------- 1 | 2 | public class Averaging { 3 | 4 | // implement the sum method here again 5 | public static int sum(int number1, int number2, int number3, int number4) { 6 | // write some code here 7 | return number1 + number2 + number3 + number4; 8 | } 9 | 10 | public static double average(int number1, int number2, int number3, int number4) { 11 | //write some code here 12 | return (double) sum(number1, number2, number3, number4) / 4 * 1.0; 13 | } 14 | 15 | public static void main(String[] args) { 16 | double result = average(4, 3, 6, 1); 17 | System.out.println("Average: " + result); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_32.Averaging/src/test/java/AveragingTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import org.junit.*; 4 | import static org.junit.Assert.*; 5 | 6 | @Points("02-32") 7 | public class AveragingTest { 8 | 9 | @Test 10 | public void started() { 11 | double result = Averaging.average(1, 1, 1, 1); 12 | assertFalse("You're returning -1, the result of the model. The average of 1, 1, 1, and 1 is 1", 13 | -1 == result); 14 | } 15 | 16 | @Test 17 | public void correctAverage() { 18 | assertEquals("The average of -12, 2, 8 and 0 is not correct, Are you doing the division with integers?", 19 | -0.5, Averaging.average(-12, 2, 8, 0), 0.0001); 20 | } 21 | 22 | @Test 23 | public void correctAverage2() { 24 | assertEquals("The average of 1, 2, 3 and 4 is not correct, Are you doing the division with integers?", 25 | 2.5, Averaging.average(1, 2, 3, 4), 0.0001); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_33.StarSign/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_33.StarSign/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_34.AdvancedAstrology/.tmcproject.json: -------------------------------------------------------------------------------- 1 | { 2 | "checkstyle": { 3 | "strategy": "fail" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part02-Part02_34.AdvancedAstrology/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_01.ThirdElement/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_01.ThirdElement/src/main/java/ThirdElement.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class ThirdElement { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(list.get(2)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_02.SecondPlusThird/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_02.SecondPlusThird/src/main/java/SecondPlusThird.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class SecondPlusThird { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList numbers = new ArrayList<>(); 11 | while (true) { 12 | int number = Integer.valueOf(scanner.nextLine()); 13 | if (number == 0) { 14 | break; 15 | } 16 | 17 | numbers.add(number); 18 | } 19 | 20 | System.out.println(numbers.get(1) + numbers.get(2)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_03.IndexOutOfBoundsException/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_03.IndexOutOfBoundsException/src/main/java/IoobProgram.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class IoobProgram { 5 | 6 | public static void main(String[] args) { 7 | // Modify this program to cause an indexOutOfBoundsException 8 | 9 | ArrayList lines = new ArrayList<>(); 10 | lines.add("Never has a man influenced physics so profoundly as Niels Bohr in the early 1900's"); 11 | lines.add("Going back to this time period, little was known about atomic structure; Bohr set out"); 12 | lines.add("to end the obscurity of physics. However, things didn't come easy for Bohr. He had to"); 13 | lines.add("give up most of his life for physics and research of many hypothesis. But, this is why"); 14 | lines.add("you and I have even heard of the quantum theory and atomic structures. Bohr came"); 15 | lines.add("up with his quantum theory while studying..."); 16 | 17 | for (String line : lines) { 18 | System.out.println(line); 19 | } 20 | 21 | System.out.println(lines.get(6)); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_03.IndexOutOfBoundsException/src/test/java/IoobProgramTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | @Points("03-03") 7 | public class IoobProgramTest { 8 | 9 | @Test 10 | public void causingIndexOutOfBoundsException() { 11 | try { 12 | IoobProgram.main(new String[]{}); 13 | fail("Execution of the program should cause an IndexOutOfBoundsException. Now it didn't happen."); 14 | } catch (IndexOutOfBoundsException e) { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_04.ListSize/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_04.ListSize/src/main/java/ListSize.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class ListSize { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | System.out.println("In total: " + list.size()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_05.LastInList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_05.LastInList/src/main/java/LastInList.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class LastInList { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(list.get(list.size() - 1)); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_06.FirstAndLast/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_06.FirstAndLast/src/main/java/FirstAndLast.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class FirstAndLast { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(list.get(0)); 21 | System.out.println(list.get(list.size() - 1)); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_07.RememberTheseNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_07.RememberTheseNumbers/src/main/java/RememberTheseNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class RememberTheseNumbers { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList numbers = new ArrayList<>(); 11 | while (true) { 12 | int luku = Integer.valueOf(scanner.nextLine()); 13 | if (luku == -1) { 14 | break; 15 | } 16 | 17 | numbers.add(luku); 18 | } 19 | 20 | for (int i = 0; i < numbers.size(); i++) { 21 | System.out.println(numbers.get(i)); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_08.OnlyTheseNumbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_08.OnlyTheseNumbers/src/main/java/OnlyTheseNumbers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class OnlyTheseNumbers { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList numbers = new ArrayList<>(); 11 | while (true) { 12 | int number = Integer.valueOf(scanner.nextLine()); 13 | if (number == -1) { 14 | break; 15 | } 16 | 17 | numbers.add(number); 18 | } 19 | 20 | System.out.println("From where?"); 21 | int start = Integer.valueOf(scanner.nextLine()); 22 | System.out.println("To where?"); 23 | int end = Integer.valueOf(scanner.nextLine()); 24 | 25 | for (int i = start; i <= end; i++) { 26 | System.out.println(numbers.get(i)); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_09.GreatestInList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_09.GreatestInList/src/main/java/GreatestInList.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class GreatestInList { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | int input = Integer.valueOf(scanner.nextLine()); 13 | if (input == -1) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(""); 21 | 22 | // implement finding the greatest number in the list here 23 | int greatest = list.get(0); 24 | 25 | for (int i = 0; i < list.size(); i++) { 26 | int number = list.get(i); 27 | 28 | if (greatest < number) { 29 | greatest = number; 30 | } 31 | } 32 | 33 | System.out.println("The greatest number: " + greatest); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_10.IndexOf/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_10.IndexOf/src/main/java/IndexOf.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class IndexOf { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | int input = Integer.valueOf(scanner.nextLine()); 13 | if (input == -1) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(""); 21 | 22 | // implement here finding the indices of a number 23 | System.out.println("Search for?"); 24 | int number = Integer.valueOf(scanner.nextLine()); 25 | int index; 26 | 27 | for (int i = 0; i < list.size(); i++) { 28 | int value = list.get(i); 29 | if (number == value) { 30 | index = i; 31 | System.out.println(number + " is at index " + index); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_11.IndexOfSmallest/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_12.SumOfAList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_12.SumOfAList/src/main/java/SumOfAList.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class SumOfAList { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | int input = Integer.valueOf(scanner.nextLine()); 13 | if (input == -1) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println(""); 21 | 22 | // toteuta listan lukujen summan laskeminen tänne 23 | int sum = 0; 24 | for (Integer number : list) { 25 | sum += number; 26 | } 27 | System.out.println("Sum: " + sum); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_13.AverageOfAList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_13.AverageOfAList/src/main/java/AverageOfAList.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class AverageOfAList { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | // implement here a program, that first reads user input 11 | // adding them on a list until user gives -1. 12 | // Then it computes the average of the numbers on the list 13 | // and prints it. 14 | ArrayList list = new ArrayList<>(); 15 | while (true) { 16 | int input = Integer.valueOf(scanner.nextLine()); 17 | if (input == -1) { 18 | break; 19 | } 20 | list.add(input); 21 | } 22 | System.out.println(""); 23 | 24 | int sum = 0; 25 | for (Integer number : list) { 26 | sum += number; 27 | } 28 | 29 | int length = list.size(); 30 | 31 | double average = (sum * 1.0) / length; 32 | 33 | System.out.println("Average: " + average); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_14.OnTheList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_14.OnTheList/src/main/java/OnTheList.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class OnTheList { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | ArrayList list = new ArrayList<>(); 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | list.add(input); 18 | } 19 | 20 | System.out.println("Search for?"); 21 | String search = scanner.nextLine(); 22 | 23 | if (list.contains(search)) { 24 | System.out.println(search + " was found!"); 25 | } else { 26 | System.out.println(search + " was not found!"); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_15.PrintInRange/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_15.PrintInRange/src/main/java/PrintInRange.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class PrintInRange { 5 | 6 | public static void main(String[] args) { 7 | // Try your method here 8 | ArrayList numbers = new ArrayList<>(); 9 | numbers.add(3); 10 | numbers.add(2); 11 | numbers.add(6); 12 | numbers.add(-1); 13 | numbers.add(5); 14 | numbers.add(1); 15 | numbers.add(11); 16 | numbers.add(4); 17 | numbers.add(7); 18 | numbers.add(-11); 19 | numbers.add(8); 20 | numbers.add(13); 21 | printNumbersInRange(numbers, 0, 5); 22 | } 23 | 24 | public static void printNumbersInRange(ArrayList numbers, int lowerLimit, int upperLimit) { 25 | System.out.println("The numbers in range [" + lowerLimit + ", " + upperLimit + "]"); 26 | for (int number : numbers) { 27 | if (number >= lowerLimit && number <= upperLimit) { 28 | System.out.println(number); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_16.Sum/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_16.Sum/src/main/java/Sum.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class Sum { 5 | 6 | public static int sum(ArrayList numbers) { 7 | int sum = 0; 8 | for (int number : numbers) { 9 | sum += number; 10 | } 11 | 12 | return sum; 13 | } 14 | 15 | public static void main(String[] args) { 16 | // Try your method here 17 | ArrayList numbers = new ArrayList<>(); 18 | numbers.add(3); 19 | numbers.add(2); 20 | numbers.add(6); 21 | numbers.add(-1); 22 | System.out.println(sum(numbers)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_17.RemoveLast/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_17.RemoveLast/src/main/java/RemoveLast.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class RemoveLast { 5 | 6 | public static void removeLast(ArrayList strings) { 7 | if (strings.size() == 0) { 8 | return; 9 | } 10 | strings.remove(strings.size() - 1); 11 | } 12 | 13 | public static void main(String[] args) { 14 | // Try your method in here 15 | ArrayList strings = new ArrayList<>(); 16 | strings.add("First"); 17 | strings.add("Second"); 18 | strings.add("Third"); 19 | strings.add("Fourth"); 20 | strings.add("Fifth"); 21 | strings.add("Sixth"); 22 | 23 | System.out.println(strings); 24 | 25 | removeLast(strings); 26 | removeLast(strings); 27 | 28 | System.out.println(strings); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_18.Swap/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_19.IndexWasNotFound/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_20.SumOfArray/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_20.SumOfArray/src/main/java/SumOfArray.java: -------------------------------------------------------------------------------- 1 | 2 | public class SumOfArray { 3 | 4 | public static void main(String[] args) { 5 | // You can try the method here 6 | int[] array = {5, 1, 9, 4, 2}; 7 | System.out.println(sumOfNumbersInArray(array)); 8 | } 9 | 10 | public static int sumOfNumbersInArray(int[] array) { 11 | // Write some code here 12 | int sum = 0; 13 | for (int i = 0; i < array.length; i++) { 14 | sum = array[i] + sum; 15 | } 16 | return sum; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_21.PrintNeatly/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_21.PrintNeatly/src/main/java/ArrayPrinter.java: -------------------------------------------------------------------------------- 1 | 2 | public class ArrayPrinter { 3 | 4 | public static void main(String[] args) { 5 | // You can test your method here 6 | int[] array = {5, 1, 3, 4, 2}; 7 | printNeatly(array); 8 | } 9 | 10 | public static void printNeatly(int[] array) { 11 | // Write some code in here 12 | for (int i = 0; i < array.length - 1; i++) { 13 | System.out.print(array[i] + "," + " "); 14 | } 15 | System.out.print(array[array.length - 1]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_22.PrintInStars/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_22.PrintInStars/src/main/java/Printer.java: -------------------------------------------------------------------------------- 1 | 2 | public class Printer { 3 | 4 | public static void main(String[] args) { 5 | // You can test the method here 6 | int[] array = {5, 1, 3, 4, 2}; 7 | printArrayInStars(array); 8 | } 9 | 10 | public static void printArrayInStars(int[] array) { 11 | // Write some code in here 12 | for (int i = 0; i < array.length; i++) { 13 | for (int j = 0; j < array[i]; j++) { 14 | System.out.print("*"); 15 | } 16 | System.out.println(""); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_23.PrintThrice/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_23.PrintThrice/src/main/java/PrintThrice.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class PrintThrice { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here 10 | System.out.print("Give a word: "); 11 | String word = scanner.nextLine(); 12 | 13 | String threeWords = word + word + word; 14 | 15 | System.out.println(threeWords); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_24.IsItTrue/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_24.IsItTrue/src/main/java/IsItTrue.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class IsItTrue { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | System.out.print("Give a string: "); 9 | String myString = scanner.nextLine(); 10 | 11 | if (myString.equals("true")) { 12 | System.out.println("You got it right!"); 13 | } else { 14 | System.out.println("Try again!"); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_25.Login/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_25.Login/src/main/java/Login.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Login { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | System.out.print("Enter username: "); 9 | String username = scanner.nextLine(); 10 | System.out.print("Enter password: "); 11 | String password = scanner.nextLine(); 12 | 13 | if (username.equals("alex") && password.equals("sunshine")) { 14 | System.out.println("You have successfully logged in!"); 15 | } else if (username.equals("emma") && password.equals("haskell")) { 16 | System.out.println("You have successfully logged in!"); 17 | } else { 18 | System.out.println("Incorrect username or password!"); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_26.LineByLine/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_26.LineByLine/src/main/java/LineByLine.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class LineByLine { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | 11 | if (input.equals("")) { 12 | return; 13 | } 14 | 15 | String[] fragments = input.split(" "); 16 | int index = 0; 17 | while (!(input.equals("")) && index < fragments.length) { 18 | for (int i = 0; i < fragments.length; i++) { 19 | System.out.println(fragments[i]); 20 | index++; 21 | } 22 | input = scanner.nextLine(); 23 | fragments = input.split(" "); 24 | index = 0; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_27.AVClub/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_27.AVClub/src/main/java/AVClub.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AVClub { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | String input = scanner.nextLine(); 10 | 11 | if (input.equals("")) { 12 | return; 13 | } 14 | 15 | String[] fragments = input.split(" "); 16 | int index = 0; 17 | while (!(input.equals("")) && index < fragments.length) { 18 | for (int i = 0; i < fragments.length; i++) { 19 | if (fragments[i].contains("av")) { 20 | System.out.println(fragments[i]); 21 | } 22 | index++; 23 | } 24 | input = scanner.nextLine(); 25 | fragments = input.split(" "); 26 | index = 0; 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_28.FirstWords/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_28.FirstWords/src/main/java/FirstWords.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class FirstWords { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | String input = scanner.nextLine(); 11 | if (input.equals("")) { 12 | break; 13 | } 14 | 15 | String[] pieces = input.split(" "); 16 | System.out.println(pieces[0]); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_29.LastWords/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_29.LastWords/src/main/java/LastWords.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class LastWords { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | String input = scanner.nextLine(); 11 | if (input.equals("")) { 12 | break; 13 | } 14 | 15 | String[] pieces = input.split(" "); 16 | System.out.println(pieces[pieces.length - 1]); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_30.AgeOfTheOldest/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_30.AgeOfTheOldest/src/main/java/AgeOfTheOldest.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class AgeOfTheOldest { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int age = 0; 9 | int oldest = 0; 10 | 11 | while (true) { 12 | String input = scanner.nextLine(); 13 | if (input.equals("")) { 14 | break; 15 | } 16 | 17 | String[] data = input.split(","); 18 | age = Integer.valueOf(data[1]); 19 | if (age > oldest) { 20 | oldest = age; 21 | } 22 | } 23 | 24 | System.out.println("Age of the oldest: " + oldest); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_31.NameOfTheOldest/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_31.NameOfTheOldest/src/main/java/NameOfTheOldest.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NameOfTheOldest { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int age = 0; 10 | String name = ""; 11 | String oldestName = ""; 12 | int oldest = 0; 13 | 14 | while (true) { 15 | String input = scanner.nextLine(); 16 | if (input.equals("")) { 17 | break; 18 | } 19 | 20 | String[] data = input.split(","); 21 | age = Integer.valueOf(data[1]); 22 | name = data[0]; 23 | if (age > oldest) { 24 | oldest = age; 25 | oldestName = name; 26 | } 27 | } 28 | System.out.println("Name of the oldest: " + oldestName); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_32.PersonalDetails/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part03-Part03_32.PersonalDetails/src/main/java/PersonalDetails.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class PersonalDetails { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | String name = ""; 11 | String longestName = ""; 12 | int sum = 0; 13 | int count = 0; 14 | 15 | while (true) { 16 | String input = scanner.nextLine(); 17 | if (input.equals("")) { 18 | break; 19 | } 20 | 21 | String[] data = input.split(","); 22 | name = data[0]; 23 | if (name.length() > longestName.length()) { 24 | longestName = name; 25 | } 26 | for (int i = 0; i < data.length; i++) { 27 | sum = sum + Integer.valueOf(data[1]); 28 | count++; 29 | } 30 | } 31 | double average = (1.0 * sum / count); 32 | System.out.println("Longest name: " + longestName); 33 | System.out.println("Average of the birth years: " + average); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_01.YourFirstAccount/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_01.YourFirstAccount/src/main/java/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT TOUCH THIS ! 3 | */ 4 | 5 | public class Account { 6 | 7 | private double balance; 8 | private String owner; 9 | 10 | public Account(String owner, double balance) { 11 | this.balance = balance; 12 | this.owner = owner; 13 | } 14 | 15 | public void deposit(double amount) { 16 | this.balance = this.balance + amount; 17 | } 18 | 19 | public void withdrawal(double amount) { 20 | this.balance = this.balance - amount; 21 | } 22 | 23 | public double saldo() { 24 | return this.balance; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return this.owner + " balance: " + this.balance; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_01.YourFirstAccount/src/main/java/YourFirstAccount.java: -------------------------------------------------------------------------------- 1 | 2 | public class YourFirstAccount { 3 | 4 | public static void main(String[] args) { 5 | // Do not touch the code in Account.java 6 | // Write your program here 7 | Account myAccount = new Account("My Account", 100.00); 8 | 9 | myAccount.deposit(20.00); 10 | 11 | System.out.println(myAccount); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_01.YourFirstAccount/src/test/java/MockInOut.java: -------------------------------------------------------------------------------- 1 | import java.io.InputStream; 2 | import java.io.PrintStream; 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.ByteArrayInputStream; 5 | 6 | public class MockInOut { 7 | 8 | private PrintStream orig; 9 | private InputStream irig; 10 | private ByteArrayOutputStream os; 11 | private ByteArrayInputStream is; 12 | 13 | public MockInOut(String input) { 14 | orig = System.out; 15 | irig = System.in; 16 | 17 | os = new ByteArrayOutputStream(); 18 | System.setOut(new PrintStream(os)); 19 | 20 | is = new ByteArrayInputStream(input.getBytes()); 21 | System.setIn(is); 22 | } 23 | 24 | public InputStream getInputStream() { 25 | return is; 26 | } 27 | 28 | public String getOutput() { 29 | if (os != null) 30 | return os.toString(); 31 | else 32 | throw new Error("getOutput on closed MockInOut!"); 33 | } 34 | 35 | public void close() { 36 | os = null; 37 | is = null; 38 | System.setOut(orig); 39 | System.setIn(irig); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_02.YourFirstBankTransfer/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_02.YourFirstBankTransfer/src/main/java/Account.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DO NOT TOUCH THIS ! 3 | */ 4 | 5 | public class Account { 6 | 7 | private double balance; 8 | private String owner; 9 | 10 | public Account(String owner, double balance) { 11 | this.balance = balance; 12 | this.owner = owner; 13 | } 14 | 15 | public void deposit(double amount) { 16 | this.balance = this.balance + amount; 17 | } 18 | 19 | public void withdrawal(double amount) { 20 | this.balance = this.balance - amount; 21 | } 22 | 23 | public double balance() { 24 | return this.balance; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return this.owner + " balance: " + this.balance; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_02.YourFirstBankTransfer/src/main/java/YourFirstBankTransfer.java: -------------------------------------------------------------------------------- 1 | 2 | public class YourFirstBankTransfer { 3 | 4 | public static void main(String[] args) { 5 | // Do not touch the code in Account.java 6 | // write your program here 7 | Account mattsAccount = new Account("Matthews account", 1000.00); 8 | 9 | Account myAccount = new Account("My account", 0.0); 10 | 11 | mattsAccount.withdrawal(100.00); 12 | 13 | myAccount.deposit(100.00); 14 | 15 | System.out.println(mattsAccount); 16 | System.out.println(myAccount); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_03.DogAttributes/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_03.DogAttributes/src/main/java/Dog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Dog { 12 | 13 | private String name; 14 | private String breed; 15 | private int age; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_03.DogAttributes/src/main/java/DogAttributes.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class DogAttributes { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Follow the instructions carefully 10 | // and run the tests. 11 | 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_04.Room/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_04.Room/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class MainProgram { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Follow the instructions carefully 10 | // and run the tests. 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_04.Room/src/main/java/Room.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Room { 12 | 13 | private String code; 14 | private int seats; 15 | 16 | public Room(String classCode, int numberOfSeats) { 17 | this.code = classCode; 18 | this.seats = numberOfSeats; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_05.Whistle/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_05.Whistle/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // This is just an empty main method you can use to test 6 | // the Whistle class. Try for example: 7 | 8 | // Whistle duckWhistle = new Whistle("Kvaak"); 9 | // Whistle roosterWhistle = new Whistle("Peef"); 10 | // 11 | // duckWhistle.sound(); 12 | // roosterWhistle.sound(); 13 | // duckWhistle.sound(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_05.Whistle/src/main/java/Whistle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Whistle { 12 | 13 | private String sound; 14 | 15 | public Whistle(String whistleSound) { 16 | this.sound = whistleSound; 17 | } 18 | 19 | public void sound() { 20 | System.out.println(this.sound); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_06.Door/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_06.Door/src/main/java/Door.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Door { 12 | 13 | public Door() { 14 | 15 | } 16 | 17 | public void knock() { 18 | System.out.println("Who's there?"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_06.Door/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // This is an empty main method 6 | // You can use it to test your Door class. Try the following: 7 | 8 | // Door alexander = new Door(); 9 | // 10 | // alexander.knock(); 11 | // alexander.knock(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_07.Product/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_07.Product/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // This is an empty main method for testing the Product class 6 | // Try: 7 | 8 | // Product product = new Product("Banana", 1.1, 13); 9 | // product.printProduct(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_07.Product/src/main/java/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Product { 12 | 13 | private double price; 14 | private int quantity; 15 | private String name; 16 | 17 | public Product(String initialName, double initialPrice, int initialQuantity) { 18 | this.name = initialName; 19 | this.price = initialPrice; 20 | this.quantity = initialQuantity; 21 | } 22 | 23 | public void printProduct() { 24 | System.out.println(this.name + ", " + "price " + this.price + ", " + this.quantity + " pcs"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_08.DecreasingCounter/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_08.DecreasingCounter/src/main/java/DecreasingCounter.java: -------------------------------------------------------------------------------- 1 | 2 | public class DecreasingCounter { 3 | 4 | private int value; // an object variable for storing the value of the counter 5 | 6 | public DecreasingCounter(int initialValue) { 7 | this.value = initialValue; 8 | } 9 | 10 | public void printValue() { 11 | // Do not change this code! 12 | System.out.println("value: " + this.value); 13 | } 14 | 15 | public void decrement() { 16 | // write the method implementation here 17 | // the aim is to decrement the value of the counter by one 18 | if (this.value > 0) { 19 | this.value = this.value - 1; 20 | } 21 | } 22 | 23 | // the other methods go here 24 | public void reset() { 25 | this.value = 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_08.DecreasingCounter/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | DecreasingCounter counter = new DecreasingCounter(10); 6 | 7 | counter.printValue(); 8 | counter.decrement(); 9 | counter.decrement(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_09.Debt/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_09.Debt/src/main/java/Debt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Debt { 12 | 13 | private double balance; 14 | private double interestRate; 15 | 16 | public Debt(double initialBalance, double initialInterestRate) { 17 | this.balance = initialBalance; 18 | this.interestRate = initialInterestRate; 19 | } 20 | 21 | public void printBalance() { 22 | System.out.println(balance); 23 | } 24 | 25 | public void waitOneYear() { 26 | balance = balance * interestRate; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_09.Debt/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Test your Debt class here 6 | Debt mortgage = new Debt(120000.0, 1.2); 7 | mortgage.printBalance(); 8 | 9 | mortgage.waitOneYear(); 10 | mortgage.printBalance(); 11 | 12 | int years = 0; 13 | 14 | while (years < 20) { 15 | mortgage.waitOneYear(); 16 | years = years + 1; 17 | } 18 | 19 | mortgage.printBalance(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_10.Song/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_10.Song/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // This is just an empty main method, where you can test your 6 | // Song class. You can for instance try this: 7 | 8 | Song garden = new Song("In The Garden", 10910); 9 | System.out.println("The song " + garden.name() + " has a length of " + garden.length() + " seconds."); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_10.Song/src/main/java/Song.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Song { 12 | 13 | private final String name; 14 | private final int length; 15 | 16 | public Song(String name, int length) { 17 | this.name = name; 18 | this.length = length; 19 | } 20 | 21 | public String name() { 22 | return this.name; 23 | } 24 | 25 | public int length() { 26 | return this.length; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_11.Film/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_11.Film/src/main/java/Film.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Film { 12 | private String name; 13 | private int ageRating; 14 | 15 | public Film(String filmName, int filmAgeRating) { 16 | this.name = filmName; 17 | this.ageRating = filmAgeRating; 18 | } 19 | 20 | public String name() { 21 | return this.name; 22 | } 23 | 24 | public int ageRating() { 25 | return this.ageRating; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_11.Film/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; // Import the Scanner class 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | // Test your Film class here 8 | 9 | Film chipmunks = new Film("Alvin and the Chipmunks: The Squeakquel", 0); 10 | 11 | Scanner reader = new Scanner(System.in); 12 | 13 | System.out.println("How old are you"); 14 | int age = Integer.valueOf(reader.nextLine()); 15 | 16 | System.out.println(); 17 | if (age >= chipmunks.ageRating()) { 18 | System.out.println("You may watch the film " + chipmunks.name()); 19 | } else { 20 | System.out.println("You may not watch the film " + chipmunks.name()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_12.Gauge/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_12.Gauge/src/main/java/Gauge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Gauge { 12 | 13 | private int value; 14 | 15 | public Gauge() { 16 | this.value = 0; 17 | } 18 | 19 | public void increase() { 20 | if (this.value < 5) { 21 | value++; 22 | } 23 | } 24 | 25 | public void decrease() { 26 | if (this.value > 0) { 27 | value--; 28 | } 29 | } 30 | 31 | public int value() { 32 | return this.value; 33 | } 34 | 35 | public boolean full() { 36 | return this.value == 5; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_12.Gauge/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Test your Gauge class here 6 | 7 | Gauge g = new Gauge(); 8 | 9 | while (!g.full()) { 10 | System.out.println("Not full! Value: " + g.value()); 11 | g.increase(); 12 | } 13 | 14 | System.out.println("Full! Value: " + g.value()); 15 | g.decrease(); 16 | System.out.println("Not full! Value: " + g.value()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_13.Agent/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_13.Agent/src/main/java/Agent.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class Agent { 4 | 5 | private String firstName; 6 | private String lastName; 7 | 8 | public Agent(String initFirstName, String initLastName) { 9 | this.firstName = initFirstName; 10 | this.lastName = initLastName; 11 | } 12 | 13 | public String toString() { 14 | return "My name is " + this.lastName + ", " + this.firstName + " " + this.lastName; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_14.Multiplier/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_14.Multiplier/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Test your Multiplier class here 6 | 7 | Multiplier multiplyByThree = new Multiplier(3); 8 | 9 | System.out.println("multiplyByThree.multiply(2): " + multiplyByThree.multiply(2)); 10 | 11 | Multiplier multiplyByFour = new Multiplier(4); 12 | 13 | System.out.println("multiplyByFour.multiply(2): " + multiplyByFour.multiply(2)); 14 | System.out.println("multiplyByThree.multiply(1): " + multiplyByThree.multiply(1)); 15 | System.out.println("multiplyByFour.multiply(1): " + multiplyByFour.multiply(1)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_14.Multiplier/src/main/java/Multiplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Multiplier { 12 | private int number; 13 | 14 | public Multiplier(int number) { 15 | this.number = number; 16 | } 17 | 18 | public int multiply(int number) { 19 | return this.number * number; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_15.NumberStatistics/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_15.NumberStatistics/src/main/java/Statistics.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class Statistics { 5 | 6 | private int count; 7 | private int sum; 8 | 9 | private final ArrayList list = new ArrayList<>(); 10 | 11 | public Statistics() { 12 | this.count = 0; 13 | } 14 | 15 | public void addNumber(int number) { 16 | this.count += 1; 17 | this.list.add(number); 18 | 19 | int total = 0; 20 | for (int i = 0; i < list.size(); i++) { 21 | total += list.get(i); 22 | } 23 | this.sum = total; 24 | } 25 | 26 | public int getCount() { 27 | return this.count; 28 | } 29 | 30 | public int sum() { 31 | if (this.count == 0) { 32 | return 0; 33 | } else { 34 | return this.sum; 35 | } 36 | } 37 | 38 | public double average() { 39 | double average; 40 | if (this.count == 0) { 41 | average = 0; 42 | } else { 43 | average = 1.0 * this.sum / this.count; 44 | } 45 | 46 | return average; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_16.PaymentCard/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_16.PaymentCard/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // Scanner scanner = new Scanner(System.in); 6 | 7 | // Here you can write code to test that PaymentCard works as intended 8 | // be sure to erase the extra code for the last part of the exercise! 9 | PaymentCard paulsCard = new PaymentCard(20); 10 | PaymentCard mattsCard = new PaymentCard(30); 11 | 12 | paulsCard.eatHeartily(); 13 | mattsCard.eatAffordably(); 14 | System.out.println("Paul: " + paulsCard); 15 | System.out.println("Matt: " + mattsCard); 16 | paulsCard.addMoney(20.00); 17 | mattsCard.eatHeartily(); 18 | System.out.println("Paul: " + paulsCard); 19 | System.out.println("Matt: " + mattsCard); 20 | paulsCard.eatAffordably(); 21 | paulsCard.eatAffordably(); 22 | mattsCard.addMoney(50); 23 | System.out.println("Paul: " + paulsCard); 24 | System.out.println("Matt: " + mattsCard); 25 | 26 | 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_17.Items/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_17.Items/src/main/java/Item.java: -------------------------------------------------------------------------------- 1 | 2 | import java.time.LocalDateTime; 3 | import java.time.format.DateTimeFormatter; 4 | 5 | public class Item { 6 | 7 | private String name; 8 | private LocalDateTime createdAt; 9 | 10 | public Item(String name) { 11 | this.name = name; 12 | this.createdAt = LocalDateTime.now(); 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss"); 22 | 23 | return this.name + " (created at: " + formatter.format(this.createdAt) + ")"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_17.Items/src/main/java/Items.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class Items { 6 | 7 | public static void main(String[] args) { 8 | // implement here your program that uses the class Item 9 | 10 | ArrayList items = new ArrayList<>(); 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | while (true) { 14 | System.out.print("Enter a name, empty will stop: "); 15 | String item = scanner.nextLine(); 16 | if (item.isEmpty()) { 17 | break; 18 | } 19 | 20 | items.add(new Item(item)); 21 | } 22 | 23 | for (Item item: items){ 24 | System.out.println(item); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_18.PersonalInformation/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_18.PersonalInformation/src/main/java/PersonalInformation.java: -------------------------------------------------------------------------------- 1 | 2 | public class PersonalInformation { 3 | 4 | private String firstName; 5 | private String lastName; 6 | private String identificationNumber; 7 | 8 | public PersonalInformation(String firstName, String lastName, String identificationNumber) { 9 | this.firstName = firstName; 10 | this.lastName = lastName; 11 | this.identificationNumber = identificationNumber; 12 | } 13 | 14 | public String getFirstName() { 15 | return firstName; 16 | } 17 | 18 | public String getLastName() { 19 | return lastName; 20 | } 21 | 22 | public String getIdentificationNumber() { 23 | return identificationNumber; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return this.lastName + ", " + this.firstName + " (" + this.identificationNumber + ")"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_19.TelevisionPrograms/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_19.TelevisionPrograms/src/main/java/TelevisionProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class TelevisionProgram { 3 | 4 | private String name; 5 | private int duration; 6 | 7 | public TelevisionProgram(String name, int duration) { 8 | this.name = name; 9 | this.duration = duration; 10 | } 11 | 12 | public boolean isAwesome() { 13 | return this.name.contains("MasterChef"); 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public int getDuration() { 21 | return duration; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return this.name + ", " + this.duration + " minutes"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_20.Books/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_20.Books/src/main/java/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Book { 12 | 13 | private String title; 14 | private int pages; 15 | private int year; 16 | 17 | public Book(String initialTitle, int initialPages, int initialYear) { 18 | this.title = initialTitle; 19 | this.pages = initialPages; 20 | this.year = initialYear; 21 | } 22 | 23 | public String getTitle() { 24 | return this.title; 25 | } 26 | 27 | public int getPages() { 28 | return this.pages; 29 | } 30 | 31 | public int getYear() { 32 | return this.year; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return this.title + ", " + this.pages + " pages, " + this.year; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_21.NumberOfStrings/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_21.NumberOfStrings/src/main/java/NumberOfStrings.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class NumberOfStrings { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | int count = 0; 10 | 11 | while (true) { 12 | String line = scanner.nextLine(); 13 | 14 | if (line.equals("end")) { 15 | break; 16 | } 17 | 18 | count += 1; 19 | } 20 | System.out.println(count); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_22.Cubes/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_22.Cubes/src/main/java/Cubes.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Cubes { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | while (true) { 10 | String value = scanner.nextLine(); 11 | 12 | if (value.equals("end")) { 13 | break; 14 | } 15 | 16 | int number = Integer.valueOf(value); 17 | System.out.println(number * number * number); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_23.CreatingANewFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | extra_student_files: 3 | - file.txt 4 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_23.CreatingANewFile/file.txt: -------------------------------------------------------------------------------- 1 | Hello, world! -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_23.CreatingANewFile/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | public class Program { 2 | 3 | public static void main(String[] args) { 4 | // you don't need to do anything here... 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_23.CreatingANewFile/src/test/java/CreatingANewFileTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.util.Scanner; 6 | import org.junit.Test; 7 | import static org.junit.Assert.*; 8 | 9 | @Points("04-23") 10 | public class CreatingANewFileTest { 11 | 12 | @Test 13 | public void fileExists() { 14 | assertTrue(new File("file.txt").exists()); 15 | } 16 | 17 | @Test 18 | public void containsTextHelloWorld() throws FileNotFoundException { 19 | fileExists(); 20 | 21 | try (Scanner s = new Scanner(new File("file.txt"))) { 22 | String row = s.nextLine(); 23 | assertTrue("The first line of the file \"file.txt\" should have the text \"Hello, world!\".\nNow the text was:\n" + row, row.startsWith("Hello, world!")); 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_24.PrintingAFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_24.PrintingAFile/data.txt: -------------------------------------------------------------------------------- 1 | 9a12 2 | 021b 3 | 8dd2 4 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_24.PrintingAFile/src/main/java/PrintingAFile.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.file.Paths; 3 | import java.util.Scanner; 4 | 5 | public class PrintingAFile { 6 | 7 | public static void main(String[] args) { 8 | try (Scanner scanner = new Scanner(Paths.get("data.txt"))) { 9 | 10 | while(scanner.hasNextLine()) { 11 | String row = scanner.nextLine(); 12 | 13 | System.out.println(row); 14 | } 15 | 16 | } catch (Exception e) { 17 | System.out.println("Error: " + e.getMessage()); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_25.PrintingASpecifiedFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_25.PrintingASpecifiedFile/data.txt: -------------------------------------------------------------------------------- 1 | hello world! 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_25.PrintingASpecifiedFile/src/main/java/PrintingASpecifiedFile.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.file.Paths; 3 | import java.util.Scanner; 4 | 5 | public class PrintingASpecifiedFile { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | System.out.println("Which file should have its contents printed? "); 11 | String fileName = scanner.nextLine(); 12 | 13 | try (Scanner reader = new Scanner(Paths.get(fileName))) { 14 | while (reader.hasNextLine()) { 15 | String row = reader.nextLine(); 16 | 17 | System.out.println(row); 18 | } 19 | } catch (Exception e) { 20 | System.out.println("Error: " + e.getMessage()); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_26.GuestListFromAFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_26.GuestListFromAFile/names.txt: -------------------------------------------------------------------------------- 1 | ada 2 | arto 3 | leena 4 | test 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_26.GuestListFromAFile/other-names.txt: -------------------------------------------------------------------------------- 1 | leo 2 | jarmo 3 | alicia 4 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_27.IsItInTheFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_27.IsItInTheFile/names.txt: -------------------------------------------------------------------------------- 1 | ada 2 | arto 3 | leena 4 | testi 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_27.IsItInTheFile/other-names.txt: -------------------------------------------------------------------------------- 1 | leo 2 | jarmo 3 | alicia 4 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_28.NumbersFromAFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_28.NumbersFromAFile/numbers-1.txt: -------------------------------------------------------------------------------- 1 | 300 2 | 9 3 | 20 4 | 15 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_28.NumbersFromAFile/numbers-2.txt: -------------------------------------------------------------------------------- 1 | 123 2 | -5 3 | 12 4 | 67 5 | -300 6 | 1902 7 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_29.RecordsFromAFile/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_29.RecordsFromAFile/data.txt: -------------------------------------------------------------------------------- 1 | lily,3 2 | anton,5 3 | levi,4 4 | amy,1 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_30.StoringRecords/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_30.StoringRecords/data.txt: -------------------------------------------------------------------------------- 1 | lilja,3 2 | anton,5 3 | leevi,4 4 | aamu,1 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_30.StoringRecords/src/main/java/Person.java: -------------------------------------------------------------------------------- 1 | 2 | public class Person { 3 | 4 | private String name; 5 | private int age; 6 | 7 | public Person(String name, int age) { 8 | this.name = name; 9 | this.age = age; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getAge() { 17 | return age; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return this.name + ", age: " + this.age; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_30.StoringRecords/tiedosto1.txt: -------------------------------------------------------------------------------- 1 | saul,32 2 | tina,30 3 | aaron,1 4 | matt,44 5 | lena,0 6 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_30.StoringRecords/tiedosto2.txt: -------------------------------------------------------------------------------- 1 | saul,41 2 | tina,9 3 | matt,13 4 | anton,42 5 | amy,0 6 | lily,13 7 | lena,41 8 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_31.SportStatistics/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part04-Part04_31.SportStatistics/data.csv: -------------------------------------------------------------------------------- 1 | ENCE,Vitality,9,16 2 | ENCE,Vitality,16,12 3 | ENCE,Vitality,9,16 4 | ENCE,Heroic,10,16 5 | SJ,ENCE,0,16 6 | SJ,ENCE,3,16 7 | FURIA,NRG,7,16 8 | FURIA,Prospects,16,1 -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_01.OneMinute/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_01.OneMinute/src/main/java/ClockHand.java: -------------------------------------------------------------------------------- 1 | 2 | public class ClockHand { 3 | 4 | private int value; 5 | private int limit; 6 | 7 | public ClockHand(int limit) { 8 | this.limit = limit; 9 | this.value = 0; 10 | } 11 | 12 | public void advance() { 13 | this.value = this.value + 1; 14 | 15 | if (this.value >= this.limit) { 16 | this.value = 0; 17 | } 18 | } 19 | 20 | public int value() { 21 | return this.value; 22 | } 23 | 24 | public String toString() { 25 | if (this.value < 10) { 26 | return "0" + this.value; 27 | } 28 | 29 | return "" + this.value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_01.OneMinute/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Program { 5 | 6 | public static void main(String[] args) { 7 | // You can test your program here 8 | Timer timer = new Timer(); 9 | 10 | while (true) { 11 | System.out.println(timer); 12 | timer.advance(); 13 | 14 | try { 15 | Thread.sleep(10); 16 | } catch (Exception e) { 17 | 18 | } 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_01.OneMinute/src/main/java/Timer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Timer { 12 | private ClockHand seconds; 13 | private ClockHand hundredths; 14 | 15 | public Timer() { 16 | this.seconds = new ClockHand(60); 17 | this.hundredths = new ClockHand(100); 18 | } 19 | 20 | public void advance() { 21 | this.hundredths.advance(); 22 | 23 | if (this.hundredths.value() == 0) { 24 | this.seconds.advance(); 25 | } 26 | } 27 | 28 | public String toString() { 29 | return seconds + ":" + hundredths; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_02.Book/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_02.Book/src/main/java/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Book { 12 | 13 | private String author; 14 | private String name; 15 | private int pages; 16 | 17 | public Book(String author, String name, int pages) { 18 | this.author = author; 19 | this.name = name; 20 | this.pages = pages; 21 | } 22 | 23 | public String getAuthor() { 24 | return this.author; 25 | } 26 | 27 | public String getName() { 28 | return this.name; 29 | } 30 | 31 | public int getPages() { 32 | return this.pages; 33 | } 34 | 35 | public String toString() { 36 | return this.author + ", " + this.name + ", " + this.pages + " pages"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_02.Book/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | public class Program { 3 | 4 | public static void main(String[] args) { 5 | // This is simply an empty main method where you are 6 | // free to experiment with your Book class. 7 | // An example that you can use for testing: 8 | 9 | 10 | Book b = new Book("J. K. Rowling", "Harry Potter and the Sorcerer's Stone", 223); 11 | System.out.println(b); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_03.Cube/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_03.Cube/src/main/java/Cube.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Cube { 12 | 13 | private int length; 14 | 15 | public Cube(int edgeLength) { 16 | this.length = edgeLength; 17 | } 18 | 19 | public int volume() { 20 | int volume = this.length * this.length * this.length; 21 | return volume; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "The length of the edge is " + this.length + " and the volume " + this.volume(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_03.Cube/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Program { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Experiment with your program here 10 | Cube oSheaJackson = new Cube(4); 11 | System.out.println(oSheaJackson.volume()); 12 | System.out.println(oSheaJackson); 13 | 14 | System.out.println(); 15 | 16 | Cube salt = new Cube(2); 17 | System.out.println(salt.volume()); 18 | System.out.println(salt); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_04.FitByte/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_04.FitByte/src/main/java/Fitbyte.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Fitbyte { 12 | private int age; 13 | private int restingHeartRate; 14 | 15 | public Fitbyte(int age, int restingHeartRate) { 16 | this.age = age; 17 | this.restingHeartRate = restingHeartRate; 18 | } 19 | 20 | public double targetHeartRate(double percentageOfMaximum) { 21 | double maximumHeartRate = 206.3 - (0.711 * this.age); 22 | return (maximumHeartRate - this.restingHeartRate) * (percentageOfMaximum) + this.restingHeartRate; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_04.FitByte/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | public class Program { 3 | 4 | public static void main(String[] args) { 5 | // This is an empty main method where you can experiment 6 | // with your Fitbyte class 7 | 8 | Fitbyte fitbyte = new Fitbyte(34, 62); 9 | 10 | double percentage = 0.5; 11 | 12 | while (percentage < 1.0) { 13 | double target = fitbyte.targetHeartRate(percentage); 14 | System.out.println("Target " + (percentage * 100) + "% of maximum: " + target); 15 | percentage += 0.1; 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_05.ConstructorOverload/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_05.ConstructorOverload/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // Test your class here 6 | Product tapeMeasure = new Product("Tape measure"); 7 | Product plaster = new Product("Plaster", "home improvement section"); 8 | Product tyre = new Product("Tyre", 5); 9 | 10 | System.out.println(tapeMeasure); 11 | System.out.println(plaster); 12 | System.out.println(tyre); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_05.ConstructorOverload/src/main/java/Product.java: -------------------------------------------------------------------------------- 1 | 2 | public class Product { 3 | 4 | private String name; 5 | private String location; 6 | private int weight; 7 | 8 | public Product(String name, String location, int weight) { 9 | this.name = name; 10 | this.location = location; 11 | this.weight = weight; 12 | } 13 | 14 | public Product(String name) { 15 | this(name, "shelf", 1); 16 | } 17 | 18 | public Product(String name, String location) { 19 | this(name, location, 1); 20 | } 21 | 22 | public Product(String name, int weight) { 23 | this(name, "shelf", weight); 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public int getWeight() { 31 | return weight; 32 | } 33 | 34 | public String getLocation() { 35 | return location; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return this.name + " (" + this.weight + " kg) can be found from the " + this.location; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_06.OverloadedCounter/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_06.OverloadedCounter/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // Test your counter here 6 | Counter count = new Counter(15); 7 | 8 | count.increase(); 9 | System.out.println(count); 10 | count.increase(10); 11 | System.out.println(count); 12 | count.increase(-10); 13 | System.out.println(count); 14 | count.decrease(); 15 | System.out.println(count); 16 | count.decrease(11); 17 | System.out.println(count); 18 | count.decrease(-11); 19 | System.out.println(count); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_06.OverloadedCounter/src/test/java/Utils.java: -------------------------------------------------------------------------------- 1 | 2 | import static org.junit.Assert.*; 3 | import fi.helsinki.cs.tmc.edutestutils.ReflectionUtils; 4 | 5 | public class Utils { 6 | 7 | public static Class getClass(String name) { 8 | try { 9 | return ReflectionUtils.findClass(name); 10 | } catch (AssertionError e) { 11 | fail("Have you created the class " + name + "?"); 12 | return null; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_07.NullPointerException/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_07.NullPointerException/src/test/java/NPEErrorTest.java: -------------------------------------------------------------------------------- 1 | 2 | import fi.helsinki.cs.tmc.edutestutils.Points; 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | @Points("05-07") 7 | public class NPEErrorTest { 8 | 9 | @Test 10 | public void causesANullPointerExceptionError() { 11 | try { 12 | NullPointerExceptionProgram.main(new String[]{}); 13 | } catch (NullPointerException e) { 14 | return; 15 | } 16 | 17 | fail("The program is supposed to cause a NullPointerException error, now it did not."); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_08.BiggestPetShop/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_08.BiggestPetShop/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class MainProgram { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | Pet hulda = new Pet("Hulda", "Golden retriever"); 10 | Person leo = new Person("Leo", hulda); 11 | 12 | System.out.println(leo); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_08.BiggestPetShop/src/main/java/Person.java: -------------------------------------------------------------------------------- 1 | 2 | public class Person { 3 | 4 | private String name; 5 | private Pet pet; 6 | 7 | public Person(String name, Pet pet) { 8 | this.name = name; 9 | this.pet = pet; 10 | } 11 | 12 | public Person(String name) { 13 | this(name, new Pet("Toothless", "dragon")); 14 | } 15 | 16 | public Person() { 17 | this("Lilo", new Pet("Stitch", "blue alien")); 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return this.name + ", " + "has a friend called " + pet.getName() + " (" + 23 | pet.getBreed() + ")"; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_08.BiggestPetShop/src/main/java/Pet.java: -------------------------------------------------------------------------------- 1 | 2 | public class Pet { 3 | 4 | private String name; 5 | private String breed; 6 | 7 | public Pet(String name, String breed) { 8 | this.name = name; 9 | this.breed = breed; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public String getBreed() { 17 | return breed; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_09.HealthStation/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_09.HealthStation/src/main/java/HealthStation.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Set; 3 | 4 | public class HealthStation { 5 | 6 | private int totalWeighings; 7 | 8 | public int weigh(Person person) { 9 | // return the weight of the person passed as the parameter 10 | totalWeighings++; 11 | return person.getWeight(); 12 | } 13 | 14 | public void feed(Person person) { 15 | person.setWeight(person.getWeight() + 1); 16 | } 17 | 18 | public int weighings() { 19 | return totalWeighings; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_09.HealthStation/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // write experimental code here to check how your program functions 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_10.CardPayments/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_10.CardPayments/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // write experimental main programs here 6 | PaymentTerminal unicafeExactum = new PaymentTerminal(); 7 | System.out.println(unicafeExactum); 8 | 9 | PaymentCard annesCard = new PaymentCard(2); 10 | 11 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 12 | 13 | boolean wasSuccessful = unicafeExactum.eatHeartily(annesCard); 14 | System.out.println("there was enough money: " + wasSuccessful); 15 | 16 | unicafeExactum.addMoneyToCard(annesCard, 100); 17 | 18 | wasSuccessful = unicafeExactum.eatHeartily(annesCard); 19 | System.out.println("there was enough money: " + wasSuccessful); 20 | 21 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 22 | 23 | System.out.println(unicafeExactum); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_10.CardPayments/src/main/java/PaymentCard.java: -------------------------------------------------------------------------------- 1 | 2 | public class PaymentCard { 3 | 4 | private double balance; 5 | 6 | public PaymentCard(double balance) { 7 | this.balance = balance; 8 | } 9 | 10 | public double balance() { 11 | return this.balance; 12 | } 13 | 14 | public void addMoney(double increase) { 15 | this.balance += increase; 16 | } 17 | 18 | public boolean takeMoney(double amount) { 19 | // implement the method so that it only takes money from the card if 20 | // the balance is at least the amount parameter. 21 | // returns true if successful and false otherwise 22 | if (this.balance >= amount) { 23 | this.balance -= amount; 24 | return true; 25 | } 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_11.ComparingApartments/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_11.ComparingApartments/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // you can write code here to try out your program 6 | Apartment manhattanStudioApt = new Apartment(1, 20, 1000); 7 | Apartment atlantaTwoBedroomApt = new Apartment(2, 38, 4200); 8 | Apartment bangorThreeBedroomApt = new Apartment(2, 23, 1500); 9 | 10 | System.out.println(manhattanStudioApt.moreExpensiveThan(atlantaTwoBedroomApt)); 11 | System.out.println(manhattanStudioApt.moreExpensiveThan(bangorThreeBedroomApt)); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_12.Song/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_12.Song/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // you can write code here for testing your program 6 | 7 | Song jackSparrow = new Song("The Lonely Island", "Jack Sparrow", 196); 8 | Song anotherSparrow = new Song("The Lonely Island", "Jack Sparrow", 196); 9 | 10 | if (jackSparrow.equals(anotherSparrow)) { 11 | System.out.println("Songs are equal."); 12 | } 13 | 14 | if (jackSparrow.equals("Another object")) { 15 | System.out.println("Strange things are afoot."); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_12.Song/src/main/java/Song.java: -------------------------------------------------------------------------------- 1 | 2 | public class Song { 3 | 4 | private String artist; 5 | private String name; 6 | private int durationInSeconds; 7 | 8 | public Song(String artist, String name, int durationInSeconds) { 9 | this.artist = artist; 10 | this.name = name; 11 | this.durationInSeconds = durationInSeconds; 12 | } 13 | 14 | public boolean equals(Object compared) { 15 | if (this == compared) { 16 | return true; 17 | } 18 | 19 | if (!(compared instanceof Song)) { 20 | return false; 21 | } 22 | 23 | Song comparedSong = (Song) compared; 24 | 25 | if (this.artist == comparedSong.artist 26 | && this.name == comparedSong.name 27 | && this.durationInSeconds == comparedSong.durationInSeconds) { 28 | return true; 29 | } 30 | 31 | return false; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return this.artist + ": " + this.name + " (" + this.durationInSeconds + " s)"; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_13.IdenticalTwins/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_13.IdenticalTwins/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // you can write code here to try out your program 6 | SimpleDate date = new SimpleDate(24, 3, 2017); 7 | SimpleDate date2 = new SimpleDate(23, 7, 2017); 8 | 9 | Person leo = new Person("Leo", date, 62, 9); 10 | Person lily = new Person("Lily", date2, 65, 8); 11 | 12 | if (leo.equals(lily)) { 13 | System.out.println("Is this quite correct?"); 14 | } else { 15 | System.out.println("Seems to work"); 16 | } 17 | 18 | Person leoWithDifferentWeight = new Person("Leo", date, 62, 10); 19 | 20 | if (leo.equals(leoWithDifferentWeight)) { 21 | System.out.println("Is this quite correct?"); 22 | } else { 23 | System.out.println("Seems to work"); 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_14.Books/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_14.Books/src/main/java/Book.java: -------------------------------------------------------------------------------- 1 | 2 | public class Book { 3 | 4 | private String name; 5 | private int publicationYear; 6 | 7 | public Book(String name, int publicationYear) { 8 | this.name = name; 9 | this.publicationYear = publicationYear; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public int getPublicationYear() { 17 | return publicationYear; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object compared) { 22 | if (this == compared) { 23 | return true; 24 | } 25 | 26 | if (!(compared instanceof Book)) { 27 | return false; 28 | } 29 | 30 | Book comparedBook = (Book) compared; 31 | 32 | if (this.name.equals(comparedBook.name) 33 | && this.publicationYear == comparedBook.publicationYear) { 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_15.Archive/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_15.Archive/src/main/java/Archive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Archive { 12 | private String identifier; 13 | private String name; 14 | 15 | public Archive(String initialIdentifier, String initialName){ 16 | this.identifier = initialIdentifier; 17 | this.name = initialName; 18 | } 19 | 20 | public String getIdentifier(){ 21 | return identifier; 22 | } 23 | 24 | public String getName(){ 25 | return name; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object compared){ 30 | if(this == compared) { 31 | return true; 32 | } 33 | 34 | if(!(compared instanceof Archive)){ 35 | return false; 36 | } 37 | 38 | Archive comparedItem = (Archive) compared; 39 | 40 | return this.identifier.equals(comparedItem.identifier); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_16.DatingApp/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_16.DatingApp/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | SimpleDate date = new SimpleDate(13, 2, 2015); 6 | System.out.println("Friday of the examined week is " + date); 7 | 8 | SimpleDate newDate = date.afterNumberOfDays(7); 9 | int week = 1; 10 | while (week <= 7) { 11 | System.out.println("Friday after " + week + " weeks is " + newDate); 12 | newDate = newDate.afterNumberOfDays(7); 13 | 14 | week = week + 1; 15 | } 16 | 17 | System.out.println("The date after 790 days from the examined Friday is ... try it out yourself!"); 18 | System.out.println("Try " + date.afterNumberOfDays(790)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_17.Money/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part05-Part05_17.Money/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | 6 | Money a = new Money(10, 0); 7 | Money b = new Money(3, 0); 8 | Money c = new Money(5, 0); 9 | 10 | System.out.println(a.lessThan(b)); // false 11 | System.out.println(b.lessThan(c)); // true 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_01.Menu/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_01.Menu/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Menu exactum = new Menu(); 5 | 6 | // When you have completed the method addMeal(String meal) 7 | // You can delete the comments below 8 | 9 | 10 | exactum.addMeal("Smoked salmon, white wine and butter sauce with basil"); 11 | exactum.addMeal("Seasonal green salad with apple-honey vinegarette"); 12 | exactum.addMeal("Roasted lamb in a red wine sauce"); 13 | 14 | // When you have completed the method printMeals() 15 | // you can remove the comment below 16 | 17 | exactum.printMeals(); 18 | 19 | // When you have completed the method clearMenu() 20 | // you can remove the comments below 21 | exactum.clearMenu(); 22 | exactum.printMeals(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_01.Menu/src/main/java/Menu.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class Menu { 5 | 6 | private ArrayList meals; 7 | 8 | public Menu() { 9 | this.meals = new ArrayList<>(); 10 | } 11 | 12 | // implement the required methods here 13 | public void addMeal(String meal) { 14 | if (this.meals.contains(meal)) { 15 | return; 16 | } else { 17 | this.meals.add(meal); 18 | } 19 | } 20 | 21 | public void printMeals() { 22 | for(String meal: meals){ 23 | System.out.println(meal); 24 | } 25 | } 26 | 27 | public void clearMenu() { 28 | this.meals.clear(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_02.Stack/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_02.Stack/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Try out your class here 7 | Stack s = new Stack(); 8 | System.out.println(s.isEmpty()); 9 | System.out.println(s.values()); 10 | s.add("Value"); 11 | System.out.println(s.isEmpty()); 12 | System.out.println(s.values()); 13 | String taken = s.take(); 14 | System.out.println(s.isEmpty()); 15 | System.out.println(s.values()); 16 | System.out.println(taken); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_02.Stack/src/main/java/Stack.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | 12 | import java.util.ArrayList; 13 | 14 | public class Stack { 15 | private ArrayList stack; 16 | 17 | public Stack(){ 18 | this.stack = new ArrayList<>(); 19 | } 20 | 21 | public boolean isEmpty(){ 22 | 23 | return this.stack.isEmpty(); 24 | 25 | } 26 | 27 | public void add(String value){ 28 | this.stack.add(0, value); 29 | } 30 | 31 | public ArrayList values(){ 32 | return this.stack; 33 | } 34 | 35 | public String take(){ 36 | 37 | return this.stack.remove(0); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_03.MessagingService/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_03.MessagingService/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Try out your class here 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_03.MessagingService/src/main/java/MessagingService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | 12 | import java.util.ArrayList; 13 | 14 | public class MessagingService { 15 | 16 | private ArrayList messages; 17 | 18 | public MessagingService(){ 19 | this.messages = new ArrayList<>(); 20 | } 21 | 22 | public void add(Message message){ 23 | if(message.getContent().length() <= 280){ 24 | messages.add(message); 25 | } 26 | } 27 | 28 | public ArrayList getMessages(){ 29 | return messages; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_04.PrintingACollection/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_04.PrintingACollection/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | // Try out your class here 7 | SimpleCollection j = new SimpleCollection("characters"); 8 | System.out.println(j); 9 | 10 | System.out.println(); 11 | 12 | j.add("magneto"); 13 | System.out.println(j); 14 | 15 | System.out.println(); 16 | 17 | j.add("mystique"); 18 | System.out.println(j); 19 | 20 | System.out.println(); 21 | 22 | j.add("phoenix"); 23 | System.out.println(j); 24 | 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_05.SantasWorkshop/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_05.SantasWorkshop/src/main/java/Gift.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * @author chadsisk 5 | */ 6 | public class Gift { 7 | private String name; 8 | private int weight; 9 | 10 | public Gift(String name, int weight){ 11 | this.name = name; 12 | this.weight = weight; 13 | } 14 | 15 | public String getName(){ 16 | return this.name; 17 | } 18 | 19 | public int getWeight(){ 20 | return this.weight; 21 | } 22 | 23 | public String toString(){ 24 | return this.name + " (" + this.weight + " kg)"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_05.SantasWorkshop/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | // use this main method to try out your classes! 7 | Gift book = new Gift("Harry Potter and the Philosopher's Stone", 2); 8 | 9 | Package gobble = new Package(); 10 | gobble.addGift(book); 11 | System.out.println(gobble.totalWeight()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_05.SantasWorkshop/src/main/java/Package.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * @author chadsisk 5 | */ 6 | 7 | import java.util.ArrayList; 8 | 9 | public class Package { 10 | 11 | private ArrayList gifts; 12 | 13 | public Package(){ 14 | this.gifts = new ArrayList<>(); 15 | } 16 | 17 | 18 | public void addGift(Gift gift){ 19 | this.gifts.add(gift); 20 | } 21 | 22 | public int totalWeight(){ 23 | 24 | if(gifts.isEmpty()){ 25 | return -1; 26 | } 27 | 28 | int totalWeight = 0; 29 | 30 | for(Gift gift : gifts){ 31 | totalWeight += gift.getWeight(); 32 | } 33 | 34 | return totalWeight; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_06.LongestInCollection/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_06.LongestInCollection/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | 7 | // Try out your class here 8 | SimpleCollection c = new SimpleCollection("characters"); 9 | System.out.println("Pisin: " + c.longest()); 10 | 11 | c.add("magneto"); 12 | c.add("mystique"); 13 | c.add("phoenix"); 14 | 15 | System.out.println("Longest: " + c.longest()); 16 | 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_06.LongestInCollection/src/main/java/SimpleCollection.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class SimpleCollection { 5 | 6 | private String name; 7 | private ArrayList elements; 8 | 9 | public SimpleCollection(String name) { 10 | this.name = name; 11 | this.elements = new ArrayList<>(); 12 | } 13 | 14 | public void add(String element) { 15 | this.elements.add(element); 16 | } 17 | 18 | public ArrayList getElements() { 19 | return this.elements; 20 | } 21 | 22 | public String longest(){ 23 | 24 | if(this.elements.isEmpty()){ 25 | return null; 26 | } 27 | 28 | String returnElement = this.elements.get(0); 29 | 30 | for(String element : elements){ 31 | if(returnElement.length() < element.length()){ 32 | returnElement = element; 33 | } 34 | } 35 | 36 | return returnElement; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_07.HeightOrder/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_07.HeightOrder/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Test your class here 6 | Room room = new Room(); 7 | room.add(new Person("Lea", 183)); 8 | room.add(new Person("Kenya", 182)); 9 | room.add(new Person("Auli", 186)); 10 | room.add(new Person("Nina", 172)); 11 | room.add(new Person("Terhi", 185)); 12 | 13 | while (!room.isEmpty()) { 14 | System.out.println(room.take()); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_08.CargoHold/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_08.CargoHold/src/main/java/Item.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | /** 8 | * 9 | * @author chadsisk 10 | */ 11 | public class Item { 12 | 13 | private String name; 14 | private int weight; 15 | 16 | public Item(String name, int weight) { 17 | this.name = name; 18 | this.weight = weight; 19 | } 20 | 21 | public String getName() { 22 | return this.name; 23 | } 24 | 25 | public int getWeight() { 26 | return this.weight; 27 | } 28 | 29 | public String toString() { 30 | return this.name + " (" + this.weight + " kg" + ")"; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_08.CargoHold/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // You can use the main to test your classes! 6 | Item book = new Item("Lord of the rings", 2); 7 | Item phone = new Item("Nokia 3210", 1); 8 | Item brick = new Item("brick", 4); 9 | 10 | Suitcase adasCase = new Suitcase(10); 11 | adasCase.addItem(book); 12 | adasCase.addItem(phone); 13 | 14 | Suitcase pekkasCase = new Suitcase(10); 15 | pekkasCase.addItem(brick); 16 | 17 | Hold hold = new Hold(1000); 18 | hold.addSuitcase(adasCase); 19 | hold.addSuitcase(pekkasCase); 20 | 21 | System.out.println("The suitcases in the hold contain the following items:"); 22 | hold.printItems(); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_09.SimpleDictionary/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_09.SimpleDictionary/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | // Try out how the different parts of the program work together 8 | // here 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | SimpleDictionary dictionary = new SimpleDictionary(); 12 | 13 | TextUI textUI = new TextUI(scanner, dictionary); 14 | textUI.start(); 15 | System.out.println(dictionary.translate("pike")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_09.SimpleDictionary/src/main/java/SimpleDictionary.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.HashMap; 3 | 4 | public class SimpleDictionary { 5 | 6 | private HashMap translations; 7 | 8 | public SimpleDictionary() { 9 | this.translations = new HashMap<>(); 10 | } 11 | 12 | public String translate(String word) { 13 | return this.translations.get(word); 14 | } 15 | 16 | public void add(String word, String translation) { 17 | this.translations.put(word, translation); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_10.TodoList/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_10.TodoList/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | 8 | // Here you can try out the combined functionality of your classes 9 | Scanner scanner = new Scanner(System.in); 10 | TodoList list = new TodoList(); 11 | list.add("read the course material"); 12 | list.add("watch the latest fool us"); 13 | list.add("take it easy"); 14 | 15 | list.print(); 16 | list.remove(2); 17 | 18 | System.out.println(); 19 | list.print(); 20 | 21 | UserInterface ui = new UserInterface(list, scanner); 22 | ui.start(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_10.TodoList/src/main/java/TodoList.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * @author chadsisk 5 | */ 6 | import java.util.ArrayList; 7 | 8 | public class TodoList { 9 | private ArrayList todos; 10 | 11 | public TodoList(){ 12 | this.todos = new ArrayList(); 13 | } 14 | 15 | public void add(String task){ 16 | this.todos.add(task); 17 | } 18 | 19 | public void remove(int number){ 20 | this.todos.remove(number - 1); 21 | } 22 | 23 | public void print(){ 24 | for(String todo : todos){ 25 | System.out.println((todos.indexOf(todo) + 1) + ": " + todo); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_11.Averages/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_11.Averages/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Program { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | GradeRegister register = new GradeRegister(); 10 | 11 | UserInterface ui = new UserInterface(register, scanner); 12 | ui.start(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_12.JokeManager/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_12.JokeManager/src/main/java/JokeManager.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * 5 | * @author chadsisk 6 | */ 7 | import java.util.ArrayList; 8 | import java.util.Random; 9 | 10 | public class JokeManager { 11 | private ArrayList jokes; 12 | 13 | public JokeManager(){ 14 | this.jokes = new ArrayList<>(); 15 | } 16 | 17 | public void addJoke(String joke){ 18 | this.jokes.add(joke); 19 | } 20 | 21 | public String drawJoke(){ 22 | if(this.jokes.isEmpty()){ 23 | return "Jokes are in short supply."; 24 | } else { 25 | Random draw = new Random(); 26 | int index = draw.nextInt(jokes.size()); 27 | return jokes.get(index); 28 | } 29 | } 30 | 31 | public void printJokes(){ 32 | for(String joke: this.jokes){ 33 | System.out.println(joke); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_12.JokeManager/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Program { 5 | 6 | public static void main(String[] args) { 7 | 8 | JokeManager jokes = new JokeManager(); 9 | 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | UserInterface userInterface = new UserInterface(jokes, scanner); 13 | 14 | userInterface.start(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_13.Exercises/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | extra_student_files: 3 | - src/test/java/TehtavienhallintaTest.java 4 | 5 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_13.Exercises/src/main/java/Exercise.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 4 | * @author chadsisk 5 | */ 6 | public class Exercise { 7 | 8 | private String name; 9 | private boolean completed; 10 | 11 | public Exercise(String name) { 12 | this.name = name; 13 | this.completed = false; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setCompleted(boolean completed) { 21 | this.completed = completed; 22 | } 23 | 24 | public boolean isCompleted() { 25 | return completed; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part06-Part06_13.Exercises/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | // update here your exercise progress 5 | public static int partsCompleted() { 6 | return 2; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_01.LiquidContainers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_02.LiquidContainers2/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_02.LiquidContainers2/src/main/java/Container.java: -------------------------------------------------------------------------------- 1 | 2 | public class Container { 3 | 4 | private int totalAmount; 5 | 6 | public Container() { 7 | this.totalAmount = 0; 8 | } 9 | 10 | public int contains() { 11 | return this.totalAmount; 12 | } 13 | 14 | public void add(int amount) { 15 | if (amount >= 0) { 16 | if ((totalAmount + amount) <= 100) { 17 | this.totalAmount += amount; 18 | } else { 19 | this.totalAmount = 100; 20 | } 21 | } 22 | } 23 | 24 | public void remove(int amount) { 25 | if (amount >= 0) { 26 | if ((totalAmount - amount) >= 0) { 27 | this.totalAmount -= amount; 28 | } else { 29 | this.totalAmount = 0; 30 | } 31 | } 32 | } 33 | 34 | public String toString() { 35 | return this.totalAmount + "/" + "100"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_02.LiquidContainers2/src/main/java/LiquidContainers2.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class LiquidContainers2 { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | Container firstContainer = new Container(); 9 | Container secondContainer = new Container(); 10 | 11 | UserInterface userInterface = new UserInterface(firstContainer, secondContainer, scanner); 12 | userInterface.start(); 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_03.Sorting/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_04.ReadymadeSortingAlgorithms/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_05.Searching/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_05.Searching/src/main/java/Book.java: -------------------------------------------------------------------------------- 1 | 2 | public class Book { 3 | 4 | private int id; 5 | private String name; 6 | 7 | public Book(int id, String name) { 8 | this.id = id; 9 | this.name = name; 10 | } 11 | 12 | public int getId() { 13 | return id; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "(id: " + id + "; name: " + name + ")"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_06.GradeStatistics/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_06.GradeStatistics/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | GradeRegister register = new GradeRegister(); 11 | 12 | // Create a new instance of UserInterface 13 | UserInterface userInterface = new UserInterface(scanner, register); 14 | 15 | // Call the method to start the program from UserInterface 16 | userInterface.start(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_07.RecipeSearch/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_07.RecipeSearch/recipes.txt: -------------------------------------------------------------------------------- 1 | Pancake dough 2 | 60 3 | milk 4 | egg 5 | flour 6 | sugar 7 | salt 8 | butter 9 | 10 | Meatballs 11 | 20 12 | ground meat 13 | egg 14 | breadcrumbs 15 | 16 | Tofu rolls 17 | 30 18 | tofu 19 | rice 20 | water 21 | carrot 22 | cucumber 23 | avocado 24 | wasabi 25 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_07.RecipeSearch/src/main/java/RecipeSearch.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.File; 3 | import java.nio.file.Paths; 4 | import java.util.ArrayList; 5 | import java.util.Scanner; 6 | 7 | public class RecipeSearch { 8 | 9 | public static void main(String[] args) { 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | System.out.println("File to read:"); 13 | 14 | String file = scanner.nextLine(); 15 | 16 | 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_08.BigYear/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /mooc-java-programming-i/part07-Part07_08.BigYear/src/main/java/mainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class mainProgram { 5 | 6 | public static void main(String[] args) { 7 | // NB! Do not create other scanner objects than the one below 8 | // if and when you create other classes, pass the scanner to them 9 | // as a parameter 10 | 11 | Scanner scan = new Scanner(System.in); 12 | 13 | } 14 | 15 | } 16 | --------------------------------------------------------------------------------