Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The basic form of the class is

    Java Code:
    class SumGPA implements StudentStatisticCalculator{
      String name;
      //constructor to initialize name
    
      public String getName(){
        return name;
      }
    
      public double computeStatistic(Student[] students){
        Declare sum
        loop
          Add each item in the array to sum
        End loop
        Return sum.
      }
    }

  2. #22
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    public class SumGpa implements StudentStatisticCalculator {

    String name;


    public SumGpa(){
    }

    public String getName(){
    return name;
    }


    public double computeStatistic(Student[] students){

    double sum = 0;
    for (double i = 1; sum <= i; i++) {
    i+= sum;
    }
    return sum;

    }

    }

  3. #23
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That's close, except you want to add the item in the array argument to sum. Right now you are just doing i = i + 0

  4. #24
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

    Default

    My brain is probably not functioning correctly. I was wonder how do i get the constructor.

    public class SumGpa implements StudentStatisticCalculator {

    String name;



    public SumGpa(){
    }

    public String getName(){
    return name;
    }


    public double computeStatistic(Student[] students){

    double sum = 0;
    for(double i =1; i <=students.length;i++) {
    i+= sum;
    }
    return sum;

    }

    }

  5. #25
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The constructor is really not too important, getting the method correct is the important thing.

  6. #26
    hoangx87 is offline Member
    Join Date
    Mar 2011
    Posts
    44
    Rep Power
    0

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Steps to write code to implement attachment feature
    By kishan in forum Advanced Java
    Replies: 6
    Last Post: 05-04-2009, 10:47 AM
  2. how to implement interface
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 12-09-2008, 02:39 PM
  3. Can generic types implement an interface?
    By jdgallag in forum New To Java
    Replies: 3
    Last Post: 10-30-2008, 04:07 AM
  4. Replies: 1
    Last Post: 10-20-2008, 12:58 PM
  5. How to implement the Icon interface in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:17 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
  •