Lab Assignment 1
Lab Assignment 1
Note:
All arrays are open ended. It is not necessary that they are completely filled.
All three arrays will work in synchronization with each other i-e the item at
index 0 will have its price in Price array at index 0 and quantity at index 0 of
Quantity array.
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.
Note:
Do not create set and get methods for array data members as they cannot be updated
independent of each other.
Runner:
In the runner one object using default constructor.
Initialize its data by using the set functions.
Create another object using argument constructor.
Call AddFoodItem() and buy() methods
CODE:
OBJECT:
package Assignment;
public tuckShop() {
owner = "Test";
for (int i = 0; i < 100; i++) {
items[i] = "null";
price[i] = 0;
quantity[i] = 0;
}
}
break;
}
}
System.out.println("Item Not Found!\n");
}
}
RUNNER:
package Assignment;
public class tuckShopRun {
public static void main(String[] args){
tuckShop t1 = new tuckShop();
t1.setOwner("Lester");
t1.addItem("Fries", 60, 5);
t1.buy("Apple", 3);
tuckShop t2 = new tuckShop("Twitch", new String[]{"Coffee", "Green Tea"}, new
double[]{50, 20}, new int[]{3, 2});
t2.display();
t2.buy("Green Tea", 2);
t2.display();
}
}
OUTPUT: