  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # How program arithmetics on general objects which become defined only later?  » java » How program arithmetics on general objects which become defined only later?

By : kachergg
Date : November 25 2020, 04:01 AM
this will help The basic arithmetic operations are addition, subtraction, multiplication and division. And these are essentially Algebraic Operations. This means that they are operations on an algebraic structure, and the structure is essentially what you tried to model with your interface. Specifically, the structure that you need for these operations is a Field.
There already are libraries that model a Field class and give a glimpse at how complicated this can be if you're trying to do it right. In the purest sense, there is no such thing as "subtraction", but only the addition of the inverse element. Similarly, a division is the multiplication with the multiplicative inverse, with 0.0 being the odd case where no such element exists. Ouch. code :
``````class Arithmetic
{
static <T> GeneralNumber<T> computeSomething(
GeneralNumber<T> a, GeneralNumber<T> b)
{
GeneralNumber<T> c = a.add(b);             // c      = a + b
GeneralNumber<T> d = c.additiveInverse();  // d      = -c
GeneralNumber<T> result = c.multiply(d);   // result = c * d
return result;
}
}

interface GeneralNumber<T>
{
T get();

GeneralNumber<T> multiply(GeneralNumber<T> a);
GeneralNumber<T> multiplicativeInverse();
GeneralNumber<T> multiplicativeNeutral();
}

class GeneralDoubleNumber implements GeneralNumber<Double>
{
static GeneralDoubleNumber of(double d)
{
return new GeneralDoubleNumber(d);
}

private final double value;
public GeneralDoubleNumber(double d)
{
this.value = d;
}

@Override
public Double get()
{
return value;
}

@Override
{
return of(get() + a.get());
}

@Override
{
return of(-get());
}

@Override
{
return of(0.0);
}

@Override
public GeneralNumber<Double> multiply(GeneralNumber<Double> a)
{
return of(get() * a.get());
}

@Override
public GeneralNumber<Double> multiplicativeInverse()
{
return of(1.0 / get());
}

@Override
public GeneralNumber<Double> multiplicativeNeutral()
{
return of(1.0);
}

}
`````` ## Socket program to send and receive user defined objects not working

By : amc
Date : March 29 2020, 07:55 AM
I hope this helps . You need to create the ObjectOutputStream before the ObjectInputStream at both ends.
The reason is that, as described in the Javadoc, the respective constructors write and read a stream header. So the input stream constructor can't return until the output stream constructor at the peer has executed. So if you construct both input streams first there is a deadlock. ## from x(defined in program) import y(defined in program) python

By : Sheela Selvaraj
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can't use a variable for an import statement.
from x import y will try to find a module literally called y. In your case, that probably means you want a file in the same directory called y.py. It will then try to find a variable (including, eg, a function or class name) in that module which is literally called x - ie, you need to do something in that file like:
code :
``````x = 5
``````
``````def x():
return 5
``````
``````from test import test2
`````` ## My Ruby Program prints inspect of objects instead of defined to_s method

By : Abhishek Kumar
Date : March 29 2020, 07:55 AM
like below fixes the issue When providing to_s method in Player class you're actually printing them on screen instead of returning.
Change to_s method in Player class to:
code :
``````def to_s
"<#{@name}: #{@skill_level}(SL), #{@age}(AGE)"
end
``````
``````puts "a"
a
#=> nil
``````
``````class A
def to_s
nil
end
end

a = A.new
#=> #<A:0x007fbfca06f770>

puts a
#<A:0x007fbfca06f770>
#=> nil
`````` ## can't make this prolog program work, prolog rules, 'or' operator, prolog arithmetics

By : rgba
Date : March 29 2020, 07:55 AM
wish helps you There are a couple of things to mention with respect to the question posting.
You listed example facts as:
code :
``````COBOL, 1960
PASCAL, 1971
C, 1971
``````
``````language('COBOL', 1960).
language('PASCAL', 1971).
language('C', 1971).
``````
``````lang_precedes_decade(Lp, L) :-
( language(Lp, X),
language(L, Y),
((X-Y) > 9) )
; ((X-Y) < -9).
``````
``````lang_precedes_decade(Lp, L) :-
language(Lp, X),
language(L, Y),
( ((X-Y) > 9); ((X-Y) < -9) ).
``````
``````| ?- lang_precedes_decade(Lp, L).

L = 'PASCAL'
Lp = 'COBOL' ? ;

L = 'C'
Lp = 'COBOL' ? ;

L = 'COBOL'
Lp = 'PASCAL' ? ;

L = 'COBOL'
Lp = 'C' ? ;

no
``````
``````lang_precedes_decade(Lp, L) :-
language(Lp, YearLp),
language(L, YearL),
(YearL-YearLp) > 9.    % Lp precedes L
``````
``````| ?- lang_precedes_decade(Lp, L).

L = 'PASCAL'
Lp = 'COBOL' ? a

L = 'C'
Lp = 'COBOL'

no
| ?-
`````` ## How come DOM objects display differently in console than general Javascript objects?

By : Sebastian
Date : March 29 2020, 07:55 AM
it fixes the issue I assume that the Console (which has been created to work within a web browser) has special logic coded into it to make it more pleasant to work with DOM elements and integrate with other parts of the IDE (such as the web inspector). That way, there is nothing special in the DOM object itself, and it is probably not something you can hook into, at least not in a portable (cross-browser) fashion. 