Percentile Class Java with Arrays

NEed HELP starting it off..not sure what im doing wrong..Please!

Page 1 of 1

1 Replies - 2604 Views - Last Post: 25 February 2010 - 01:05 AM Rate Topic: -----

#1 shorty246  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-February 10

Percentile Class Java with Arrays

Posted 25 February 2010 - 12:08 AM

NEed HELP starting it off..not sure what im doing wrong..Please!!

The Percentile class
The constructor of your class should have one parameter representing the capacity of the array that the class will contain. The array should be a double array with its length equal to the capacity. You will also need to keep track of how many values have been added to the array (called the "size" of the array), which will be initially 0. The capacity and size will correspond to fields of the Percentile class and should have accessor methods for the size and capacity. However, do not provide an accessor method for the array. The Percentile class should also have a toString method that returns a String describing the object, including elements of the array. The elements of the array should be listed on a single line, separated by commas. There should not be a comma after the last element.
Also create a PercentileTester class that will have a main method that will start by printing a line containing your name. It will then test the Percentile class by constructing several instances and printing enough information to test the accessor and toString methods of the class.

package pr02;

public class Percentile {
private int mySize = 0;
private double myCapacity;
private double [] array;
//private Percentile[] array; 
//private double [] myArray = new double[myCapacity];

public Percentile(double[] capacity){
array = capacity;

}

public double getCapacity(){
return myCapacity;
}

public int getSize(){
return mySize;
}

public String toString(){
return "The Capacity is " + myCapacity+ "and the Size is" +mySize;
}

}


This post has been edited by pbl: 25 February 2010 - 08:09 PM
Reason for edit:: Code tags added because it is your first post. Welcome at DIC


Is This A Good Question/Topic? 0
  • +

Replies To: Percentile Class Java with Arrays

#2 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 120
  • View blog
  • Posts: 710
  • Joined: 15-October 09

Re: Percentile Class Java with Arrays

Posted 25 February 2010 - 01:05 AM

(Please, :code:)


View Postshorty246, on 25 February 2010 - 06:08 AM, said:

public Percentile(double[] capacity){
array = capacity;

}



The capacity of your is actually the maximum number of elements your array will be able to hold, so its type cannot be double[]; it will probably be an int used to initialize the size of the array with new double[capacity]. You then have to store it in an instance variable.

Read the text your assignment carefully because everything is given in there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1