This task is to be completed if you are already familiar with topics covered in stage 0 and want to skip it.
- Work with class
Animal
. - Provide it with 3 private fields - color(
String
), numberOfPaws(int
), hasFur(boolean
). - Add constructor with full parameters. Save the parameter order as it is listed in a second paragraph.
- Add a methods
getDescription()
, witch would use class fields and return a string with such pattern "This animal is mostly(color)
. It has(numberOfPaws)
paws and('a'/'no' -> depends on value of hasFur)
fur." - (Optional) In the method
getDescription()
change the word 'paw' depending on thenumberOfPaws
: number of paws is 1 -> 'paw', number of paws is different from 1 -> 'paws'.
- Work with classes
Dog
andBird
. Extend them with the help ofAnimal
. - Create no-args constructor for each where provide all necessary information for
Animal
constructor bysuper()
method:
- for
Dog
:color
- brown,numberOfPaws
- 4,hasFur
- true; - for
Bird
:color
- blue,numberOfPaws
- 2,hasFur
- false.
- Override
getDescription()
method for classBird
: add one more sentence to the description. The result must be " This animal is mostly blue. It has 2 paws and no fur. Moreover, it has 2 wings and can fly." - (Optional) Create an object of each class and call
getDescription()
method for both of them. Try to explain the output results.
Revert 3-digit number that will be passed (e.g.: given -> 489, expected -> 984) and print it. Code snippet:
public class NumberReverter {
public void revert(int number) {
}
}
Where number - variable that should be used within the program.
You will be given a four-digit number your task will be to find the sum of all digits in the given number. Code snippet:
public class DigitsSumCalculator {
public void calculateSum(int number) {
}
}
Where number - variable that should be used within the program.
Implement the program that will print the season name to the console by the number of the month. If month is incorrect -> print "Wrong month number". Month will be passed as the method argument. (Example: "1" -> "Winter", 0 -> "Wrong month number")
public class SeasonDeterminer {
public void tellTheSeason(int monthNumber) {
}
}
Create a program that will consume 3 points as method arguments and will print to the console if those points can build up a valid triangle or not. (output when correct: "this is a valid triangle", otherwise : "it's not a triangle")
public class TriangleValidator {
public void validate(double firstSide, double secondSide, double thirdSide) {
}
}
Create a program that will consume a year and a month (validation is required) and will print amount of days in this month considering also if a year is leap or not.(prints amount of days or else "invalid date", negative years are not accepted)
public class DaysInMonth {
public void printDays(int year, int month) {
}
}
Create a program that will consume 2 integers from method args (dividend and divider) and will perform integer division of dividend be divider, save the value, and then will multiply result by divider and will if got value is equal to dividend will print:"can be divided completely", otherwise "cannot be divided completely" or "division by zero".
public class IntegerDivider {
public void printCompletelyDivided(int dividend, int divider) {
}
}
Create a program that will consume 2 integers from method args as data of a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies(beginning with top right:"first", "second", "third", "fourth", "zero"):
public class CoordinatePane {
public void printQuadrant(int x, int y) {
}
}
Implement the program that will swap 2 variables without creating new variables or objects, using bitwise operators:
public class BitwiseValuesSwap {
public void swap(int first, int second) {
}
}
Write a program that prompts the user to input a positive integer. It should then print the multiplication table of that number.
public class MultiplicationTable {
public void printTable(int numberTableToPrint) {
}
}
Write a program that will print
public class Pyramid {
public void printPyramid(int cathetusLength) {
}
public static void main(String[] args) {
new Pyramid().printPyramid(7);
}
}
Write a program that will find power of any number using for loop
public class Power {
public void printPower(int numberToPrint, int power) {
}
public static void main(String[] args) {
new Power().printPower(10, 3);
}
}
Write a program that will print
public class HalfPyramid {
public void printHalfPyramid(int cathetusLength) {
}
public static void main(String[] args) {
new HalfPyramid().printHalfPyramid(8);
}
}
Tasks for assessing the algorithm complexity. The following are the ratios of the constants with the BigO estimate:
Complexity.O_LOG_N -> O(log N)
Complexity.O_N_2 -> O(log N^2)
Complexity.O_FACTORIAL_N -> O(!N)
Complexity.O_2_N -> O(2 * N)
Complexity.O_N_LOG_N -> O(N * log N)
Complexity.O_1 -> O(1)
Complexity.O_N -> O(N)
badLinerSearch
- return the linear search complexity if the element you are looking for is at the end of the array.arrayIndexItemAccess
- return the complexity of accessing an array element by index.binarySorting
- return the complexity of a binary search.twoCycleSorting
- return the complexity of the Two Cycle Sorting algorithm.
Here are the tasks for working with the arrays.
The usage of any additional packages (such as java.util.*
) is forbidden.
seasonsArray
- return aString[]
array that will list all the seasons of the year, starting with winter.generateNumbers
- generate anint[]
array of consecutive positive integers starting at 1 of the given length ( length parameter > 0)
Example:
length = 1 -> [1]
length = 3 -> [1, 2, 3]
length = 5 -> [1, 2, 3, 4, 5]
totalSum
- find the sum of all elements of theint[]
array.
Example:
arr = [1, 3, 5] -> sum = 9
arr = [5, -3, -4] -> sum = -2
findIndexOfNumber
- return the index of the first occurrence ofnumber
in thearr
array. If there is no such element in the array, return-1
.
Example:
arr = [99, -7, 102], number = -7 -> 2
arr = [5, -3, -4], number = 10 -> -1
reverseArray
- return the newString[]
array obtained from the arr array by reversing the order of the elements.
Example:
arr = ["Bob", "Nick"] -> ["Nick", "Bob"]
arr = ["pineapple", "apple", "pen"] -> ["pen", "apple", "pineapple"]
getOnlyPositiveNumbers
- return newint[]
array obtained fromarr int[]
array by choosing positive numbers only. P.S. 0 is not a positive number
Example:
arr = [1,-2, 3] -> [1, 3]
arr = [-1, -2, -3] -> []
arr = [1, 2] -> [1, 2]
- [OPTIONAL]
sortRaggedArray
- return a sorted, ragged, two-dimensionalint[][]
array following these rules:- incoming one-dimensional arrays must be arranged in ascending order of their length;
- numbers in all one-dimensional arrays must be in ascending order.
Example:
arr = [[3, 1, 2,], [3,2]] -> [[2, 3], [1, 2, 3]]
arr = [[5, 4], [7]] -> [[7], [4, 5]]