Question about class method in java. I have the class as follow: class Cellphone { public String brand; public long serialNumber; public double price; //these are the 3 declarations of the attribute brand, serialNumber, and price (respectively) public Cellphone(String br, long sN, double Pr) { brand = br; serialNumber = sN; price = Pr; //this creates a constructor for when an object is created } and I have to create a method that allows me to compare different object created in my main method ( i.e: cell_1 vs cell_2)
Didn't really see a question in there, but I'll show you what I think you want to see. Below is the method I created that checks if cell_1 matches cell_2. private boolean checkCellphone(Cellphone cell_1, Cellphone cell_2) { boolean test = false; //Here it is checking the variables to make sure they are the same. If they are, it returns true, if not it will continue through the method and return false. if (cell_1.brand == cell_2.brand && cell_1.serialNumber == cell_2.serialNumber && cell_1.price == cell_2.price) { test = true; } return test; } I hope this helped.
Join our real-time social learning platform and learn together with your friends!