Question: COMPLETE THE FOLLOWING CODE USING JAVA: 1. In the class Item, write the method equals: the method takes as input an Object other, if the

COMPLETE THE FOLLOWING CODE USING JAVA: 1. In the class Item, write the method equals: the method takes as input an Object other, if the other Object is an Item and the name of the other is equal to the name of the calling object, the method return true. Otherwise, the method returns false.

// Write your code in the class

  1. In the class Shop, write the method HasItem: the method takes as input an Item itm. It returns -1 if the given Item (itm) is not found in the array (items). It returns the index of its position if it is found in the array.

// Write your code in the class

  1. In the class Shop, write the method addItem: the method takes as input an Item itm. If the Item is not in the array items, it adds the item to the array items and returns true. Otherwise, it returns false.

// Write your code in the class

public class Item {

private String name;

private int Qty;

public Item(String name, int Qty){

this.name = name;

this.Qty = Qty;

}

// 1.Complete the code for the method equals

public boolean equals(Object other){

}

}

public class Shop {

private int ID;

private Item[] items=new Item[20];

public Shop(int ID){

this.ID = ID;

}

// 2. Complete the code for the method HasItem

public int HasItem(Item it){

}

// 3. Complete the code for the method addItem

public boolean addItem(Item itm){

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!