Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Urgent Doubts

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Urgent Doubts

    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
    package 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());
        }
    }
    Please someone do help me!!! its very mportant


    Thnxx n advance

    Regards
    Shlpz
    Last edited by helloworld922; November 12th, 2009 at 10:23 PM. Reason: Please use [code] tags


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Location
    Home-Ujjain /Job-Mumbai
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: Urgent Doubts

    Hi Dear,
    I am not understanding your problem properly but if you want to count all method calls then try this

    public class CountCalls
    {
    public static int count=0;
    }

    And from each method (which calls you want to count) call this as
    method()
    {
    CountCalls.count++;
    }

    And in last print the CountCalls.count
    I think this will work
    Programmer

Similar Threads

  1. Credit and thrift society application(urgent)
    By 5723 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 3rd, 2009, 03:44 AM
  2. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM
  3. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM
  4. Replies: 1
    Last Post: May 4th, 2009, 06:30 AM