הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Syntax Exersice 4

In the following exercise we practice writing user defined classes in Java. Each task is around a certain class or a group of classes.
When implementing the classes, take care to add relevant javadoc comments to all classes and methods. In addition, take care to implement a JUnit test class when appropriate.
Feel free to play around with the data and add ideas of your own. This is the last java syntax exercise before going deeper to learn the Java APIs and libraries.

After completing this module, you should feel at home with creating classes and objects, and adding JUnit test classes to your project.

Person Class

  1. Write a class called Person with the fields: name, age.
  2. Create getter methods: getName, getAge
  3. Create method: growUp(). The method should increase age by 1

Fish Tank

  1. Write a class called Fish with the fields: name, color, speed.
  2. Create a constructor that takes the three arguments
  3. Implement a JUnit class that creates a random fish tank with 10 fish, each having a random speed and random color. Then print all the fish data

Car Racing

  1. Implement a Car class with two fields: maxSpeed and manufactureYear and a constructor
  2. Implement a way(long timeInHourse) method that takes driving time in hours and returns the number of KM passed
  3. Implement a Race class. The class should provide a single start() method that creates 5 cars with random speeds, and sends them on a 10 hours drive. It should then print the way each car has passed using the '*' character. For instance, assuming car 1 passed 5Km and car 2 passed 7 KM, the output should look like this:
    • Car1: *****
    • Car2: *******

Geometrical Party

Implement two classes: Rectangle and Triangle, each with a constructor that takes two values: baseLength and height.
Implement a draw() method in each class that will paint either a rectangle or a triangle using the '*' character.
Implement a class called DrawingBoard that holds two arrays. One array of Rectangle and one array of Triangle. The DrawingBoard should randomize some values to fill the arrays, and draws all its shapes on screen.

Reversi

Implement a ReverseNum class that has a field called num and a constructor taking a number into num.
Implement a method called reverse() which returns the number with the digits order reversed. For example, if the original number is 13421, the result of reverse should be: 12431.
Implement a JUnit class to test your work.

More Paintings

  1. Implement a class called Line with a constructor taking a line's length.
  2. Add a draw() method that prints the line using the * character.
  3. Extend the Line class by creating a new class called WLine. The constructor should now take two values: length and width.
  4. Override WLine's draw() method so the line will have a width according to the given argument. Use the super method to draw each line
  5. Implement a class called Painter that creates 10 WLine objects and draws them on screen.
course: