Question: Java Implement a class, called Combination, to store four integer values (ints). 1. Declare the necessary instance variables to store the four integer values 2.
Java Implement a class, called Combination, to store four integer values (ints).
1. Declare the necessary instance variables to store the four integer values
2. Create a constructor, public Combination(int rst, int second, int third,
int fourth), to initialize the values of this object
3. Implement the instance method public boolean equals(Combination other),
such that equals return true if other contains the same values, in the same
order, as this Combination; the order is dened by the order of the pa-
rameters of the constructor, given the following:
Combination c1;
c1 = new Combination( 1, 2, 3, 4 );
Combination c2;
c2 = new Combination( 1, 2, 3, 4 );
Combination c3;
c3 = new Combination( 4, 3, 2, 1 );
then c1.equals(c2) is true but c1.equals(c3) is false;
4. Finally, implement the method public String toString(), to return a String
representation of this object, where the rst, second, third and fourth
values are concatenated and separated by : symbols. E.g.
Combination c1;
c1 = new Combination( 1, 2, 3, 4 );
System.out.println( c1 );
displays 1:2:3.
The interface of the class Combination consists therefore of its constructor,
the method equals and the method toString. Ideally, the input data should be
validated. In particular, all the values should be in the range 1 to 10. However,
since we do not yet have the tools to handle exceptional situations, we will
assume (for now) that all the input data are valid!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
