hello frnds ,
I am very much new to Java and have some couple of questions. Can someone please help me out.
In the Profiling directory, you will find the following files:
Item.java
ShoppingCart.java
Inventory.java
ShoppingCartManager.java
TestShop.java
Write an aspect called ProfileAspect that profiles the application, and counts the total number of
method calls made during the execution of the program. Observe the following requirements:
Count every method call, including method invocations that are made from inside of one method.
Include calls to constructors.
Include calls to methods in the Java library, but don’t include calls made by the library methods to
other methods.
Do not include method calls made by the advice in your aspect.
At the end of the program, print the following message:
The total number of method calls made in this program is: <???>
inventory.java
package ps; import java.util.*; public class Inventory { private List _items = new Vector(); public void addItem(Item item) { _items.add(item); } public void removeItem(Item item) { _items.remove(item); } }
Item.java
package ps; public class Item { private String _id; private float _price; public Item(String id, float price) { _id = id; _price = price; } public String getID() { return _id; } public float getPrice() { return _price; } public String toString() { return "Item: " + _id; } }
ShoppingCart.java
package ps; import java.util.*; public class ShoppingCart { private List _items = new Vector(); public void addItem(Item item) { _items.add(item); } public void removeItem(Item item) { _items.remove(item); } public void empty() { _items.clear(); } public float totalValue() { int i = 0; float total = 0; while (i < _items.size()) { total += ((Item)_items.get(i)).getPrice(); i++; } return total; } }
Shoppngcartmanager.java
package ps; public class ShoppingCartManager { public void addShoppingCartItem(ShoppingCart sc, Inventory inv, Item item) { inv.removeItem(item); sc.addItem(item); } public void removeShoppingCartItem(ShoppingCart sc, Inventory inv, Item item) { sc.removeItem(item); inv.addItem(item); } }
Testshop.java
Please someone do help me!!! its very mportantpackage ps; public class TestShop { public static void main(String[] args) { Inventory inventory = new Inventory(); ShoppingCart sc = new ShoppingCart(); ShoppingCartManager scm = new ShoppingCartManager(); Item item1 = new Item("1", 20); Item item2 = new Item("2", 40); Item item3 = new Item("3", 60); inventory.addItem(item1); inventory.addItem(item2); inventory.addItem(item3); System.out.println("Value of shopping cart = " + sc.totalValue()); scm.addShoppingCartItem(sc, inventory, item1); System.out.println("Value of shopping cart = " + sc.totalValue()); scm.addShoppingCartItem(sc, inventory, item2); System.out.println("Value of shopping cart = " + sc.totalValue()); } }
Thnxx n advance
Regards
Shlpz