├── part05 ├── famous-malayan-tiger-640048-part05-Part05_02.Book-7492853 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Program.java │ │ └── Book.java │ │ └── main │ │ └── java │ │ ├── Program.java │ │ └── Book.java ├── famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Program.java │ │ └── Cube.java │ │ └── main │ │ └── java │ │ ├── Program.java │ │ └── Cube.java ├── famous-malayan-tiger-640048-part05-Part05_12.Song-7522061 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Main.java │ │ └── Song.java │ │ └── main │ │ └── java │ │ ├── Main.java │ │ └── Song.java ├── famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Program.java │ │ ├── Timer.java │ │ └── ClockHand.java │ │ └── main │ │ └── java │ │ ├── Program.java │ │ ├── Timer.java │ │ └── ClockHand.java ├── famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Fitbyte.java │ │ └── Program.java │ │ └── main │ │ └── java │ │ ├── Fitbyte.java │ │ └── Program.java ├── famous-malayan-tiger-640048-part05-Part05_14.Books-7522750 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Book.java │ │ └── Main.java │ │ └── main │ │ └── java │ │ ├── Book.java │ │ └── Main.java ├── famous-malayan-tiger-640048-part05-Part05_15.Archive-7524782 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Archive.java │ │ └── main │ │ └── java │ │ └── Archive.java ├── famous-malayan-tiger-640048-part05-Part05_16.DatingApp-7524218 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java ├── famous-malayan-tiger-640048-part05-Part05_17.Money-7524732 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── MainProgram.java │ │ └── main │ │ └── java │ │ └── MainProgram.java ├── famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── MainProgram.java │ │ ├── Pet.java │ │ └── Person.java │ │ └── main │ │ └── java │ │ ├── MainProgram.java │ │ ├── Pet.java │ │ └── Person.java ├── famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── HealthStation.java │ │ └── Main.java │ │ └── main │ │ └── java │ │ ├── HealthStation.java │ │ └── Main.java ├── famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── PaymentCard.java │ │ └── Main.java │ │ └── main │ │ └── java │ │ ├── PaymentCard.java │ │ └── Main.java ├── famous-malayan-tiger-640048-part05-Part05_13.IdenticalTwins-7522134 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java ├── famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── MainProgram.java │ │ └── Product.java │ │ └── main │ │ └── java │ │ ├── MainProgram.java │ │ └── Product.java ├── famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ ├── main │ │ ├── java │ │ │ ├── MainProgram.java │ │ │ └── Counter.java │ │ └── main │ │ │ └── java │ │ │ ├── MainProgram.java │ │ │ └── Counter.java │ │ └── test │ │ ├── java │ │ └── Utils.java │ │ └── test │ │ └── java │ │ └── Utils.java ├── famous-malayan-tiger-640048-part05-Part05_11.ComparingApartments-7521746 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java └── famous-malayan-tiger-640048-part05-Part05_07.NullPointerException-7513866 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ └── test │ ├── java │ └── NPEErrorTest.java │ └── test │ └── java │ └── NPEErrorTest.java ├── part06 ├── famous-malayan-tiger-640048-part06-Part06_01.Menu-7541117 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Menu.java │ │ └── main │ │ └── java │ │ └── Menu.java ├── famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Main.java │ │ └── Stack.java │ │ └── main │ │ └── java │ │ ├── Main.java │ │ └── Stack.java ├── famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Item.java │ │ ├── Main.java │ │ └── Hold.java │ │ └── main │ │ └── java │ │ ├── Item.java │ │ ├── Main.java │ │ └── Hold.java ├── famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── TodoList.java │ │ └── Main.java │ │ └── main │ │ └── java │ │ ├── TodoList.java │ │ └── Main.java ├── famous-malayan-tiger-640048-part06-Part06_11.Averages-7581639 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Program.java │ │ └── main │ │ └── java │ │ └── Program.java ├── famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Main.java │ │ ├── Gift.java │ │ └── Package.java │ │ └── main │ │ └── java │ │ ├── Main.java │ │ ├── Gift.java │ │ └── Package.java ├── famous-malayan-tiger-640048-part06-Part06_07.HeightOrder-7562378 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java ├── famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Program.java │ │ └── JokeManager.java │ │ └── main │ │ └── java │ │ ├── Program.java │ │ └── JokeManager.java ├── famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Main.java │ │ └── MessagingService.java │ │ └── main │ │ └── java │ │ ├── Main.java │ │ └── MessagingService.java ├── famous-malayan-tiger-640048-part06-Part06_04.PrintingACollection-7552143 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java ├── famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── Main.java │ │ └── SimpleCollection.java │ │ └── main │ │ └── java │ │ ├── Main.java │ │ └── SimpleCollection.java ├── famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ ├── SimpleDictionary.java │ │ └── Main.java │ │ └── main │ │ └── java │ │ ├── SimpleDictionary.java │ │ └── Main.java └── famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189 │ ├── .tmcparams │ ├── src │ ├── test │ │ ├── java │ │ │ └── ExerciseManagementTest.java │ │ └── test │ │ │ └── java │ │ │ └── ExerciseManagementTest.java │ └── main │ │ ├── java │ │ ├── MainProgram.java │ │ ├── Exercise.java │ │ └── ExerciseManagement.java │ │ └── main │ │ └── java │ │ ├── MainProgram.java │ │ └── Exercise.java │ └── .tmcproject.yml ├── part07 ├── famous-malayan-tiger-640048-part07-Part07_03.Sorting-7590224 │ ├── .tmcproject.yml │ └── .tmcparams ├── famous-malayan-tiger-640048-part07-Part07_05.Searching-7605244 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Book.java │ │ └── main │ │ └── java │ │ └── Book.java ├── famous-malayan-tiger-640048-part07-Part07_08.BigYear-7614471 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Bird.java │ │ └── main │ │ └── java │ │ └── Bird.java ├── famous-malayan-tiger-640048-part07-Part07_01.LiquidContainers-7586999 │ ├── .tmcproject.yml │ └── .tmcparams ├── famous-malayan-tiger-640048-part07-Part07_02.LiquidContainers2-7587051 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Container.java │ │ └── main │ │ └── java │ │ └── Container.java ├── famous-malayan-tiger-640048-part07-Part07_07.RecipeSearch-7612508 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── recipes.txt ├── famous-malayan-tiger-640048-part07-Part07_06.GradeStatistics-7605493 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ │ └── main │ │ ├── java │ │ └── Main.java │ │ └── main │ │ └── java │ │ └── Main.java └── famous-malayan-tiger-640048-part07-Part07_04.ReadymadeSortingAlgorithms-7590337 │ ├── .tmcproject.yml │ ├── .tmcparams │ └── src │ └── main │ ├── java │ └── Main.java │ └── main │ └── java │ └── Main.java ├── part04 ├── Program.java ├── DogAttributes.java ├── MainProgram.java ├── Multiplier.java ├── Door.java ├── Dog.java ├── Agent.java ├── Main.java ├── Film.java ├── NumberOfStrings.java ├── Person.java ├── Cubes.java ├── Room.java ├── YourFirstBankTransfer.java ├── Whistle.java ├── PrintingAFile.java ├── Gauge.java ├── Song.java ├── Item.java ├── TelevisionProgram.java ├── Account.java ├── Statistics.java ├── Books.java ├── Debt.java ├── DecreasingCounter.java ├── Product.java ├── RecordsFromAFile.java ├── PrintingASpecifiedFile.java ├── Items.java ├── PersonalInformation.java ├── PaymentCard.java ├── IsItInTheFile.java ├── MockInOut.java └── NumbersFromAFile.java ├── part01 ├── AdaLovelace.java ├── Sandbox.java ├── HiAdaLovelace.java ├── Dinosaur.java ├── OnceUponATime.java ├── Message.java ├── BooleanInput.java ├── Greeting.java ├── DoubleInput.java ├── IntegerInput.java ├── Orwell.java ├── SecondsInADay.java ├── Ancient.java ├── SpeedingTicket.java ├── MessageThreeTimes.java ├── CheckingTheAge.java ├── Adulthood.java ├── Password.java ├── Conversation.java ├── Positivity.java ├── MultiplicationFormula.java ├── SumOfTwoNumbers.java ├── Same.java ├── AverageOfTwoNumbers.java ├── AdditionFormula.java ├── LeapYear.java ├── SumOfThreeNumbers.java ├── CheckYourIndentation.java ├── LargerThanOrEqualTo.java ├── AverageOfThreeNumbers.java ├── VariousVariables.java ├── Story.java ├── DifferentTypesOfInput.java ├── GradesAndPoints.java └── OddOrEven.java ├── part02 ├── InAHoleInTheGround.java ├── Word.java ├── NumberUno.java ├── Squared.java ├── FromOneToParameter.java ├── FromParameterToOne.java ├── Summation.java ├── Counting.java ├── CountingToHundred.java ├── CarryOn.java ├── AbsoluteValue.java ├── AreWeThereYet.java ├── SquareRootOfSum.java ├── Factorial.java ├── SumOfASequence.java ├── Division.java ├── DivisibleByThree.java ├── Smallest.java ├── FromWhereToWhere.java ├── Greatest.java ├── Averaging.java ├── NumberOfNumbers.java ├── ComparingNumbers.java ├── SumOfASequenceTheSequel.java ├── SumOfNumbers.java ├── NumberOfNegativeNumbers.java ├── OnlyPositives.java ├── AverageOfNumbers.java ├── NumberAndSumOfNumbers.java ├── AverageOfPositiveNumbers.java └── Reprint.java ├── part03 ├── PrintThrice.java ├── IsItTrue.java ├── SumOfArray.java ├── Printer.java ├── FirstWords.java ├── LastWords.java ├── ArrayPrinter.java ├── ThirdElement.java ├── ListSize.java ├── LineByLine.java ├── SecondPlusThird.java ├── LastInList.java ├── AVClub.java ├── FirstAndLast.java ├── RememberTheseNumbers.java ├── Sum.java ├── SumOfAList.java ├── Login.java ├── RemoveLast.java ├── AgeOfTheOldest.java ├── NameOfTheOldest.java ├── OnTheList.java ├── OnlyTheseNumbers.java ├── GreatestInList.java ├── IndexOf.java ├── PrintInRange.java ├── IoobProgram.java ├── AverageOfAList.java ├── IndexWasNotFound.java ├── PersonalDetails.java └── Swap.java ├── README.md ├── .gitignore └── LICENSE /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_01.Menu-7541117/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_15.Archive-7524782/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_16.DatingApp-7524218/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_17.Money-7524732/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_11.Averages-7581639/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_03.Sorting-7590224/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_05.Searching-7605244/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_13.IdenticalTwins-7522134/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_07.HeightOrder-7562378/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_08.BigYear-7614471/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_11.ComparingApartments-7521746/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_04.PrintingACollection-7552143/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_01.LiquidContainers-7586999/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_02.LiquidContainers2-7587051/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_07.RecipeSearch-7612508/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_07.NullPointerException-7513866/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_06.GradeStatistics-7605493/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_04.ReadymadeSortingAlgorithms-7590337/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_15.Archive-7524782/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_17.Money-7524732/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_01.Menu-7541117/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_03.Sorting-7590224/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_08.BigYear-7614471/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_16.DatingApp-7524218/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_07.HeightOrder-7562378/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_11.Averages-7581639/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_05.Searching-7605244/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_07.RecipeSearch-7612508/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_13.IdenticalTwins-7522134/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_01.LiquidContainers-7586999/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_02.LiquidContainers2-7587051/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_06.GradeStatistics-7605493/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_07.NullPointerException-7513866/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_11.ComparingApartments-7521746/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_04.PrintingACollection-7552143/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_04.ReadymadeSortingAlgorithms-7590337/.tmcparams: -------------------------------------------------------------------------------- 1 | export error_msg_locale=en 2 | export runtime_params=() 3 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/test/java/ExerciseManagementTest.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | public class ExerciseManagementTest { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/test/test/java/ExerciseManagementTest.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | public class ExerciseManagementTest { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | force_new_sandbox: true 2 | extra_student_files: 3 | - src/test/java/TehtavienhallintaTest.java 4 | 5 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part01/Sandbox.java: -------------------------------------------------------------------------------- 1 | 2 | public class Sandbox { 3 | 4 | public static void main(String[] args) { 5 | // Write your program here 6 | System.out.print("Hello World!"); 7 | } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // Test your class here 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/src/main/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // Test your class here 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/main/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 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part02/InAHoleInTheGround.java: -------------------------------------------------------------------------------- 1 | public class InAHoleInTheGround { 2 | 3 | public static void main(String[] args) { 4 | printText(); 5 | } 6 | 7 | public static void printText() { 8 | System.out.println("In a hole in the ground there lived a method"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /part02/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 "Hellrox"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part02/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 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part04/Multiplier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @author bexx 4 | */ 5 | public class Multiplier { 6 | private int number; 7 | 8 | public Multiplier(int number) { 9 | this.number = number; 10 | } 11 | 12 | public int multiply(int number) { 13 | return this.number * number; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part02/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 number = Integer.valueOf(scanner.nextLine()); 10 | System.out.println((number * number)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_07.RecipeSearch-7612508/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 | -------------------------------------------------------------------------------- /part02/FromOneToParameter.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class FromOneToParameter { 4 | 5 | public static void main(String[] args) { 6 | printUntilNumber(5); 7 | } 8 | 9 | public static void printUntilNumber(int number) { 10 | for (int n = 1; n <= number; n++) { 11 | System.out.println(n); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/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(3); 7 | count.increase(); 8 | System.out.println(count.value()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /part02/FromParameterToOne.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class FromParameterToOne { 4 | 5 | public static void main(String[] args) { 6 | printFromNumberToOne(5); 7 | } 8 | 9 | public static void printFromNumberToOne(int number) { 10 | for (int n = number; n >= 1; n -= 1) { 11 | System.out.println(n); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/src/main/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(3); 7 | count.increase(); 8 | System.out.println(count.value()); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /part02/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 | -------------------------------------------------------------------------------- /part02/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 | for (int n = 0; n < num + 1; n++) { 11 | System.out.println(n); 12 | } 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Door { 12 | 13 | public void knock() { 14 | System.out.println("Who's there?"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Gift book = new Gift("Harry Potter and the Philosopher's Stone", 2); 5 | 6 | Package gifts = new Package(); 7 | gifts.addGift(book); 8 | System.out.println(gifts.totalWeight()); 9 | } 10 | } -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Dog { 12 | 13 | private String name; 14 | private String breed; 15 | private int age; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Gift book = new Gift("Harry Potter and the Philosopher's Stone", 2); 5 | 6 | Package gifts = new Package(); 7 | gifts.addGift(book); 8 | System.out.println(gifts.totalWeight()); 9 | } 10 | } -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part03/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 | System.out.print(word + word + word); 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![An old rock in the desert](https://i.imgur.com/li0AlIH.png) 2 | 3 | Solutions to the MOOC.fi Java Programming I & Java Programming II exercises - the University of Helsinki’s free massive open online course (MOOC) on programming! 4 | 5 | Folders are organized just like the parts in the course. However, actual .java files only contain solution codes and are ordered by the names of the exercise (without enumeration) 6 | -------------------------------------------------------------------------------- /part02/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 start = Integer.valueOf(scanner.nextLine()); 10 | 11 | for (int n = start; n < 101; n++) { 12 | System.out.println(n); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Author defined 2 | /p 3 | 4 | # Compiled class file 5 | *.class 6 | 7 | # Log file 8 | *.log 9 | 10 | # BlueJ files 11 | *.ctxt 12 | 13 | # Mobile Tools for Java (J2ME) 14 | .mtj.tmp/ 15 | 16 | # Package Files # 17 | *.jar 18 | *.war 19 | *.nar 20 | *.ear 21 | *.zip 22 | *.tar.gz 23 | *.rar 24 | 25 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 26 | hs_err_pid* 27 | -------------------------------------------------------------------------------- /part01/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 smh = Boolean.valueOf(scanner.nextLine()); 12 | System.out.println("True or false? " + smh); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part01/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 | 12 | String name = scanner.nextLine(); 13 | 14 | System.out.println("Hi " + name); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /part02/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 | while (true) { 9 | System.out.println("Carry on?"); 10 | String say = scanner.nextLine(); 11 | if (say.equals("no")) { 12 | break; 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part01/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 number = Double.valueOf(scanner.nextLine()); 12 | System.out.println("You gave the number " + number); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part01/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 number = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("You gave the number " + number); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part01/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 orwell = Integer.valueOf(scan.nextLine()); 12 | if (orwell == 1984) { 13 | System.out.println("Orwell"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/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 | -------------------------------------------------------------------------------- /part01/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 | System.out.println(days * 86400); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/src/main/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 | -------------------------------------------------------------------------------- /part02/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 number = Integer.valueOf(scanner.nextLine()); 10 | if (number < 0) { 11 | System.out.println((number * -1)); 12 | } else { 13 | System.out.println(number); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /part04/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 | 17 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part02/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 | if (number == 4) { 13 | break; 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /part02/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 first = Integer.valueOf(scanner.nextLine()); 10 | int second = Integer.valueOf(scanner.nextLine()); 11 | 12 | double sum = (double) first + second; 13 | System.out.println(Math.sqrt(sum)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part04/Film.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @author bexx 4 | */ 5 | public class Film { 6 | private String name; 7 | private int ageRating; 8 | 9 | public Film (String filmName, int filmAgeRating) { 10 | this.name = filmName; 11 | this.ageRating = filmAgeRating; 12 | } 13 | 14 | public String name() { 15 | return this.name; 16 | } 17 | 18 | public int ageRating() { 19 | return this.ageRating; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/src/main/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 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part04/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 | int count = 0; 9 | while (true) { 10 | String input = scanner.nextLine(); 11 | if (input.equals("end")) { 12 | break; 13 | } 14 | count++; 15 | } 16 | System.out.println(count); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/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 | Message firstSMS = new Message("bexx", "Some jibberish I'm about to send"); 8 | MessagingService geocell = new MessagingService(); 9 | 10 | geocell.add(firstSMS); 11 | System.out.println(geocell.getMessages()); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part03/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 | 9 | System.out.print("Give a string: "); 10 | String word = scanner.nextLine(); 11 | 12 | if (word.equals("true")) { 13 | System.out.println("You got it right!"); 14 | } else { 15 | System.out.println("Try again!"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part03/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, 3, 4, 2}; 7 | System.out.println(sumOfNumbersInArray(array)); 8 | } 9 | 10 | public static int sumOfNumbersInArray(int[] array) { 11 | // Write some code here 12 | int total = 0; 13 | for (int n: array) { 14 | total += n; 15 | } 16 | return total; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/src/main/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 | Message firstSMS = new Message("bexx", "Some jibberish I'm about to send"); 8 | MessagingService geocell = new MessagingService(); 9 | 10 | geocell.add(firstSMS); 11 | System.out.println(geocell.getMessages()); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part01/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 message = scanner.nextLine(); 12 | 13 | System.out.println(message); 14 | System.out.println(message); 15 | System.out.println(message); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/src/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Random; 4 | import java.util.Scanner; 5 | 6 | public class Program { 7 | 8 | public static void main(String[] args) { 9 | 10 | JokeManager manager = new JokeManager(); 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | UserInterface main = new UserInterface(manager, scanner); 14 | main.start(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part03/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 | for (int i: array) { 12 | for (int s =0; s < i; s++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(""); 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/src/main/main/java/Program.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Random; 4 | import java.util.Scanner; 5 | 6 | public class Program { 7 | 8 | public static void main(String[] args) { 9 | 10 | JokeManager manager = new JokeManager(); 11 | Scanner scanner = new Scanner(System.in); 12 | 13 | UserInterface main = new UserInterface(manager, scanner); 14 | main.start(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part02/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 num = Integer.valueOf(scanner.nextLine()); 11 | int fact = 1; 12 | 13 | for (int n = 1; n <= num; n++) { 14 | fact *= n; 15 | } 16 | 17 | System.out.println("Factorial: " + fact); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part04/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 user = scanner.nextLine(); 11 | if (user.equals("end")) { 12 | break; 13 | } 14 | 15 | int number = Integer.valueOf(user); 16 | System.out.println(number * number * number); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/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 | int size = Integer.valueOf(scanner.nextLine()); 11 | Cube newCube = new Cube(size); 12 | System.out.println(newCube.volume()); 13 | System.out.println(newCube); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/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 | -------------------------------------------------------------------------------- /part02/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 last = Integer.valueOf(scanner.nextLine()); 11 | int total = 0; 12 | 13 | for (int n = 0; n <= last; n++) { 14 | total += n; 15 | } 16 | System.out.println("The sum is " + total); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/src/main/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 | int size = Integer.valueOf(scanner.nextLine()); 11 | Cube newCube = new Cube(size); 12 | System.out.println(newCube.volume()); 13 | System.out.println(newCube); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/src/test/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_16.DatingApp-7524218/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // test your program here! 6 | SimpleDate someDate = new SimpleDate(24, 12, 1987); 7 | System.out.println(someDate); 8 | someDate.advance(15); 9 | System.out.println(someDate); 10 | 11 | SimpleDate something = someDate.afterNumberOfDays(45); 12 | System.out.println(something); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_16.DatingApp-7524218/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // test your program here! 6 | SimpleDate someDate = new SimpleDate(24, 12, 1987); 7 | System.out.println(someDate); 8 | someDate.advance(15); 9 | System.out.println(someDate); 10 | 11 | SimpleDate something = someDate.afterNumberOfDays(45); 12 | System.out.println(something); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part01/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 | if (age >= 18) { 13 | System.out.println("You are an adult"); 14 | } else { 15 | System.out.println("You are not an adult"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part01/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 pass = scan.nextLine(); 12 | 13 | if (pass.equals("Caput Draconis")) { 14 | System.out.println("Welcome!"); 15 | } else { 16 | System.out.println("Off with you!"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part02/Division.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | public class Division { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Once you have implemented the division method, you can 8 | // try it out here. Fopr example division(3,5); 9 | // should print "0.6" 10 | 11 | division(3, 5); 12 | } 13 | 14 | // implement the method here 15 | public static void division(int numerator, int denominator) { 16 | 17 | System.out.println(((double) numerator / denominator)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/src/main/java/Cube.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Cube { 5 | private int edgeLength; 6 | 7 | public Cube(int edgeLength) { 8 | this.edgeLength = edgeLength; 9 | } 10 | public int volume() { 11 | return this.edgeLength * this.edgeLength * this.edgeLength; 12 | } 13 | public String toString() { 14 | return "The length of the edge is " + this.edgeLength + " and the volume " + this.volume(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part01/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("Oh, how interesting. Tell me more!"); 13 | String second = scanner.nextLine(); 14 | System.out.println("Thanks for sharing!"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part03/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 words = scanner.nextLine(); 11 | 12 | if (words.equals("")) { 13 | break; 14 | } 15 | 16 | String[] splitz = words.split(" "); 17 | System.out.println(splitz[0]); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part03/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 words = scanner.nextLine(); 11 | 12 | if (words.equals("")) { 13 | break; 14 | } 15 | 16 | String[] splitz = words.split(" "); 17 | System.out.println(splitz[splitz.length - 1]); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Room { 12 | 13 | private String code; 14 | private int seats; 15 | 16 | public Room(String classCode, int numberOfSeats) { 17 | 18 | this.code = classCode; 19 | this.seats = numberOfSeats; 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /part04/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 matAcc = new Account("Matthews account", 1000); 8 | Account bekAcc = new Account("My account", 0); 9 | 10 | matAcc.withdrawal(100.0); 11 | bekAcc.deposit(100.0); 12 | 13 | System.out.println(matAcc); 14 | System.out.println(bekAcc); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_03.Cube-7492935/src/main/main/java/Cube.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Cube { 5 | private int edgeLength; 6 | 7 | public Cube(int edgeLength) { 8 | this.edgeLength = edgeLength; 9 | } 10 | public int volume() { 11 | return this.edgeLength * this.edgeLength * this.edgeLength; 12 | } 13 | public String toString() { 14 | return "The length of the edge is " + this.edgeLength + " and the volume " + this.volume(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part01/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 | if (number > 0) { 13 | System.out.println("The number is positive."); 14 | } else { 15 | System.out.println("The number is not positive"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part02/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 | 9 | divisibleByThreeInRange(2, 10); 10 | } 11 | 12 | public static void divisibleByThreeInRange(int beginning, int end) { 13 | 14 | for (int n = beginning; n <= end; n++) { 15 | if (n % 3 == 0) { 16 | System.out.println(n); 17 | } 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_07.HeightOrder-7562378/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | Room room = new Room(); 6 | room.add(new Person("Lea", 183)); 7 | room.add(new Person("Kenya", 182)); 8 | room.add(new Person("Auli", 186)); 9 | room.add(new Person("Nina", 172)); 10 | room.add(new Person("Terhi", 185)); 11 | 12 | while (!room.isEmpty()) { 13 | System.out.println(room.take()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part03/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; i++) { 13 | System.out.print(array[i]); 14 | if (i < array.length - 1) { 15 | System.out.print(", "); 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Whistle { 12 | 13 | private String sound; 14 | 15 | public Whistle(String whistleSound) { 16 | 17 | this.sound = whistleSound; 18 | 19 | } 20 | 21 | public void sound() { 22 | System.out.println(this.sound); 23 | } 24 | } -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/src/main/java/HealthStation.java: -------------------------------------------------------------------------------- 1 | 2 | public class HealthStation { 3 | private int count; 4 | 5 | public int weigh(Person person) { 6 | // return the weight of the person passed as the parameter 7 | this.count++; 8 | return person.getWeight(); 9 | } 10 | 11 | public void feed(Person person) { 12 | person.setWeight((person.getWeight() + 1)); 13 | } 14 | 15 | public int weighings() { 16 | return this.count; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/src/main/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_07.HeightOrder-7562378/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | Room room = new Room(); 6 | room.add(new Person("Lea", 183)); 7 | room.add(new Person("Kenya", 182)); 8 | room.add(new Person("Auli", 186)); 9 | room.add(new Person("Nina", 172)); 10 | room.add(new Person("Terhi", 185)); 11 | 12 | while (!room.isEmpty()) { 13 | System.out.println(room.take()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part03/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 | -------------------------------------------------------------------------------- /part04/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 | System.out.println(row); 13 | } 14 | } 15 | catch (Exception e) { 16 | System.out.println("Error: " + e.getMessage()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/src/main/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/src/main/java/Fitbyte.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Fitbyte { 5 | private int age; 6 | private int restHR; 7 | 8 | public Fitbyte(int age, int restingHeartRate) { 9 | this.age = age; 10 | this.restHR = restingHeartRate; 11 | } 12 | public double targetHeartRate(double percentageOfMaximum) { 13 | double maxHR = 206.3 - (0.711 * this.age); 14 | return (maxHR - this.restHR) * percentageOfMaximum + this.restHR; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/src/main/main/java/HealthStation.java: -------------------------------------------------------------------------------- 1 | 2 | public class HealthStation { 3 | private int count; 4 | 5 | public int weigh(Person person) { 6 | // return the weight of the person passed as the parameter 7 | this.count++; 8 | return person.getWeight(); 9 | } 10 | 11 | public void feed(Person person) { 12 | person.setWeight((person.getWeight() + 1)); 13 | } 14 | 15 | public int weighings() { 16 | return this.count; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_15.Archive-7524782/src/main/java/Archive.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Archive { 5 | private String name; 6 | private String identifier; 7 | 8 | public Archive(String identifier, String name) { 9 | this.name = name; 10 | this.identifier = identifier; 11 | } 12 | 13 | public String getIdentifier() { 14 | return this.identifier; 15 | } 16 | 17 | public String toString() { 18 | return this.identifier + ": " + this.name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_05.Searching-7605244/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 | -------------------------------------------------------------------------------- /part02/Smallest.java: -------------------------------------------------------------------------------- 1 | 2 | public class Smallest { 3 | 4 | public static int smallest(int number1, int number2) { 5 | // Write some code here 6 | // don't print anything inside this method 7 | // there must be a return in the end of the method 8 | if (number1 < number2) { 9 | return number1; 10 | } else { 11 | return number2; 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | int result = smallest(2, 7); 17 | System.out.println("Smallest: " + result); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/src/main/main/java/Fitbyte.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Fitbyte { 5 | private int age; 6 | private int restHR; 7 | 8 | public Fitbyte(int age, int restingHeartRate) { 9 | this.age = age; 10 | this.restHR = restingHeartRate; 11 | } 12 | public double targetHeartRate(double percentageOfMaximum) { 13 | double maxHR = 206.3 - (0.711 * this.age); 14 | return (maxHR - this.restHR) * percentageOfMaximum + this.restHR; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_15.Archive-7524782/src/main/main/java/Archive.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Archive { 5 | private String name; 6 | private String identifier; 7 | 8 | public Archive(String identifier, String name) { 9 | this.name = name; 10 | this.identifier = identifier; 11 | } 12 | 13 | public String getIdentifier() { 14 | return this.identifier; 15 | } 16 | 17 | public String toString() { 18 | return this.identifier + ": " + this.name; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_05.Searching-7605244/src/main/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/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 | -------------------------------------------------------------------------------- /part02/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 to = Integer.valueOf(scanner.nextLine()); 12 | System.out.println("Where from?"); 13 | int from = Integer.valueOf(scanner.nextLine()); 14 | 15 | for (int n = from; n <= to; n++) { 16 | System.out.println(n); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/src/main/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 | -------------------------------------------------------------------------------- /part02/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/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 | Scanner scanner = new Scanner(System.in); 9 | SimpleDictionary dictionary = new SimpleDictionary(); 10 | 11 | TextUI textUI = new TextUI(scanner, dictionary); 12 | textUI.start(); 13 | System.out.println(dictionary.translate("pike")); // prints the string "hauki" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part01/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 | 15 | System.out.println(first + " * " + second + " = " + (first * second)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /part01/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 first = Integer.valueOf(scanner.nextLine()); 12 | 13 | System.out.println("Give the second number:"); 14 | int second = Integer.valueOf(scanner.nextLine()); 15 | 16 | System.out.println("The sum of the numbers is " + (first + second)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_09.SimpleDictionary-7577212/src/main/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 | Scanner scanner = new Scanner(System.in); 9 | SimpleDictionary dictionary = new SimpleDictionary(); 10 | 11 | TextUI textUI = new TextUI(scanner, dictionary); 12 | textUI.start(); 13 | System.out.println(dictionary.translate("pike")); // prints the string "hauki" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/java/Item.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | public class Item { 6 | private String name; 7 | private int weight; 8 | 9 | public Item(String name, int weight) { 10 | this.name = name; 11 | this.weight = weight; 12 | } 13 | 14 | public String getName() { 15 | return this.name; 16 | } 17 | 18 | public int getWeight() { 19 | return this.weight; 20 | } 21 | 22 | public String toString() { 23 | return name + " (" + weight + " kg)"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part03/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 | 20 | int size = list.size(); 21 | System.out.println("In total: " + size); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/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 | Book Asimov = new Book("Isaac Asimov", "Foundation", 320); 14 | System.out.println(Asimov); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/main/java/Item.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | public class Item { 6 | private String name; 7 | private int weight; 8 | 9 | public Item(String name, int weight) { 10 | this.name = name; 11 | this.weight = weight; 12 | } 13 | 14 | public String getName() { 15 | return this.name; 16 | } 17 | 18 | public int getWeight() { 19 | return this.weight; 20 | } 21 | 22 | public String toString() { 23 | return name + " (" + weight + " kg)"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part01/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 the first string:"); 11 | String first = scan.nextLine(); 12 | System.out.println("Enter the 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 | -------------------------------------------------------------------------------- /part03/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 | while (true) { 10 | String text = scanner.nextLine(); 11 | if (text.equals("")) { 12 | break; 13 | } 14 | 15 | String[] split = text.split(" "); 16 | for (int i = 0; i < split.length; i++) { 17 | 18 | System.out.println(split[i]); 19 | } 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /part03/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/src/main/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 | Book Asimov = new Book("Isaac Asimov", "Foundation", 320); 14 | System.out.println(Asimov); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/java/Gift.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Gift { 5 | private String name; 6 | private int weight; 7 | 8 | public Gift(String name, int weight) { 9 | this.name = name; 10 | this.weight = weight; 11 | } 12 | 13 | public String getName() { 14 | return this.name; 15 | } 16 | 17 | public int getWeight() { 18 | return this.weight; 19 | } 20 | 21 | public String toString() { 22 | return this.name + " (" + this.weight + " kg)"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part04/Gauge.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @author bexx 4 | */ 5 | public class Gauge { 6 | private int value; 7 | 8 | public Gauge() { 9 | this.value = 0; 10 | } 11 | 12 | public void increase() { 13 | if (this.value < 5) { 14 | this.value++; 15 | } 16 | } 17 | 18 | public void decrease() { 19 | if (this.value > 1) { 20 | this.value -= 1; 21 | } 22 | } 23 | 24 | public int value() { 25 | return this.value; 26 | } 27 | 28 | public boolean full() { 29 | return this.value == 5; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/main/java/Gift.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Gift { 5 | private String name; 6 | private int weight; 7 | 8 | public Gift(String name, int weight) { 9 | this.name = name; 10 | this.weight = weight; 11 | } 12 | 13 | public String getName() { 14 | return this.name; 15 | } 16 | 17 | public int getWeight() { 18 | return this.weight; 19 | } 20 | 21 | public String toString() { 22 | return this.name + " (" + this.weight + " kg)"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/main/java/Exercise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Exercise{ 5 | 6 | private String name; 7 | private boolean completed; 8 | 9 | public Exercise(String name) { 10 | this.name = name; 11 | this.completed = false; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setCompleted(boolean completed) { 19 | this.completed = completed; 20 | } 21 | 22 | public boolean isCompleted() { 23 | return completed; 24 | } 25 | } -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/main/main/java/Exercise.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Exercise{ 5 | 6 | private String name; 7 | private boolean completed; 8 | 9 | public Exercise(String name) { 10 | this.name = name; 11 | this.completed = false; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setCompleted(boolean completed) { 19 | this.completed = completed; 20 | } 21 | 22 | public boolean isCompleted() { 23 | return completed; 24 | } 25 | } -------------------------------------------------------------------------------- /part01/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 = (first + second) / (double) 2; 15 | 16 | System.out.println("The average is " + average); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/java/Package.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | 6 | public class Package { 7 | private ArrayList collection; 8 | 9 | public Package() { 10 | this.collection = new ArrayList<>(); 11 | } 12 | 13 | public void addGift(Gift gift) { 14 | this.collection.add(gift); 15 | } 16 | 17 | public int totalWeight() { 18 | int total = 0; 19 | for (Gift g: collection) { 20 | total += g.getWeight(); 21 | } 22 | return total; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part03/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 | 21 | int index = list.size() - 1; 22 | System.out.println(list.get(index)); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Song { 12 | private String name; 13 | private int length; 14 | 15 | public Song(String name, int length) { 16 | this.name = name; 17 | this.length = length; 18 | } 19 | 20 | public String name() { 21 | return this.name; 22 | } 23 | 24 | public int length() { 25 | return this.length; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_05.SantasWorkshop-7552328/src/main/main/java/Package.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | 6 | public class Package { 7 | private ArrayList collection; 8 | 9 | public Package() { 10 | this.collection = new ArrayList<>(); 11 | } 12 | 13 | public void addGift(Gift gift) { 14 | this.collection.add(gift); 15 | } 16 | 17 | public int totalWeight() { 18 | int total = 0; 19 | for (Gift g: collection) { 20 | total += g.getWeight(); 21 | } 22 | return total; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part01/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 | 13 | System.out.println("Give the second number:"); 14 | int second = Integer.valueOf(scanner.nextLine()); 15 | 16 | // result = first + second; 17 | System.out.println(first + " + " + second + " = " + (first + second)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/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(30, 60); 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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_07.NullPointerException-7513866/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_04.FitByte-7493048/src/main/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(30, 60); 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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_07.NullPointerException-7513866/src/test/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 | -------------------------------------------------------------------------------- /part03/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 | while (true) { 10 | String text = scanner.nextLine(); 11 | if (text.equals("")) { 12 | break; 13 | } 14 | 15 | String[] splitav = text.split(" "); 16 | for (int i = 0; i < splitav.length; i++) { 17 | if (splitav[i].contains("av")) { 18 | System.out.println(splitav[i]); 19 | } 20 | } 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part01/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 % 100 == 0 && year % 400 == 0) { 13 | System.out.println("The year is a leap year"); 14 | } else if (year % 4 == 0 && year % 100 != 0) { 15 | System.out.println("The year is a leap year"); 16 | } else { 17 | System.out.println("The year is not a leap year"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part02/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; 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 | -------------------------------------------------------------------------------- /part02/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 | int count = 0; 9 | 10 | while (true) { 11 | System.out.println("Give a number:"); 12 | int number = Integer.valueOf(scanner.nextLine()); 13 | if (number == 0) { 14 | break; 15 | } 16 | 17 | if (number != 0) { 18 | count = count + 1; 19 | } 20 | } 21 | System.out.println("Number of numbers: " + count); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part03/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 | int last = list.size() - 1; 21 | System.out.println(list.get(0)); 22 | System.out.println(list.get(last)); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_11.ComparingApartments-7521746/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, 16, 5500); 7 | Apartment atlantaTwoBedroomApt = new Apartment(2, 38, 4200); 8 | Apartment bangorThreeBedroomApt = new Apartment(3, 78, 2500); 9 | 10 | System.out.println(manhattanStudioApt.moreExpensiveThan(atlantaTwoBedroomApt)); 11 | System.out.println(bangorThreeBedroomApt.moreExpensiveThan(atlantaTwoBedroomApt)); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/src/main/java/MessagingService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class MessagingService { 8 | private ArrayList messages; 9 | 10 | public MessagingService() { 11 | this.messages = new ArrayList<>(); 12 | } 13 | 14 | public void add(Message message) { 15 | if (message.getContent().length() <= 280) { 16 | this.messages.add(message); 17 | } 18 | } 19 | 20 | public ArrayList getMessages() { 21 | return this.messages; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_11.ComparingApartments-7521746/src/main/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, 16, 5500); 7 | Apartment atlantaTwoBedroomApt = new Apartment(2, 38, 4200); 8 | Apartment bangorThreeBedroomApt = new Apartment(3, 78, 2500); 9 | 10 | System.out.println(manhattanStudioApt.moreExpensiveThan(atlantaTwoBedroomApt)); 11 | System.out.println(bangorThreeBedroomApt.moreExpensiveThan(atlantaTwoBedroomApt)); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_03.MessagingService-7541723/src/main/main/java/MessagingService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class MessagingService { 8 | private ArrayList messages; 9 | 10 | public MessagingService() { 11 | this.messages = new ArrayList<>(); 12 | } 13 | 14 | public void add(Message message) { 15 | if (message.getContent().length() <= 280) { 16 | this.messages.add(message); 17 | } 18 | } 19 | 20 | public ArrayList getMessages() { 21 | return this.messages; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/src/main/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 | -------------------------------------------------------------------------------- /part03/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/src/main/java/Timer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Timer { 5 | private ClockHand hundredths; 6 | private ClockHand seconds; 7 | 8 | public Timer() { 9 | this.hundredths = new ClockHand(100); 10 | this.seconds = new ClockHand(60); 11 | } 12 | 13 | public void advance() { 14 | this.hundredths.advance(); 15 | 16 | if (this.hundredths.value() == 0) { 17 | this.seconds.advance(); 18 | } 19 | } 20 | 21 | public String toString() { 22 | return this.seconds + ":" + this.hundredths; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part02/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 first = Integer.valueOf(scanner.nextLine()); 10 | int second = Integer.valueOf(scanner.nextLine()); 11 | 12 | if (first > second) { 13 | System.out.println(first + " is greater than " + second); 14 | } else if (first < second) { 15 | System.out.println(first + " is smaller than " + second); 16 | } else { 17 | System.out.println(first + " is equal to " + second); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/src/main/main/java/Timer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Timer { 5 | private ClockHand hundredths; 6 | private ClockHand seconds; 7 | 8 | public Timer() { 9 | this.hundredths = new ClockHand(100); 10 | this.seconds = new ClockHand(60); 11 | } 12 | 13 | public void advance() { 14 | this.hundredths.advance(); 15 | 16 | if (this.hundredths.value() == 0) { 17 | this.seconds.advance(); 18 | } 19 | } 20 | 21 | public String toString() { 22 | return this.seconds + ":" + this.hundredths; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/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() + " (" + pet.getBreed() + ")"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /part02/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 first = Integer.valueOf(scanner.nextLine()); 11 | 12 | System.out.println("Second number?"); 13 | int last = Integer.valueOf(scanner.nextLine()); 14 | 15 | int total = 0; 16 | 17 | for (int n = first; n <= last; n++) { 18 | total += n; 19 | } 20 | 21 | System.out.println("The sum is " + total); 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_08.BiggestPetShop-7521583/src/main/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() + " (" + pet.getBreed() + ")"; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /part02/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 summery = 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 | summery = summery + number; 21 | } 22 | } 23 | System.out.println("Sum of the numbers: " + summery); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_01.Menu-7541117/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 (!(meals.contains(meal))) { 15 | meals.add(meal); 16 | } 17 | } 18 | 19 | public void printMeals() { 20 | for (String meal: meals) { 21 | System.out.println(meal); 22 | } 23 | } 24 | 25 | public void clearMenu() { 26 | meals.clear(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /part02/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 | int count = 0; 9 | 10 | while (true) { 11 | System.out.println("Give a number:"); 12 | int number = Integer.valueOf(scanner.nextLine()); 13 | 14 | if (number == 0) { 15 | break; 16 | } 17 | 18 | if (number < 0) { 19 | count = count + 1; 20 | } 21 | } 22 | System.out.println("Number of negative numbers: " + count); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_01.Menu-7541117/src/main/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 (!(meals.contains(meal))) { 15 | meals.add(meal); 16 | } 17 | } 18 | 19 | public void printMeals() { 20 | for (String meal: meals) { 21 | System.out.println(meal); 22 | } 23 | } 24 | 25 | public void clearMenu() { 26 | meals.clear(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_11.Averages-7581639/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 | // GradeRegister register = new GradeRegister(); 15 | // register.addGradeBasedOnPoints(93); 16 | // register.addGradeBasedOnPoints(91); 17 | // register.addGradeBasedOnPoints(92); 18 | // 19 | // System.out.println(register.averageOfPoints()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_11.Averages-7581639/src/main/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 | // GradeRegister register = new GradeRegister(); 15 | // register.addGradeBasedOnPoints(93); 16 | // register.addGradeBasedOnPoints(91); 17 | // register.addGradeBasedOnPoints(92); 18 | // 19 | // System.out.println(register.averageOfPoints()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part01/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 first = Integer.valueOf(scanner.nextLine()); 12 | 13 | System.out.println("Give the second number:"); 14 | int second = Integer.valueOf(scanner.nextLine()); 15 | 16 | System.out.println("Give the third number:"); 17 | int third = Integer.valueOf(scanner.nextLine()); 18 | 19 | System.out.println("The sum of the numbers is " + (first + second + third)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part04/Statistics.java: -------------------------------------------------------------------------------- 1 | /* 2 | author @bexx 3 | */ 4 | 5 | public class Statistics { 6 | private int count; 7 | private int total; 8 | 9 | public Statistics() { 10 | this.count = 0; 11 | this.total = 0; 12 | } 13 | 14 | public void addNumber(int number) { 15 | this.count += 1; 16 | this.total += number; 17 | } 18 | 19 | public int getCount() { 20 | return this.count; 21 | } 22 | 23 | public int sum() { 24 | return this.total; 25 | } 26 | 27 | public double average() { 28 | if (this.count != 0) { 29 | return (double) this.total / this.count; 30 | } else { 31 | return 0; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_01.OneMinute-7492744/src/main/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_04.PrintingACollection-7552143/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/src/main/java/TodoList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | import java.util.Scanner; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | 9 | public class TodoList { 10 | private ArrayList list; 11 | 12 | public TodoList() { 13 | this.list = new ArrayList<>(); 14 | } 15 | 16 | public void add(String task) { 17 | list.add(task); 18 | } 19 | 20 | public void print() { 21 | for (String item: list) { 22 | System.out.println((list.indexOf(item) + 1) + ": " + item); 23 | } 24 | } 25 | 26 | public void remove(int number) { 27 | list.remove(number - 1); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /part04/Books.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @author bexx 4 | */ 5 | public class Books { 6 | private String title; 7 | private int pages; 8 | private int published; 9 | 10 | public Books(String title, int pages, int published) { 11 | this.title = title; 12 | this.pages = pages; 13 | this.published = published; 14 | } 15 | 16 | public String toString() { 17 | return this.title + ", " + this.pages + " pages, " + this.published; 18 | } 19 | 20 | public String getTitle() { 21 | return this.title; 22 | } 23 | 24 | public int getPages() { 25 | return this.pages; 26 | } 27 | 28 | public int getPublished() { 29 | return this.published; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Debt { 12 | private double balance; 13 | private double interestRate; 14 | 15 | public Debt (double initialBalance, double initialInterestRate) { 16 | this.balance = initialBalance; 17 | this.interestRate = initialInterestRate; 18 | } 19 | 20 | public void printBalance() { 21 | System.out.println(this.balance); 22 | } 23 | 24 | public void waitOneYear() { 25 | this.balance = this.balance * (this.interestRate); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_04.PrintingACollection-7552143/src/main/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 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/src/main/main/java/TodoList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | import java.util.Scanner; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | 9 | public class TodoList { 10 | private ArrayList list; 11 | 12 | public TodoList() { 13 | this.list = new ArrayList<>(); 14 | } 15 | 16 | public void add(String task) { 17 | list.add(task); 18 | } 19 | 20 | public void print() { 21 | for (String item: list) { 22 | System.out.println((list.indexOf(item) + 1) + ": " + item); 23 | } 24 | } 25 | 26 | public void remove(int number) { 27 | list.remove(number - 1); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_13.IdenticalTwins-7522134/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | SimpleDate date = new SimpleDate(24, 3, 2017); 6 | SimpleDate date2 = new SimpleDate(23, 7, 2017); 7 | 8 | Person leo = new Person("Leo", date, 62, 9); 9 | Person lily = new Person("Lily", date2, 65, 8); 10 | 11 | if (leo.equals(lily)) { 12 | System.out.println("Is this quite correct?"); 13 | } 14 | 15 | Person leoWithDifferentWeight = new Person("Leo", date, 62, 10); 16 | 17 | if (leo.equals(leoWithDifferentWeight)) { 18 | System.out.println("Is this quite correct?"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part01/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 | System.out.println("Give the first number:"); 9 | int first = Integer.valueOf(scan.nextLine()); 10 | System.out.println("Give the second number:"); 11 | int second = Integer.valueOf(scan.nextLine()); 12 | if (first > second) { 13 | System.out.println("Greater number is: " + first); 14 | } else if (first < second) { 15 | System.out.println("Greater number is: " + second); 16 | } else { 17 | System.out.println("The numbers are equal!"); 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part03/Sum.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class Sum { 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 | System.out.println(sum(numbers)); 14 | 15 | numbers.add(5); 16 | numbers.add(1); 17 | System.out.println(sum(numbers)); 18 | } 19 | 20 | public static int sum(ArrayList numbers) { 21 | 22 | int sum = 0; 23 | 24 | for (int n: numbers) { 25 | sum += n; 26 | } 27 | 28 | return sum; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_13.IdenticalTwins-7522134/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | SimpleDate date = new SimpleDate(24, 3, 2017); 6 | SimpleDate date2 = new SimpleDate(23, 7, 2017); 7 | 8 | Person leo = new Person("Leo", date, 62, 9); 9 | Person lily = new Person("Lily", date2, 65, 8); 10 | 11 | if (leo.equals(lily)) { 12 | System.out.println("Is this quite correct?"); 13 | } 14 | 15 | Person leoWithDifferentWeight = new Person("Leo", date, 62, 10); 16 | 17 | if (leo.equals(leoWithDifferentWeight)) { 18 | System.out.println("Is this quite correct?"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part01/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 | 17 | double average = (first + second + third) / (double) 3; 18 | System.out.println("The average is " + average); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /part02/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 | System.out.println("Unsuitable number"); 15 | continue; 16 | } 17 | 18 | if (number == 0) { 19 | break; 20 | } 21 | 22 | if (number > 0) { 23 | System.out.println((number * number)); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part04/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 >= 1) { 19 | this.value -= 1; 20 | } 21 | } 22 | 23 | // the other methods go here 24 | public void reset() { 25 | this.value = 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part03/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 (int n: list) { 25 | sum += n; 26 | } 27 | 28 | System.out.println("Sum: " + sum); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part02/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 count = 0; 10 | int total = 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 | count = count + 1; 22 | total = total + number; 23 | } 24 | } 25 | System.out.println("Average of the numbers: " + ((double) total / count)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part03/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 | 9 | System.out.print("Enter username: "); 10 | String user = scanner.nextLine(); 11 | System.out.print("Enter password: "); 12 | String pass = scanner.nextLine(); 13 | 14 | if (user.equals("alex") && pass.equals("sunshine")) { 15 | System.out.println("You have successfully logged in!"); 16 | } else if (user.equals("emma") && pass.equals("haskell")) { 17 | System.out.println("You have successfully logged in!"); 18 | } else { 19 | System.out.println("Incorrect username or password!"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /part03/RemoveLast.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | 4 | public class RemoveLast { 5 | 6 | public static void main(String[] args) { 7 | // Try your method in here 8 | ArrayList strings = new ArrayList<>(); 9 | 10 | strings.add("First"); 11 | strings.add("Second"); 12 | strings.add("Third"); 13 | 14 | System.out.println(strings); 15 | 16 | removeLast(strings); 17 | removeLast(strings); 18 | 19 | System.out.println(strings); 20 | } 21 | 22 | public static void removeLast(ArrayList strings) { 23 | int number = strings.size(); 24 | 25 | if (strings.size() > 0) { 26 | strings.remove(number - 1); 27 | } 28 | 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /part04/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 bexx 10 | */ 11 | public class Product { 12 | 13 | private int quantity; 14 | private double price; 15 | private String name; 16 | 17 | public Product(String initialName, double initialPrice, int initialQuantity) { 18 | 19 | this.quantity = initialQuantity; 20 | this.price = initialPrice; 21 | this.name = initialName; 22 | 23 | } 24 | 25 | public void printProduct() { 26 | System.out.println(this.name + ", price" + this.price + ", " + this.quantity + " pcs"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /part04/RecordsFromAFile.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.file.Paths; 3 | import java.util.Scanner; 4 | 5 | public class RecordsFromAFile { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.println("Name of the file:"); 10 | String file = scanner.nextLine(); 11 | 12 | try (Scanner csv = new Scanner(Paths.get(file))) { 13 | while (csv.hasNextLine()) { 14 | String line = csv.nextLine(); 15 | String[] parts = line.split(","); 16 | System.out.println(parts[0] + ", age: " + parts[1] + " years"); 17 | } 18 | } 19 | catch (Exception e) { 20 | System.out.println("Error: " + e.getMessage()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Item book = new Item("Lord of the rings", 2); 5 | Item phone = new Item("Nokia 3210", 1); 6 | Item brick = new Item("brick", 4); 7 | 8 | Suitcase adasCase = new Suitcase(10); 9 | adasCase.addItem(book); 10 | adasCase.addItem(phone); 11 | 12 | Suitcase pekkasCase = new Suitcase(10); 13 | pekkasCase.addItem(brick); 14 | 15 | Hold hold = new Hold(1000); 16 | hold.addSuitcase(adasCase); 17 | hold.addSuitcase(pekkasCase); 18 | 19 | System.out.println("The suitcases in the hold contain the following items:"); 20 | hold.printItems(); 21 | } 22 | } -------------------------------------------------------------------------------- /part04/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 | System.out.println("Which file should have its contents printed?"); 10 | String path = scanner.nextLine(); 11 | System.out.println(path); 12 | 13 | try (Scanner text = new Scanner(Paths.get(path))) { 14 | 15 | while (text.hasNextLine()) { 16 | String row = text.nextLine(); 17 | System.out.println(row); 18 | } 19 | } 20 | catch (Exception e) { 21 | System.out.println("Error: " + e.getMessage()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/src/main/java/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Book { 5 | private String author; 6 | private String title; 7 | private int pages; 8 | 9 | public Book(String author, String title, int pages) { 10 | this.author = author; 11 | this.title = title; 12 | this.pages = pages; 13 | } 14 | 15 | public String getAuthor() { 16 | return this.author; 17 | } 18 | 19 | public String getName() { 20 | return this.title; 21 | } 22 | 23 | public int getPages() { 24 | return this.pages; 25 | } 26 | 27 | public String toString() { 28 | return this.author + ", " + this.title + ", " + this.pages + " pages"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | public static void main(String[] args) { 4 | Item book = new Item("Lord of the rings", 2); 5 | Item phone = new Item("Nokia 3210", 1); 6 | Item brick = new Item("brick", 4); 7 | 8 | Suitcase adasCase = new Suitcase(10); 9 | adasCase.addItem(book); 10 | adasCase.addItem(phone); 11 | 12 | Suitcase pekkasCase = new Suitcase(10); 13 | pekkasCase.addItem(brick); 14 | 15 | Hold hold = new Hold(1000); 16 | hold.addSuitcase(adasCase); 17 | hold.addSuitcase(pekkasCase); 18 | 19 | System.out.println("The suitcases in the hold contain the following items:"); 20 | hold.printItems(); 21 | } 22 | } -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_02.Book-7492853/src/main/main/java/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Book { 5 | private String author; 6 | private String title; 7 | private int pages; 8 | 9 | public Book(String author, String title, int pages) { 10 | this.author = author; 11 | this.title = title; 12 | this.pages = pages; 13 | } 14 | 15 | public String getAuthor() { 16 | return this.author; 17 | } 18 | 19 | public String getName() { 20 | return this.title; 21 | } 22 | 23 | public int getPages() { 24 | return this.pages; 25 | } 26 | 27 | public String toString() { 28 | return this.author + ", " + this.title + ", " + this.pages + " pages"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part04/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("Name: "); 15 | String name = scanner.nextLine(); 16 | 17 | if (name.equals("")) { 18 | break; 19 | } 20 | 21 | items.add(new Item(name)); 22 | } 23 | 24 | System.out.println(""); 25 | for (Item item: items) { 26 | System.out.println(item); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | Stack s = new Stack(); 7 | System.out.println(s.isEmpty()); 8 | System.out.println(s.values()); 9 | s.add("Value"); 10 | System.out.println(s.isEmpty()); 11 | System.out.println(s.values()); 12 | String taken = s.take(); 13 | System.out.println(s.isEmpty()); 14 | System.out.println(s.values()); 15 | System.out.println(taken); 16 | 17 | s.add("1"); 18 | s.add("2"); 19 | s.add("3"); 20 | s.add("4"); 21 | s.add("5"); 22 | 23 | while (!s.isEmpty()) { 24 | System.out.println(s.take()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part01/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 | -------------------------------------------------------------------------------- /part03/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 | 9 | int holder = 0; 10 | 11 | while (true) { 12 | String users = scanner.nextLine(); 13 | 14 | if (users.equals("")) { 15 | break; 16 | } 17 | 18 | String[] splitz = users.split(","); 19 | 20 | int oldest = Integer.valueOf(splitz[1]); 21 | 22 | if (oldest > holder) { 23 | holder = oldest; 24 | } 25 | 26 | } 27 | 28 | System.out.println("Age of the oldes: " + holder); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | 6 | Stack s = new Stack(); 7 | System.out.println(s.isEmpty()); 8 | System.out.println(s.values()); 9 | s.add("Value"); 10 | System.out.println(s.isEmpty()); 11 | System.out.println(s.values()); 12 | String taken = s.take(); 13 | System.out.println(s.isEmpty()); 14 | System.out.println(s.values()); 15 | System.out.println(taken); 16 | 17 | s.add("1"); 18 | s.add("2"); 19 | s.add("3"); 20 | s.add("4"); 21 | s.add("5"); 22 | 23 | while (!s.isEmpty()) { 24 | System.out.println(s.take()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part02/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 | int count = 0; 9 | int summ = 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 | count = count + 1; 21 | summ = summ + number; 22 | } 23 | } 24 | System.out.println("Number of numbers: " + count); 25 | System.out.println("Sum of the numbers: " + summ); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_04.ReadymadeSortingAlgorithms-7590337/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | // insert test code here 9 | int[] array = {3, 1, 5, 99, 3, 12}; 10 | } 11 | 12 | public static void sort(int[] array) { 13 | Arrays.sort(array); 14 | } 15 | 16 | public static void sort(String[] array) { 17 | Arrays.sort(array); 18 | } 19 | 20 | public static void sortIntegers(ArrayList integers) { 21 | Collections.sort(integers); 22 | } 23 | 24 | public static void sortStrings(ArrayList strings) { 25 | Collections.sort(strings); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /part03/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 | int holder = 0; 9 | String name = ""; 10 | while (true) { 11 | String users = scanner.nextLine(); 12 | 13 | if (users.equals("")) { 14 | break; 15 | } 16 | 17 | String[] splitz = users.split(","); 18 | 19 | int oldest = Integer.valueOf(splitz[1]); 20 | 21 | if (oldest > holder) { 22 | holder = oldest; 23 | name = splitz[0]; 24 | } 25 | } 26 | 27 | System.out.println("Name of the oldes: " + name); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_04.ReadymadeSortingAlgorithms-7590337/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | // insert test code here 9 | int[] array = {3, 1, 5, 99, 3, 12}; 10 | } 11 | 12 | public static void sort(int[] array) { 13 | Arrays.sort(array); 14 | } 15 | 16 | public static void sort(String[] array) { 17 | Arrays.sort(array); 18 | } 19 | 20 | public static void sortIntegers(ArrayList integers) { 21 | Collections.sort(integers); 22 | } 23 | 24 | public static void sortStrings(ArrayList strings) { 25 | Collections.sort(strings); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /part03/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.print("Search for? "); 21 | String name = String.valueOf(scanner.nextLine()); 22 | 23 | if (list.contains(name)) { 24 | System.out.println(name + " was found!"); 25 | } else { 26 | System.out.println(name + " was not found!"); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_08.BigYear-7614471/src/main/java/Bird.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | public class Bird { 6 | 7 | private String name; 8 | private String latinName; 9 | private int observations; 10 | 11 | public Bird(String name, String latinName) { 12 | this.name = name; 13 | this.latinName = latinName; 14 | this.observations = 0; 15 | } 16 | 17 | public String getName() { 18 | return this.name; 19 | } 20 | 21 | public String getLatinName() { 22 | return this.latinName; 23 | } 24 | 25 | public void addObservation() { 26 | this.observations++; 27 | } 28 | 29 | public String toString() { 30 | return name + " (" + latinName +"): " + observations + " observations"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_08.BigYear-7614471/src/main/main/java/Bird.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | public class Bird { 6 | 7 | private String name; 8 | private String latinName; 9 | private int observations; 10 | 11 | public Bird(String name, String latinName) { 12 | this.name = name; 13 | this.latinName = latinName; 14 | this.observations = 0; 15 | } 16 | 17 | public String getName() { 18 | return this.name; 19 | } 20 | 21 | public String getLatinName() { 22 | return this.latinName; 23 | } 24 | 25 | public void addObservation() { 26 | this.observations++; 27 | } 28 | 29 | public String toString() { 30 | return name + " (" + latinName +"): " + observations + " observations"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /part02/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 | int count = 0; 9 | int total = 0; 10 | 11 | while (true) { 12 | int number = Integer.valueOf(scanner.nextLine()); 13 | 14 | if (number == 0) { 15 | break; 16 | } 17 | 18 | if (number > 0) { 19 | count = count + 1; 20 | total = total + number; 21 | } 22 | } 23 | 24 | if (count == 0) { 25 | System.out.println("Cannot calculate the average"); 26 | } else { 27 | System.out.println(((double) total / count)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part02/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 num = Integer.valueOf(scanner.nextLine()); 13 | 14 | for (int i = 1; i <= num; i++) { 15 | printText(); 16 | } 17 | } 18 | 19 | // Don't change the next line that defines the method! 20 | // (We aren't giving a method a parameter yet) 21 | public static void printText() { 22 | // write some code here 23 | System.out.println("In a hole in the ground there lived a method"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/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 (amount <= this.balance) { 23 | this.balance -= amount; 24 | return true; 25 | } 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/src/main/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 (amount <= this.balance) { 23 | this.balance -= amount; 24 | return true; 25 | } 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /part01/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 | 16 | System.out.println("Here is the story:"); 17 | System.out.println("Once upon a time there was " + name + ", who was " + job + "."); 18 | System.out.println("On the way to work, " + name + " reflected on life."); 19 | System.out.println("Perhaps " + name + " will not be " + job + " forever."); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part04/PaymentCard.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @author bexx 4 | */ 5 | public class PaymentCard { 6 | private double balance; 7 | 8 | public PaymentCard(double openingBalance) { 9 | this.balance = openingBalance; 10 | } 11 | 12 | public String toString() { 13 | return "The card has a balance of " + this.balance + " euros"; 14 | } 15 | 16 | public void eatAffordably() { 17 | if (this.balance >= 2.6) { 18 | this.balance -= 2.6; 19 | } 20 | } 21 | 22 | public void eatHeartily() { 23 | if (this.balance >= 4.5) { 24 | this.balance -= 4.6; 25 | } 26 | } 27 | public void addMoney(double amount) { 28 | if (amount > 0) { 29 | this.balance += amount; 30 | } 31 | 32 | if (this.balance > 150) { 33 | this.balance = 150; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /part03/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.print("From where? "); 21 | int start = Integer.valueOf(scanner.nextLine()); 22 | 23 | System.out.print("To where? "); 24 | int finish = Integer.valueOf(scanner.nextLine()); 25 | 26 | for (int i = start; i <= finish; i++) { 27 | System.out.println(numbers.get(i)); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /part03/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 great = list.get(0); 24 | for (int i = 1; i < list.size(); i++) { 25 | if (list.get(i) > list.get(i-1)) { 26 | great = list.get(i); 27 | } 28 | } 29 | 30 | System.out.println(great); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/src/main/java/Stack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class Stack { 8 | private ArrayList example; 9 | 10 | public Stack() { 11 | this.example = new ArrayList<>(); 12 | } 13 | 14 | public boolean isEmpty() { 15 | if (this.example.isEmpty()) { 16 | return true; 17 | } else { 18 | return false; 19 | } 20 | } 21 | 22 | public void add(String value) { 23 | this.example.add(value); 24 | } 25 | 26 | public ArrayList values() { 27 | return this.example; 28 | } 29 | 30 | public String take() { 31 | String topValue = this.example.get(this.example.size() - 1); 32 | this.example.remove(topValue); 33 | return topValue; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_02.Stack-7541533/src/main/main/java/Stack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class Stack { 8 | private ArrayList example; 9 | 10 | public Stack() { 11 | this.example = new ArrayList<>(); 12 | } 13 | 14 | public boolean isEmpty() { 15 | if (this.example.isEmpty()) { 16 | return true; 17 | } else { 18 | return false; 19 | } 20 | } 21 | 22 | public void add(String value) { 23 | this.example.add(value); 24 | } 25 | 26 | public ArrayList values() { 27 | return this.example; 28 | } 29 | 30 | public String take() { 31 | String topValue = this.example.get(this.example.size() - 1); 32 | this.example.remove(topValue); 33 | return topValue; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/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 | 9 | // Here you can taddry out the combined functionality of your classes 10 | // TodoList list = new TodoList(); 11 | // Scanner scanner = new Scanner(System.in); 12 | // 13 | // UserInterface ui = new UserInterface(list, scanner); 14 | // ui.start(); 15 | 16 | TodoList list = new TodoList(); 17 | list.add("read the course material"); 18 | list.add("watch the latest fool us"); 19 | list.add("take it easy"); 20 | list.print(); 21 | list.remove(2); 22 | list.print(); 23 | list.add("buy raisins"); 24 | list.print(); 25 | list.remove(1); 26 | list.remove(1); 27 | list.print(); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_10.TodoList-7577457/src/main/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 | 9 | // Here you can taddry out the combined functionality of your classes 10 | // TodoList list = new TodoList(); 11 | // Scanner scanner = new Scanner(System.in); 12 | // 13 | // UserInterface ui = new UserInterface(list, scanner); 14 | // ui.start(); 15 | 16 | TodoList list = new TodoList(); 17 | list.add("read the course material"); 18 | list.add("watch the latest fool us"); 19 | list.add("take it easy"); 20 | list.print(); 21 | list.remove(2); 22 | list.print(); 23 | list.add("buy raisins"); 24 | list.print(); 25 | list.remove(1); 26 | list.remove(1); 27 | list.print(); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_02.LiquidContainers2-7587051/src/main/java/Container.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | 6 | public class Container { 7 | private int container; 8 | 9 | public Container() { 10 | this.container = container; 11 | } 12 | 13 | public int contains() { 14 | return container; 15 | } 16 | 17 | public void add(int amount) { 18 | if (amount > 0) { 19 | container += amount; 20 | if (container > 100) { 21 | container = 100; 22 | } 23 | } 24 | } 25 | 26 | public void remove(int amount) { 27 | if (amount > 0) { 28 | container -= amount; 29 | if (container < 0) { 30 | container = 0; 31 | } 32 | } 33 | } 34 | 35 | public String toString() { 36 | return container + "/100"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_02.LiquidContainers2-7587051/src/main/main/java/Container.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | 5 | 6 | public class Container { 7 | private int container; 8 | 9 | public Container() { 10 | this.container = container; 11 | } 12 | 13 | public int contains() { 14 | return container; 15 | } 16 | 17 | public void add(int amount) { 18 | if (amount > 0) { 19 | container += amount; 20 | if (container > 100) { 21 | container = 100; 22 | } 23 | } 24 | } 25 | 26 | public void remove(int amount) { 27 | if (amount > 0) { 28 | container -= amount; 29 | if (container < 0) { 30 | container = 0; 31 | } 32 | } 33 | } 34 | 35 | public String toString() { 36 | return container + "/100"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /part03/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.print("Search for? "); 24 | int search = Integer.valueOf(scanner.nextLine()); 25 | 26 | for (int i = 0; i < list.size(); i++) { 27 | if (search == list.get(i)) { 28 | System.out.println(search + " is at index " + i); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/src/main/java/JokeManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Random; 7 | 8 | public class JokeManager { 9 | 10 | private ArrayList jokes; 11 | 12 | public JokeManager() { 13 | this.jokes = new ArrayList<>(); 14 | } 15 | 16 | public void addJoke(String joke) { 17 | jokes.add(joke); 18 | } 19 | 20 | public String drawJoke() { 21 | if (jokes.isEmpty()) { 22 | return "Jokes are in short supply."; 23 | } 24 | 25 | Random rand = new Random(); 26 | int index = rand.nextInt(jokes.size()); 27 | return jokes.get(index); 28 | } 29 | 30 | public void printJokes() { 31 | for (String joke: jokes) { 32 | System.out.println(joke); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_12.JokeManager-7582581/src/main/main/java/JokeManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Random; 7 | 8 | public class JokeManager { 9 | 10 | private ArrayList jokes; 11 | 12 | public JokeManager() { 13 | this.jokes = new ArrayList<>(); 14 | } 15 | 16 | public void addJoke(String joke) { 17 | jokes.add(joke); 18 | } 19 | 20 | public String drawJoke() { 21 | if (jokes.isEmpty()) { 22 | return "Jokes are in short supply."; 23 | } 24 | 25 | Random rand = new Random(); 26 | int index = rand.nextInt(jokes.size()); 27 | return jokes.get(index); 28 | } 29 | 30 | public void printJokes() { 31 | for (String joke: jokes) { 32 | System.out.println(joke); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_06.GradeStatistics-7605493/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 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here -- consider breaking the program into 10 | // multiple classes. 11 | Grades grades = new Grades(); 12 | System.out.println("Enter point totals, -1 stops:"); 13 | while (true) { 14 | int userPoint = Integer.valueOf(scanner.nextLine()); 15 | 16 | if (userPoint == -1) { 17 | break; 18 | } 19 | 20 | grades.add(userPoint); 21 | } 22 | 23 | grades.pointAverage(); 24 | grades.pointAveragePassing(); 25 | grades.passPercentage(); 26 | grades.gradeDistribution(); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /part07/famous-malayan-tiger-640048-part07-Part07_06.GradeStatistics-7605493/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | 9 | // Write your program here -- consider breaking the program into 10 | // multiple classes. 11 | Grades grades = new Grades(); 12 | System.out.println("Enter point totals, -1 stops:"); 13 | while (true) { 14 | int userPoint = Integer.valueOf(scanner.nextLine()); 15 | 16 | if (userPoint == -1) { 17 | break; 18 | } 19 | 20 | grades.add(userPoint); 21 | } 22 | 23 | grades.pointAverage(); 24 | grades.pointAveragePassing(); 25 | grades.passPercentage(); 26 | grades.gradeDistribution(); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_17.Money-7524732/src/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // test your class here 6 | Money a = new Money(7, 50); 7 | Money b = new Money(1, 60); 8 | 9 | Money c = a.minus(b); 10 | 11 | System.out.println(a); // 10.00e 12 | System.out.println(b); // 3.50e 13 | System.out.println(c); // 6.50e 14 | 15 | Money d = a.plus(b); 16 | System.out.println("sum: " + d); 17 | 18 | c = c.minus(a); // NB: a new Money object is created, and is placed "at the end of the strand connected to c" 19 | // the old 6.5 euros at the end of the strand disappears and the Java garbage collector takes care of it 20 | 21 | 22 | System.out.println(a); // 10.00e 23 | System.out.println(b); // 3.50e 24 | System.out.println(c); // 0.00e 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_17.Money-7524732/src/main/main/java/MainProgram.java: -------------------------------------------------------------------------------- 1 | 2 | public class MainProgram { 3 | 4 | public static void main(String[] args) { 5 | // test your class here 6 | Money a = new Money(7, 50); 7 | Money b = new Money(1, 60); 8 | 9 | Money c = a.minus(b); 10 | 11 | System.out.println(a); // 10.00e 12 | System.out.println(b); // 3.50e 13 | System.out.println(c); // 6.50e 14 | 15 | Money d = a.plus(b); 16 | System.out.println("sum: " + d); 17 | 18 | c = c.minus(a); // NB: a new Money object is created, and is placed "at the end of the strand connected to c" 19 | // the old 6.5 euros at the end of the strand disappears and the Java garbage collector takes care of it 20 | 21 | 22 | System.out.println(a); // 10.00e 23 | System.out.println(b); // 3.50e 24 | System.out.println(c); // 0.00e 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /part01/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 text = scan.nextLine(); 12 | System.out.println("Give an integer:"); 13 | int integ = Integer.valueOf(scan.nextLine()); 14 | System.out.println("Give a double:"); 15 | double floatvalue = Double.valueOf(scan.nextLine()); 16 | System.out.println("Give a boolean:"); 17 | boolean trueorfalse = Boolean.valueOf(scan.nextLine()); 18 | 19 | System.out.println("You gave the string " + text); 20 | System.out.println("You gave the integer " + integ); 21 | System.out.println("You gave the double " + floatvalue); 22 | System.out.println("You gave the boolean " + trueorfalse); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /part03/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 | 16 | System.out.println("The numbers in the range [0, 5]"); 17 | printNumbersInRange(numbers, 0, 5); 18 | 19 | System.out.println("The numbers in the range [3, 10]"); 20 | printNumbersInRange(numbers, 3, 10); 21 | } 22 | 23 | public static void printNumbersInRange(ArrayList numbers, int lowerLimit, int upperLimit) { 24 | for (int n: numbers) { 25 | if (n >= lowerLimit && n <= upperLimit) { 26 | System.out.println(n); 27 | } 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /part01/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 a points [0-100]:"); 10 | int grade = Integer.valueOf(scan.nextLine()); 11 | 12 | if (grade > 100) { 13 | System.out.println("incredible!"); 14 | } else if (grade > 89) { 15 | System.out.println("5"); 16 | } else if (grade > 79) { 17 | System.out.println("4"); 18 | } else if (grade > 69) { 19 | System.out.println("3"); 20 | } else if (grade > 59) { 21 | System.out.println("2"); 22 | } else if (grade > 49) { 23 | System.out.println("1"); 24 | } else if (grade >= 0) { 25 | System.out.println("failed"); 26 | } else { 27 | System.out.println("impossible!"); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/src/main/java/Counter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Counter { 5 | private int startValue; 6 | 7 | public Counter() { 8 | this.startValue = 0; 9 | } 10 | 11 | public Counter(int startValue) { 12 | this.startValue = startValue; 13 | } 14 | 15 | public void increase() { 16 | this.startValue++; 17 | } 18 | 19 | public void decrease() { 20 | this.startValue -= 1; 21 | } 22 | 23 | public void increase(int increaseBy) { 24 | if (increaseBy >= 0) { 25 | this.startValue = this.startValue + increaseBy; 26 | } 27 | } 28 | 29 | public void decrease(int decreaseBy) { 30 | if (decreaseBy >= 0) { 31 | this.startValue = this.startValue - decreaseBy; 32 | } 33 | } 34 | 35 | public int value() { 36 | return startValue; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_06.OverloadedCounter-7504482/src/main/main/java/Counter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | public class Counter { 5 | private int startValue; 6 | 7 | public Counter() { 8 | this.startValue = 0; 9 | } 10 | 11 | public Counter(int startValue) { 12 | this.startValue = startValue; 13 | } 14 | 15 | public void increase() { 16 | this.startValue++; 17 | } 18 | 19 | public void decrease() { 20 | this.startValue -= 1; 21 | } 22 | 23 | public void increase(int increaseBy) { 24 | if (increaseBy >= 0) { 25 | this.startValue = this.startValue + increaseBy; 26 | } 27 | } 28 | 29 | public void decrease(int decreaseBy) { 30 | if (decreaseBy >= 0) { 31 | this.startValue = this.startValue - decreaseBy; 32 | } 33 | } 34 | 35 | public int value() { 36 | return startValue; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | PaymentTerminal unicafeExactum = new PaymentTerminal(); 6 | System.out.println(unicafeExactum); 7 | 8 | PaymentCard annesCard = new PaymentCard(2); 9 | 10 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 11 | 12 | boolean wasSuccessful = unicafeExactum.eatHeartily(annesCard); 13 | System.out.println("there was enough money: " + wasSuccessful); 14 | 15 | unicafeExactum.addMoneyToCard(annesCard, 100); 16 | 17 | wasSuccessful = unicafeExactum.eatHeartily(annesCard); 18 | System.out.println("there was enough money: " + wasSuccessful); 19 | 20 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 21 | 22 | System.out.println(unicafeExactum); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_10.CardPayments-7517524/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | PaymentTerminal unicafeExactum = new PaymentTerminal(); 6 | System.out.println(unicafeExactum); 7 | 8 | PaymentCard annesCard = new PaymentCard(2); 9 | 10 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 11 | 12 | boolean wasSuccessful = unicafeExactum.eatHeartily(annesCard); 13 | System.out.println("there was enough money: " + wasSuccessful); 14 | 15 | unicafeExactum.addMoneyToCard(annesCard, 100); 16 | 17 | wasSuccessful = unicafeExactum.eatHeartily(annesCard); 18 | System.out.println("there was enough money: " + wasSuccessful); 19 | 20 | System.out.println("amount of money on the card is " + annesCard.balance() + " euros"); 21 | 22 | System.out.println(unicafeExactum); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/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 | HealthStation childrensHospital = new HealthStation(); 7 | 8 | Person ethan = new Person("Ethan", 1, 110, 7); 9 | Person peter = new Person("Peter", 33, 176, 85); 10 | 11 | System.out.println("weighings performed: " + childrensHospital.weighings()); 12 | 13 | childrensHospital.weigh(ethan); 14 | childrensHospital.weigh(peter); 15 | 16 | System.out.println("weighings performed: " + childrensHospital.weighings()); 17 | 18 | childrensHospital.weigh(ethan); 19 | childrensHospital.weigh(ethan); 20 | childrensHospital.weigh(ethan); 21 | childrensHospital.weigh(ethan); 22 | 23 | System.out.println("weighings performed: " + childrensHospital.weighings()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_09.HealthStation-7514210/src/main/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 | HealthStation childrensHospital = new HealthStation(); 7 | 8 | Person ethan = new Person("Ethan", 1, 110, 7); 9 | Person peter = new Person("Peter", 33, 176, 85); 10 | 11 | System.out.println("weighings performed: " + childrensHospital.weighings()); 12 | 13 | childrensHospital.weigh(ethan); 14 | childrensHospital.weigh(peter); 15 | 16 | System.out.println("weighings performed: " + childrensHospital.weighings()); 17 | 18 | childrensHospital.weigh(ethan); 19 | childrensHospital.weigh(ethan); 20 | childrensHospital.weigh(ethan); 21 | childrensHospital.weigh(ethan); 22 | 23 | System.out.println("weighings performed: " + childrensHospital.weighings()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /part03/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 (int i = 1; i < 10; i++) { 18 | System.out.println(lines.get(i)); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/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 | if (elements.isEmpty()) { 24 | return null; 25 | } 26 | 27 | String longString = this.elements.get(0); 28 | 29 | for (String el: elements) { 30 | if (el.length() > longString.length()) { 31 | longString = el; 32 | } 33 | } 34 | 35 | return longString; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_06.LongestInCollection-7562221/src/main/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 | if (elements.isEmpty()) { 24 | return null; 25 | } 26 | 27 | String longString = this.elements.get(0); 28 | 29 | for (String el: elements) { 30 | if (el.length() > longString.length()) { 31 | longString = el; 32 | } 33 | } 34 | 35 | return longString; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /part03/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 number = Integer.valueOf(scanner.next()); 17 | 18 | if (number == -1) { 19 | break; 20 | } 21 | 22 | list.add(number); 23 | } 24 | 25 | int count = 0; 26 | int sum = 0; 27 | 28 | for (int n: list) { 29 | count++; 30 | sum += n; 31 | } 32 | 33 | System.out.println("Average: " + ((double) sum / count)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/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 | public boolean equals(Object compared) { 21 | if (this == compared) { 22 | return true; 23 | } 24 | 25 | if (!(compared instanceof Book)) { 26 | return false; 27 | } 28 | 29 | Book comparedBook = (Book) compared; 30 | 31 | if (this.name.equals(comparedBook.name) && 32 | this.publicationYear == comparedBook.publicationYear) { 33 | return true; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/src/main/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 | public boolean equals(Object compared) { 21 | if (this == compared) { 22 | return true; 23 | } 24 | 25 | if (!(compared instanceof Book)) { 26 | return false; 27 | } 28 | 29 | Book comparedBook = (Book) compared; 30 | 31 | if (this.name.equals(comparedBook.name) && 32 | this.publicationYear == comparedBook.publicationYear) { 33 | return true; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /part03/IndexWasNotFound.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | import java.util.Scanner; 4 | 5 | public class IndexWasNotFound { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | int[] array = new int[10]; 10 | array[0] = 6; 11 | array[1] = 2; 12 | array[2] = 8; 13 | array[3] = 1; 14 | array[4] = 3; 15 | array[5] = 0; 16 | array[6] = 9; 17 | array[7] = 7; 18 | 19 | System.out.print("Search for? "); 20 | int searching = Integer.valueOf(scanner.nextLine()); 21 | 22 | // Implement the search functionality here 23 | boolean found = false; 24 | for (int i = 0; i < array.length; i++) { 25 | if (searching == array[i]) { 26 | System.out.println(searching + " is at index " + i + "."); 27 | found = true; 28 | } 29 | 30 | } 31 | if (!found) { 32 | System.out.println(searching + " was not found."); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /part04/IsItInTheFile.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.file.Paths; 3 | import java.util.Scanner; 4 | 5 | public class IsItInTheFile { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | System.out.println("Name of the file:"); 11 | String file = scanner.nextLine(); 12 | 13 | System.out.println("Search for:"); 14 | String searchedFor = scanner.nextLine(); 15 | 16 | Boolean found = false; 17 | 18 | try (Scanner searchLine = new Scanner(Paths.get(file))) { 19 | while (searchLine.hasNextLine()) { 20 | if (searchLine.nextLine().equals(searchedFor)) { 21 | System.out.println("Found!"); 22 | found = true; 23 | } 24 | } 25 | if (!found) { 26 | System.out.println("Not found."); 27 | } 28 | } 29 | catch (Exception e) { 30 | System.out.println("Reading the file " + file + " failed."); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /part03/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 | int sum = 0; 10 | int count = 0; 11 | int length = 0; 12 | String name = ""; 13 | 14 | while (true) { 15 | 16 | String users = scanner.nextLine(); 17 | if (users.equals("")) { 18 | break; 19 | } 20 | 21 | String[] splitz = users.split(","); 22 | int age = Integer.valueOf(splitz[1]); 23 | 24 | sum += age; 25 | count++; 26 | 27 | if (splitz[0].length() > length) { 28 | length = splitz[0].length(); 29 | name = splitz[0]; 30 | } 31 | 32 | } 33 | 34 | System.out.println("Longest name: " + name); 35 | System.out.println("Average of the birth years: " + ((double) sum / count)); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /part04/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 | -------------------------------------------------------------------------------- /part04/NumbersFromAFile.java: -------------------------------------------------------------------------------- 1 | 2 | import java.nio.file.Paths; 3 | import java.util.Scanner; 4 | 5 | public class NumbersFromAFile { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | 10 | System.out.print("File? "); 11 | String file = scanner.nextLine(); 12 | System.out.print("Lower bound? "); 13 | int lowerBound = Integer.valueOf(scanner.nextLine()); 14 | System.out.print("Upper bound? "); 15 | int upperBound = Integer.valueOf(scanner.nextLine()); 16 | int count = 0; 17 | 18 | try (Scanner numbers = new Scanner(Paths.get(file))) { 19 | while (numbers.hasNextLine()) { 20 | int number = Integer.valueOf(numbers.nextLine()); 21 | if (number >= lowerBound && number <= upperBound) { 22 | count++; 23 | } 24 | } 25 | } 26 | catch (Exception e) { 27 | System.out.println("error: " + e.getMessage()); 28 | } 29 | System.out.println("Numbers: " + count); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/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 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_05.ConstructorOverload-7504360/src/main/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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Beka Modebadze 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/java/Hold.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class Hold { 8 | private int maxWeight; 9 | private ArrayList baggage; 10 | 11 | public Hold(int maxWeight) { 12 | this.maxWeight = maxWeight; 13 | this.baggage = new ArrayList<>(); 14 | } 15 | 16 | public void addSuitcase(Suitcase suitcase) { 17 | int totalWeight = 0; 18 | for (Suitcase i: baggage) { 19 | totalWeight += i.totalWeight(); 20 | } 21 | if (totalWeight + suitcase.totalWeight() <= maxWeight) { 22 | baggage.add(suitcase); 23 | } 24 | } 25 | 26 | public String toString() { 27 | int totalWeight = 0; 28 | for (Suitcase i: baggage) { 29 | totalWeight += i.totalWeight(); 30 | } 31 | return baggage.size() + " suitcases (" + totalWeight + " kg)"; 32 | } 33 | 34 | public void printItems() { 35 | for (Suitcase i: baggage) { 36 | i.printItems(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_08.CargoHold-7562890/src/main/main/java/Hold.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author bexx 3 | */ 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class Hold { 8 | private int maxWeight; 9 | private ArrayList baggage; 10 | 11 | public Hold(int maxWeight) { 12 | this.maxWeight = maxWeight; 13 | this.baggage = new ArrayList<>(); 14 | } 15 | 16 | public void addSuitcase(Suitcase suitcase) { 17 | int totalWeight = 0; 18 | for (Suitcase i: baggage) { 19 | totalWeight += i.totalWeight(); 20 | } 21 | if (totalWeight + suitcase.totalWeight() <= maxWeight) { 22 | baggage.add(suitcase); 23 | } 24 | } 25 | 26 | public String toString() { 27 | int totalWeight = 0; 28 | for (Suitcase i: baggage) { 29 | totalWeight += i.totalWeight(); 30 | } 31 | return baggage.size() + " suitcases (" + totalWeight + " kg)"; 32 | } 33 | 34 | public void printItems() { 35 | for (Suitcase i: baggage) { 36 | i.printItems(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/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.equals(comparedSong.artist) && 26 | this.name.equals(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 | } 41 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | ArrayList books = new ArrayList<>(); 10 | 11 | while (true) { 12 | System.out.println("Name (empty will stop):"); 13 | String name = scanner.nextLine(); 14 | if (name.isEmpty()) { 15 | break; 16 | } 17 | 18 | System.out.println("Publication year:"); 19 | int publicationYear = Integer.valueOf(scanner.nextLine()); 20 | 21 | Book book = new Book(name, publicationYear); 22 | 23 | if (books.contains(book)) { 24 | System.out.println("The book is already on the list. Let's not add the same book again."); 25 | } else { 26 | books.add(book); 27 | } 28 | } 29 | 30 | // NB! Don't alter the line below! 31 | System.out.println("Thank you! Books added: " + books.size()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /part03/Swap.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class Swap { 5 | 6 | public static void main(String[] args) { 7 | Scanner scanner = new Scanner(System.in); 8 | int[] array = new int[5]; 9 | array[0] = 1; 10 | array[1] = 3; 11 | array[2] = 5; 12 | array[3] = 7; 13 | array[4] = 9; 14 | 15 | int index = 0; 16 | while (index < array.length) { 17 | System.out.println(array[index]); 18 | index++; 19 | } 20 | System.out.println(""); 21 | 22 | // Implement here 23 | // asking for the two indices 24 | // and then swapping them 25 | System.out.println("Give two indices to swap:"); 26 | int first = Integer.valueOf(scanner.nextLine()); 27 | int second = Integer.valueOf(scanner.nextLine()); 28 | 29 | int helper = array[first]; 30 | array[first] = array[second]; 31 | array[second] = helper; 32 | 33 | System.out.println(""); 34 | index = 0; 35 | while (index < array.length) { 36 | System.out.println(array[index]); 37 | index++; 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_12.Song-7522061/src/main/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.equals(comparedSong.artist) && 26 | this.name.equals(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 | } 41 | -------------------------------------------------------------------------------- /part05/famous-malayan-tiger-640048-part05-Part05_14.Books-7522750/src/main/main/java/Main.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | ArrayList books = new ArrayList<>(); 10 | 11 | while (true) { 12 | System.out.println("Name (empty will stop):"); 13 | String name = scanner.nextLine(); 14 | if (name.isEmpty()) { 15 | break; 16 | } 17 | 18 | System.out.println("Publication year:"); 19 | int publicationYear = Integer.valueOf(scanner.nextLine()); 20 | 21 | Book book = new Book(name, publicationYear); 22 | 23 | if (books.contains(book)) { 24 | System.out.println("The book is already on the list. Let's not add the same book again."); 25 | } else { 26 | books.add(book); 27 | } 28 | } 29 | 30 | // NB! Don't alter the line below! 31 | System.out.println("Thank you! Books added: " + books.size()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /part01/OddOrEven.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class OddOrEven { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | 9 | // Write your program here 10 | 11 | System.out.println("Give a number:"); 12 | int number = Integer.valueOf(scan.nextLine()); 13 | if (number % 2 == 0) { 14 | System.out.println("Number " + number + " is even."); 15 | } else { 16 | System.out.println("Number " + number + " is odd."); 17 | } 18 | // HINT: 19 | // You can find out if a number is even or odd easily using the modulo operator % 20 | // Try the following commands to see what they print 21 | // System.out.println( 1%2 ); 22 | // System.out.println( 2%2 ); 23 | // System.out.println( 3%2 ); 24 | // System.out.println( 4%2 ); 25 | // System.out.println( 5%2 ); 26 | // System.out.println( 6%2 ); 27 | // System.out.println( 7%2 ); 28 | // int luku = 8 29 | // System.out.println( luku%2 ); 30 | // So, by taking the modulo of a number and two you can find out if it is even or odd ! 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /part06/famous-malayan-tiger-640048-part06-Part06_13.Exercises-7585189/src/main/java/ExerciseManagement.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class ExerciseManagement { 4 | 5 | private ArrayList exercises; 6 | 7 | public ExerciseManagement() { 8 | this.exercises = new ArrayList<>(); 9 | } 10 | 11 | public ArrayList exerciseList() { 12 | ArrayList list = new ArrayList<>(); 13 | for (Exercise exercise: exercises) { 14 | list.add(exercise.getName()); 15 | } 16 | return list; 17 | } 18 | 19 | public void add(String exercise) { 20 | this.exercises.add(new Exercise(exercise)); 21 | } 22 | 23 | public void markAsCompleted(String exercise) { 24 | for (Exercise ex: exercises) { 25 | if (ex.getName().equals(exercise)) { 26 | ex.setCompleted(true); 27 | } 28 | } 29 | } 30 | 31 | public boolean isCompleted(String exercise) { 32 | for (Exercise ex: exercises) { 33 | if (ex.getName().equals(exercise)) { 34 | return ex.isCompleted(); 35 | } 36 | } 37 | return false; 38 | } 39 | } 40 | --------------------------------------------------------------------------------