In: Computer Science
String Owner
String Food_Items[100]
Double Price [100]
Int Quantity [100]
Note:
Methods:
Two Constructors (default, four-argument)
set for Owner , get for Owner
display()
addFooditem (?) // Adds a food item, its price, and its quantity in the first available free slot in Food_Items, price and quantity array
buy (?) //decrement quantity if more than one item is present. If only one item is present then the item should be removed from Food_Item array.
compareTwoShops ( ? ) //compare two shops and return the shop with more items.
compareOwner ( ? ) //compare owners of two shops and return true if both owners are same and false otherwise.
Note:
Do not add data members at your own.
Declare data as private
Do not create set and get methods for array data members as they cannot be updated independent of each other.
‘?’ means that you need to identify the arguments if they are required.
Runner:
In the runner create two objects and all the above function.
in java or in C#
package inter;
public class TuckShop {
private String owner;
private String food_items[];
private double price[];
private int quantity[];
int i=0;
public TuckShop(String owner, String[] food_items, double[] price, int[] quantity) {
this.owner = owner;
this.food_items = food_items;
this.price = price;
this.quantity = quantity;
}
public void display()
{
System.out.println(getOwner());
}
public void addFoodItem(String food_item,double pr,int quant)
{
i++;
food_items[i]=food_item;
price[i]=pr;
quantity[i]=quant;
}
public void addFoodItem(String food_item)
{
for(int j=0;j<food_items.length;j++)
{
if(food_items[j].equals(food_item))
{
if(quantity[j]>1)
{
quantity[j]--;
}
else
{
System.out.println("Not available");
}
}
}
}
public int compareShop(TuckShop tuckshop2)
{
return this.food_items.length-tuckshop2.food_items.length;
}
public boolean compareOwner(TuckShop tuckshop2)
{
return this.getOwner().equals(tuckshop2.getOwner());
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
}