1

I have a ProcessHeap class that has two fields:

Heap: an array of type Process which represents the heap

Size: the number of elements in the heap

My constructor and attributes look like this:

private Process[] heap;
private int size;
private static int counter = 0;

//Paramaterized construct
    public ProcessHeap(Process[] heap, int size) {
        this.heap = heap;
        this.size = size;

The problem is, we were given a driver and at the start of the driver I am getting an error particularly on (HEAP_SIZE)

This is the line:

final int HEAP_SIZE = 100;
ProcessHeap heap = new ProcessHeap(HEAP_SIZE); // gives this error:

The error upon mouse-over states:

ProcessHeap (Process[], int) in ProcessHeap cannot be applied to (int)

GhostCat
  • 127,190
  • 21
  • 146
  • 218

5 Answers5

1

As others have said; your direct problem is that you want only have one constructor taking two arguments, but then you are invoking it with one argument. But beyond that, you are over-complicating things:

class ProcessHeap {
  private final Process[] heap;

 public ProcessHeap(int size) {
   heap = new Process[size];
 }

is all that you need and should use. There is no point in tracking size and array in two places. You can always do heap.length to get the size of your heap. And beyond that: you absolutely do not want that users of this class have to provide an array for your heap - because they could just go and manipulate that array later on.

Your class implements that heap; and that you are using an array to do that is an implementation detail that you should not at all communicate to the outside world.

GhostCat
  • 127,190
  • 21
  • 146
  • 218
0

Your constructor ProcessHeap is taking 2 parameters (an array and an integer), you are passing only one...

So you need either to change the params in the constructor:

ProcessHeap(Process[] heap, int size) and remove the arraay, OR overload it defining a new one taking only an integer.

ΦXocę 웃 Пepeúpa ツ
  • 43,054
  • 16
  • 58
  • 83
0

In your ProcessHeap class, you don't have a constructor which takes int argument, so declare it as shown below:

public class ProcessHeap {

   private int heapSize;

    public ProcessHeap(int heapSize) {
      this.heapSize = heapSize;
    }

    //your other existing code

}
developer
  • 19,553
  • 8
  • 40
  • 57
  • that wouldn't go along with what the ProcessHeap is supposed to do, at least the constructor should initialize the process array – Japu_D_Cret Mar 29 '17 at 06:30
  • Exactly. This answer is technically correct, but doesn't make any sense regarding the context. – GhostCat Mar 29 '17 at 06:34
0

the problem

you have a constructor ProcessHeap(Process[] heap, int size) but try to call it here new ProcessHeap(HEAP_SIZE) with only an int - so the compiler stops and warns you that the parameters do not match up

how to fix it?

you either have to change the constructor/add a constructor, which I guess you can't, cause its for your assignment

the other option is that you pass an already created array of processes

final int HEAP_SIZE = 100;

final Process[] processHeap = new Process[HEAP_SIZE];

ProcessHeap heap = new ProcessHeap(processHeap , HEAP_SIZE);
Japu_D_Cret
  • 591
  • 4
  • 17
0

You need to define one parameter constructor also because you are passing only singleInteger value. At the time of Instantiate the ProcessHeap class.

    private Process[] heap;
    private int size;
    private static int counter = 0;

    //One Paramaterized construct 
     public ProcessHeap( int size) {
            this.size = size;
     }

    //Two Paramaterized construct
     public ProcessHeap(Process[] heap, int size) {
            this.heap = heap;
            this.size = size;
     }

Now you cal call your Constructor As you desired.

Like This

final int HEAP_SIZE = 100;

final Process[] processHeap = new Process[HEAP_SIZE];

ProcessHeap heap = new ProcessHeap(HEAP_SIZE); 
ProcessHeap heap1 = new ProcessHeap(processHeap , HEAP_SIZE); 
Raj S. Rusia
  • 640
  • 7
  • 14