Skip to content

My Java Programming 1 solutions and projects. This repository demonstrates my foundational understanding of object-oriented programming, core Java syntax, and problem-solving techniques, covering data types, control structures, and basic algorithms.

License

Notifications You must be signed in to change notification settings

marceloxreis/mooc-java-programming-i

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

University of Helsinki MOOC: Java Programming I - Solutions

This repository contains my solutions and notes for the University of Helsinki's Java Programming I MOOC. The course teaches the fundamentals of programming using Java, including algorithms and object-oriented programming.



đź’» About the Repository

An important part of this course is completing the exercises for feedback. This repository contains the solutions I've developed for those exercises. Below are descriptions and links for each part and exercise.



đź“• Academic Honesty

Keep in mind the course's guidelines on academic honesty. You should attempt to solve each exercise yourself before consulting other implementations. Also, remember that I am learning, and these solutions might not be the best implementations.



đź“– Content


▶️ Notes


PNG Badge

  • Notes - Contains notes taken from course materials and other sources.

Part 1

Java


Part 2

Java


Part 3

Java


Part 4

Java

  • Exercise 4.1: Your first account - Create an Account with 100.0 balance, deposit 20.0, then print its final balance.
  • Exercise 4.2: Your first bank transfer - Create two accounts ("Matthews account": 1000, "My account": 0), transfer 100 from Matthew's to My account, then print both.
  • Exercise 4.3: Dog attributes - Create a Dog class with private instance variables: name (String), breed (String), and age (int).
  • Exercise 4.4: Room - Create a Room class with private code (String) and seats (int) variables, and a constructor to initialize them.
  • Exercise 4.5: Whistle - Create a Whistle class with a private sound (String) variable, a constructor to set it, and a sound() method to print the whistle's sound.
  • Exercise 4.6: Door - Create a Door class with a no-parameter constructor and a knock() method that prints "Who's there?".
  • Exercise 4.7: Product - Create a Product class with name (String), price (double), and quantity (int), including a constructor and a printProduct() method.
  • Exercise 4.8: Decreasing counter - Implement decrement() to reduce the counter's value by one (but not below zero), and add a reset() method to set the counter to zero.
  • Exercise 4.9: Debt - Create a Debt class with balance and interestRate; implement printBalance() and waitOneYear() to simulate debt growth.
  • Exercise 4.10: Song - Create a Song class with name (String) and length (int), a constructor to set them, and corresponding name() and length() getter methods.
  • Exercise 4.11: Film - Create a Film class with name (String) and ageRating (int), a constructor, and name() and ageRating() getter methods.
  • Exercise 4.12: Gauge - Create a Gauge class with a value (int) that increments (max 5), decrements (min 0), returns its value(), and indicates if full() (value is 5).
  • Exercise 4.13: Agent - Remove the print method from the Agent class and implement a toString() method to return "My name is [Last Name], [First Name] [Last Name]".
  • Exercise 4.14: Multiplier - Create a Multiplier class with a constructor taking an integer, and a multiply() method that returns its input multiplied by the constructor's number.
  • Exercise 4.15: Statistics - Develop a Statistics class to addNumber and track count, sum, and average. Then, use this class in MainProgram to calculate the total sum, count, and average of user-inputted numbers (ending with -1). Finally, extend MainProgram to separately sum all, even, and odd user-entered numbers using three Statistics objects.
  • Exercise 4.16: Payment Card - Implement PaymentCard with balance management and transaction methods; eat methods prevent negative balance; addMoney caps at 150 and prevents negative top-ups; MainProgram simulates multiple card interactions.
  • Exercise 4.17: Items - Read names, create and store Item objects, then print them.
  • Exercise 4.18: Personal information - Read personal info (first name, last name, ID) until an empty first name; then print only first and last names.
  • Exercise 4.19: Television programs - Read TV programs (name, duration) until empty name; then prompt for max duration and print programs within that limit.
  • Exercise 4.20: Books - Read book details (title, pages, year) until an empty title; then, based on user input ("everything" or "name"), print either all details or just titles.
  • Exercise 4.21: Number of Strings - Read strings until "end"; print the count of strings read, excluding "end".
  • Exercise 4.22: Cubes - Read strings until "end"; for each, convert to an integer and print its cube.
  • Exercise 4.23: Creating a New File - Create file.txt in the project root via NetBeans Files tab and write "Hello, world!" into it.
  • Exercise 4.24: Printing a File - Read and print each line of "data.txt".
  • Exercise 4.25: Printing a Specified File - Prompt for a filename, then read and print its content.
  • Exercise 4.26: Guest List From a File - Prompt for a guest list filename, read names from it, then check if user-entered names are on that list.
  • Exercise 4.27: Is it in the file? - Prompt for a filename and a search string; read the file and print "Found!" or "Not found!", or an error if reading fails.
  • Exercise 4.28: Numbers From a File - Prompt for a filename and number range; count and print how many numbers from the file fall within that range.
  • Exercise 4.29: Records From a File - Prompt for a CSV file name; read "name,age" pairs and print them as "name, age: X year(s)".
  • Exercise 4.30: Storing Records - Implement readRecordsFromFile(String file) to parse "name,age" CSV data into a list of Person objects.
  • Exercise 4.31: Sport Statistics - Prompt for a CSV file and a team name; read match data, then print the total games played, wins, and losses for that team.

Part 5

Java

  • Exercise 5.1: One Minute - Implement a Timer class using ClockHand with hundredths and seconds, including a constructor, toString() for "SS:HH" format, and an advance() method to update time.
  • Exercise 5.2: Book - Create a Book class with author, title, pages, getter methods for each, and a toString() method for formatted output.
  • Exercise 5.3: Cube - Create a Cube class with an edgeLength constructor, volume() method, and toString() returning "The length of the edge is l and the volume v".
  • Exercise 5.4: Fitbyte - Create a Fitbyte class with age and resting heart rate, and a targetHeartRate() method that calculates target heart rate based on a percentage.
  • Exercise 5.5: Constructor Overload - Add three overloaded constructors to the Product class: one taking only name (defaulting location to "shelf", weight to 1); one taking name and location (defaulting weight to 1); and one taking name and weight (defaulting location to "shelf").
  • Exercise 5.6: Overloaded Counter - Implement Counter with two constructors (defaulting to 0 or accepting a startValue), value() getter, increase() and decrease() by 1, and overloaded increase(int increaseBy) and decrease(int decreaseBy) methods that modify the counter only if increaseBy or decreaseBy are non-negative.
  • Exercise 5.7: NullPointerException - Implement a program that directly causes a NullPointerException upon execution without user interaction.
  • Exercise 5.8: Health station - Implement a HealthStation class with a weigh(Person person) method that returns the person's weight, a feed(Person person) method that increases their weight by one, and a weighings() method that returns the total count of weighings performed.
  • Exercise 5.9: Card payments - Refactor PaymentCard to be "dumb" with a takeMoney() method returning success; implement PaymentTerminal to handle cash payments (eatAffordably, eatHeartily returning change) and card payments (eatAffordably, eatHeartily taking a PaymentCard and returning boolean success), also add addMoneyToCard to increase card balance and terminal cash.
  • Exercise 5.10: Biggest pet shop - Modify Person's toString() method to include the associated Pet's name and breed.
  • Exercise 5.11: Comparing apartments - Implement methods in the Apartment class: largerThan to compare total areas, priceDifference to return the absolute price difference, and moreExpensiveThan to compare total prices.
  • Exercise 5.12: Song - Implement the equals() method in the Song class to compare two Song objects for equality based on their content.
  • Exercise 5.13: Identical twins - Implement the equals() method in the Person class to compare all instance variables, including the SimpleDate birthday object.
  • Exercise 5.14: Books - Read book names and publication years until an empty name; add new books to a list only if not already present (same name and year).
  • Exercise 5.15: Archive - Read item identifier and name pairs until empty input; then print each unique item (based on identifier) at most once, using the first entered name for duplicates.
  • Exercise 5.16: Dating app - Expand SimpleDate by implementing advance() to move the date one day, advance(int howManyDays) to move by a specified number of days, and afterNumberOfDays(int days) to return a new SimpleDate object representing a future date without altering the original.
  • Exercise 5.17: Money - Implement methods for the immutable Money class: plus returns a new Money object representing the sum; lessThan checks if one Money object's value is less than another's; and minus returns a new Money object representing the difference, or 0 if negative.

Part 6

Java

  • Exercise 6.1: Menu - Implement a Menu class with addMeal() to add unique meals, printMeals() to display them, and clearMenu() to empty the list.
  • Exercise 6.2: Stack - Implement a Stack class with isEmpty() to check for emptiness, add(String value) to push to the top, values() to return all elements as a list, and take() to remove and return the topmost element.
  • Exercise 6.3: MessagingService - Implement MessagingService with a constructor; add(Message message) to store messages up to 280 characters; and getMessages() to retrieve the stored messages.
  • Exercise 6.4: Printing a Collection - Implement the toString() method for SimpleCollection to print its name and number of elements, listing each element on a new line if present, otherwise indicating it's empty.
  • Exercise 6.5: Santa's Workshop - Create a Gift class with a name and weight, and methods to retrieve them and a toString() for formatted output. Then, create a Package class to which Gift objects can be added, with a method to calculate and return the total weight of all gifts inside.
  • Exercise 6.6: Longest in collection - Implement longest() method in SimpleCollection to return the longest string in the collection, or null if empty.
  • Exercise 6.7: Height Order - Implement a Room class that can add Person objects, isEmpty() to check for occupants, getPersons() to return all, shortest() to find the shortest person without removal, and take() to remove and return the shortest person.
  • Exercise 6.8: Cargo hold - Implement Item (name, weight, toString); Suitcase (max weight, addItem with weight limit, toString with proper singular/plural/zero item count, printItems, totalWeight, heaviestItem); and Hold (max weight, addSuitcase with weight limit, toString, printItems from all suitcases).
  • Exercise 6.9: Simple Dictionary - Implement a TextUI class that interacts with a SimpleDictionary. It should process commands: "end" to exit with "Bye bye!", "add" to prompt for and store a word and its translation, and "search" to prompt for a word and print its translation or indicate if not found.
  • Exercise 6.10: To do list - Implement a TodoList class that can add tasks, print them with indices, and remove by index. Then, create a UserInterface class that uses a TodoList and Scanner to provide a text-based interface for add, list, remove, and stop commands.
  • Exercise 6.11: Averages - Enhance GradeRegister with averageOfGrades() to compute the average of recorded grades and averageOfPoints() to compute the average of exam points (storing points when grades are added). Finally, integrate these averages into the user interface's output.
  • Exercise 6.12: Joke Manager - Create a JokeManager class to addJoke, drawJoke (randomly, or "Jokes are in short supply." if empty), and printJokes. Then, create a UserInterface class to handle user interaction (add, draw, list, stop) by utilizing JokeManager and Scanner.
  • Exercise 6.13: Exercises - Implement ExerciseManagementTest and ExerciseManagement classes, developing the exercise management program using test-driven development, including refactoring.

Part 7

Java

  • Exercise 7.1: Liquid containers - Implement an interactive program in main to manage two 100-liter containers: "first" and "second". Support "add amount" to the first (max 100L); "move amount" from first to second (respecting limits and capacity); and "remove amount" from the second (respecting limits). Print container states after each command.
  • Exercise 7.2: Liquid Containers 2.0 - Create a Container class with methods to contains(), add() (max 100, no negatives), remove() (min 0, no negatives), and toString() ("amount/100"). Then, rewrite the liquid container user interface from Exercise 6.1 to utilize this new Container class.
  • Exercise 7.3: Sorting - Implement five MainProgram methods for sorting: smallest (returns smallest value in array), indexOfSmallest (returns index of smallest value), indexOfSmallestFrom (returns index of smallest from startIndex), swap (swaps two elements), and sort (implements selection sort using the other methods, printing array state after each swap).
  • Exercise 7.4: Ready-made Sorting Algorithms - Implement overloaded sort methods for int[] and String[] arrays, and sortIntegers and sortStrings for ArrayList<Integer> and ArrayList<String>, all using Java's built-in sorting functionalities.
  • Exercise 7.5: Searching - Implement linearSearch(ArrayList<Book> books, int searchedId) to find a book's index by ID sequentially, and binarySearch(ArrayList<Book> books, int searchedId) to find a book's index by ID using the binary search algorithm on a sorted list.
  • Exercise 7.6: Grade statistics - Read point totals (0-100, -1 to end, others ignored); print the overall point average, average of passing points (>=50, or "-" if none), pass percentage, and a visual grade distribution (0-5) using stars.
  • Exercise 7.7: Recipe search - Read recipes from a file (name, cooking time, ingredients); then, based on user commands, list all recipes, search by name (partial match), search by maximum cooking time, or search by exact ingredient match.
  • Exercise 7.8: Big year - Implement a bird-watching database with commands to "Add" a bird (name, Latin name), "Observation" to record an observation for a bird (or "Not a bird!"), "All" to list all birds with observation counts, and "One" to show details for a specific bird. Handle invalid bird inputs.

Credits

A big thank you to the University of Helsinki and MOOC.fi for providing this excellent Java learning resource.


If you'd like to learn more about the course, here are some helpful links:

About

My Java Programming 1 solutions and projects. This repository demonstrates my foundational understanding of object-oriented programming, core Java syntax, and problem-solving techniques, covering data types, control structures, and basic algorithms.

Topics

Resources

License

Stars

Watchers

Forks

Languages