Tom_the_cat

1

votes
2

answer
39

views

Issues with validating fields in constructor of a subclass

I am now learning about Java's inheritance. I have total of 3 questions, and thank you for your support. 1st question: Can I validate a class's fields in its constructor? 2nd question: Some people recommended me to throw an exception for validation. Does it mean throwing an exception to the calle...
Tom_the_cat
1

votes
1

answer
41

views

The reason why we need a function prototype for methods that is imported from its header file

I am currently studying about pointer from K&R. In page, 109 the authors declare function prototypes for methods int getline(char *, int); char *alloc(int); even after, the source file import their standard libraries in the beginning. #include #include isn't their declaration is done in their header...
Tom_the_cat
2

votes
6

answer
105

views

Algorithm, Big O notation: Is this function O(n^2) ? or O(n)?

This is code from a algorithm book, 'Data structures and Algorithms in Java, 6th Edition.' by by Michael T. GoodRich, Roberto Tamassia, and Michael H. Goldwasser public static String repeat1(char c, int n) { String answer = ''; for(int j=0; j < n; j++) { answer += c; } return answer; } According t...
Tom_the_cat
2

votes
4

answer
83

views

How to properly using EOF?

I have question about EOF. First of all, I am coding a simple program that is coping/printing the user's input. However, the program copies the EOF also in the output. For an example, my O.S is Window and my EOF works when I type (Enter -> cntrl + z -> Enter) in order. If I input 'Hello' + Enter +...
Tom_the_cat
2

votes
1

answer
35

views

Using atan2() to find the intersection point of objects in a Brick Breaker game

I am looking at a source code of a brick breaker game created by r3ticuli(an user of GitHub). The below method checks whether two objects intersect each other or not, and if they do, the method checks and returns which part of the main object is touched by the other. The method is part of GameObject...
Tom_the_cat