Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please! The code that needs to be completed is given below public class Combination { // Instance variables. // Remove this comment and

In java please! The code that needs to be completed is given belowimage text in transcribed

public class Combination { // Instance variables. // Remove this comment and declare your instance variables here // Constructor public Combination( int first, int second, int third ) { // Your code here } // An instance method that compares this object // to other. // Always check that other is not null, i) // an error would occur if you tried to // access other.first if other was null, ii) // null is a valid argument, the method should // simply return false. public boolean equals( Combination other ) { // Put your code here and remove the line below return true; } // Returns a String representation of this Combination. public String toString() { // Put your code here and remove the line below return ""; } }
3. Combination You will hand in this exercise. Download and complete the starter file here: Combination.java. Implement a class, called Combination, to store three integer values (ints). 1. declare the necessary instance variables to store the three integer values; 2. create a constructor, public Combination(int first, int second, int third), to initialize the values of this object. 3. implement the instance method public boolean equals(Combination other), such that equals returns true if other contains the same values, in the same order, as this Combination; the order is defined by the order of the parameters of the constructor, given the following: Combination cl, c2, c3; 1 %3D w Cbination (1, 2, 3); c2 - new Combination(1, 2, 3); c3 - new Combination(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 first, second and third values are concatenated and separated by ":" symbols. E.g. Combination cl; 1 %3D w Cbination(1, 2, 3); System.out.printin(el); 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 5. 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! Note: Simpler code is better and it is worthwhile spending time cleaning up code even if it was already working. Hint: my implementation is approximately 20 lines long, not counting blank lines. This is not a contest to write the shortest class declaration. I am providing this information so that you can evaluate the relative complexity of the tasks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

1. How has the prototype approach identified key features of love?

Answered: 1 week ago