Question: // I need help filling the empty methods public class Smartphone { private String brand; private String model; private int price; public Smartphone(String brand, String
// I need help filling the empty methods
public class Smartphone {
private String brand; private String model; private int price; public Smartphone(String brand, String model, int price) { super(); this.brand = brand; this.model = model; this.price = price; } @Override public boolean equals(Object c2) { if (!(c2 instanceof Smartphone)) { throw new RuntimeException("Illegal argument to Smarthphone.equals()"); } Smartphone phone2 = (Smartphone) c2; return ((this.getBrand().equals(phone2.getBrand())) && (this.getModel().equals(phone2.getModel())) && (this.getPrice() == phone2.getPrice())); }
@Override public String toString() { return "Smartphone[" + brand + "," + model + "," + price + "]"; }
public String getBrand() { return brand; }
public String getModel() { return model; }
public int getPrice() { return price; } // returns the count of smartphones of a the same brand as the target phone in the given stock public int countSameBrand(Smartphone[] stock) { return 0; //dummy return } // returns true if the target phone is in stock public boolean isAvailable(Smartphone[] stock) { return false; //dummy return } // returns the phone in stock with the highest price. public static Smartphone highestPrice(Smartphone[] stock) { return null; //dummy return } //returns a new array of Smartphones with prices equal or lower than the given budget in the given stock //the array to return must have valid contiguous positions(there cannot be void //spaces in between). public static Smartphone[] phonesInBudget(Smartphone[] stock, int budget) { return null; // dummy return } // returns the specific smartphone that is equal to the model that the customer is looking for. // returns null if the desired model is not in stock. // Must stop looking as soon as the first Smartphone with the desired model is found. public static Smartphone findModel(Smartphone[] stock, String model) { return null; // dummy return } //returns true iff there are at least two Smartphone's with the same model in stock. //Must stop as soon as the pair is found. //Hint: do not compare the phones in the same position //(stock[0].getModel().equals(stock[0].getModel) will yield true but is not corect public static boolean twoWithSameModelExist(Smartphone stock[]) { return false; // dummy return } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
