TutorMe homepage
Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Tj P.
4 years of tutoring experience, Software Engineer at FactSet Research Systems
Tutor Satisfaction Guarantee
Java Programming
TutorMe
Question:

Question on Object-Oriented Programming: What is an interface? What is a super class? And what is the difference between the two?

Tj P.
Answer:

An interface is a class in Java that specifies abstract methods, like a guideline or outline to some of the methods an implementing class must contain. The interface solely gives the method header and it is up to any implementing classes to implement the functionality for these methods. In order for a class to implement an interface, they must specifically write functionality for every method header given in the interface. By contrast, a super class is an independent object containing instance variables, methods, and/or abstract methods. A child class inheriting this class must implement any abstract methods the super class contains however any additional instance variables or methods in the super class are inherited to the child class, automatically and without having to re-implement them in the child class. If a child class chooses so, it can rewrite methods from the super class, changing the functionality to something child class specific, this is called overriding. The clearest distinction between an interface and a super class is that, in general, a super class is an object which can act as a standalone class. It can be constructed, manipulated, and used just like any regular object in Java. A child class just extends the functionality of a super class to account for more specific use cases of that object. By contrast, an interface cannot be constructed nor used, as it does not contain anything except for guidelines for which methods an implementing class should use. Interfaces are used to allow for easy transitions and standardization between different types of classes. For example, the Collection interface specifies methods such as 'add()' and 'size()' which allows programmers that are using different types of data structures to use the same method names which makes coding in Java more straightforward. Although the inner-workings of how different data structures use 'add()' vary, the call from the user does not change.

Calculus
TutorMe
Question:

Non-trivial integration by parts question: Evaluate the integral $$\int{e^{x}sin(2x)}dx$$ using integration by parts.

Tj P.
Answer:

All integration by parts follows the form: $$\int{udv}= uv - \int{vdu}$$. Now we must determine what the $$u$$ and $$v$$ should be for our given integral $$\int{e^{x}sin(2x)dx}$$. When choosing a $$u$$ and $$v$$, try to choose a $$u$$ which will have a simpler $$du$$ than the original $$u$$ and avoid a $$dv$$ that gets much more complicated when a $$v$$ is found. For example, $$e^{x}$$ is a poor $$u$$ because the derivative is exactly the same and $$ln(x)$$ is a very poor $$dv$$ since integrating $$ln(x)$$ is more complicated than the original but deriving it makes things much simpler. Although $$u=sin(2x)$$ does not really simplify things much, $$e^{x}$$ is the last choice you want for a $$u$$ so we decide to use the former. Next we find the derivative and integral of the respective variables $$u$$ and $$dv$$. I like to write the $$u$$ and $$dv$$ out as a little table but you can choose how you do it. $$u=sin(2x)$$ | $$dv=e^{x}dx$$ $$du=2cos(2x)dx$$ | $$v=e^{x}$$ Substituting these variables into the integration by parts formula we get: $$\int{e^{x}sin(2x)dx}= sin(2x)e^{x}-2\int{e^{x}cos(2x)dx}$$. This does not seem to simplify things much. When working with cyclical derivatives, particularly $$sin$$, $$cos$$, and $$e^{x}$$, you'll notice that sometimes integration by parts will always yield a similar integral as the original one you started with. To solve this, we must repeat this process once more to obtain the original integral on both sides. Integrating by parts once more with $$\int{e^{x}cos(2x)dx}$$ we decide on: $$u=cos(2x)$$ | $$dv=e^{x}dx$$ $$du=-2sin(2x)dx$$ | $$v=e^{x}$$ $$\int{e^{x}sin(2x)dx}= sin(2x)e^{x} + [- 2cos(2x)e^{x}-4\int{e^{x}sin(2x)dx}]$$ Notice that the integral on the left side of our equation is the same as the integral on the end of the right side of the equation... that is the goal. We can now move the integral from the right side over to the left side, obtaining: $$5\int{e^{x}sin(2x)dx}= sin(2x)e^{x}-2cos(2x)e^{x}$$. Dividing by 5 gives us the solution to our original problem. $$\int{e^{x}sin(2x)dx}=\frac{sin(2x)e^{x}-2cos(2x)e^{x}}{5} + C$$

C++ Programming
TutorMe
Question:

Question about pass-by-reference: You are writing a function 'int foo_compare()' to compare certain values in two Foo objects, which will be referred to inside the function as 'foo1' and 'foo2'. Write the method header for the 'foo_compare()' method and give an example of how to invoke that method within the 'main()' function of a class containing both functions.

Tj P.
Answer:

Any objects containing data bigger than the size of a pointer, which is generally all objects, should be pass-by-reference unless there are specific functional reasons this should not be done. Passing an object by reference passes the function a reference pointer, which points to where the object is stored in memory, instead of copying over all of the data in the object, which takes much longer. This also gives functions the ability to modify the original object from within the function which does not happen if a copy of the object is passed to the function. By default, objects are pass-by-value, so when invoking pass-by-reference the symbol, '&', should be appended to the end of the object type, 'Foo&', or the front of the variable name, '&foo1'. Because this gives the function unlimited access to alter the variable, it is important to think about the permissions needed to be given to the function for each variable. Functions which need to only access the information from a variable (not change it!) should be restricted to such by placing the keyword 'const' in front of the variable type. Keeping all of this in mind, the correct way to write the function header is 'int foo_compare(const Foo &foo1, const &foo2) {}'. While pass-by-reference is specified in the function header, it is not specified when calling the function. To call 'foo_compare()' from main using the Foo objects a1 and a2, simply write the line 'foo_compare(a1, a2);'.

Send a message explaining your
needs and TJ will reply soon.
Contact TJ
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.