Results 1 to 3 of 3
  1. #1
    vipergt89 is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Default Calculating per hour statistics

    Hey all,
    Ive got a relatively simple question, and i understand why it doesnt work, but i was wondering if anyone had any suggestions or ideas on how to get it to work.

    I am creating a discrete event simulator that takes customers, adds them to a wait line, and then to a teller if the teller is not busy.

    I am supposed to return statistics as customers leave, such as wait time, completion time and **Average wait per hour** that means that for every hour, i need to calculate what the current average wait time is.

    My code for average wait per hour:

    public int averageWaitPerHour(){
    double a = 0;
    a = Clock.currentTime();
    if(a % 60 == 0)
    System.out.println("Running average: " + averageTime());
    }


    the error i am getting is that im referenceing a non static method from a static context, which i understand, i cannot assign variable a to Clock.currentTime().

    I was just wondering if anyone had any suggestions on how i could return this with a non-static variable.

    Thanks

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    Lol I just finished this project. It took me 13 classes, which just happens to be my favorite number. This project was for my 102 class, and me and a friend worked on it together. It was a cool way to learn about queues.
    My IP address is 127.0.0.1

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    referenceing a non static method from a static context
    Java Code:
    // Calling a static method.
    double a = Clock.currentTime();
    
    // Calling an instance method.
    Clock clock = new Clock();
    double a = clock.currentTime();
    
    class Clock {
        double currentTime() {
            System.out.println("instance method");
            return time;
        }
    
        static double currentTime() {
            System.out.println("static method/context");
            return time;
        }
    }

Similar Threads

  1. To display performance statistics as graphs using JSP, Spring and JBoss
    By sheeba in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 03-11-2009, 05:36 PM
  2. Calculating trigonometric functions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:56 PM
  3. Calculating hyperbolic functions
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:55 PM
  4. Calculating the DB connection time
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 08:55 AM
  5. Calculating sin of a double value
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 08:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •