Skip to main content
deleted 7 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

These are the exam questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

These are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

These are the exam questions:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

deleted 7 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

EDIT: TheseThese are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

EDIT: These are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

These are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

added 756 characters in body
Source Link
M-R
  • 237
  • 2
  • 9

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

EDIT: These are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

Java arrays only allow subscripts to range between 0 and N-1 for an array of size N.

The class below aims to remove that constraint by allowing the class user to specify the valid subscripts for a one dimensional array of integers.

public class BoundedIntArray {

 private int[] array;

 // further state required here

 public BoundedIntArray() {…}

 public BoundedIntArray(int high) {…}

 public BoundedIntArray(int low, int high) {…}



 public int length() {…}

 public int getElement(int index) {…}

 public void putElement(int index, int value) {…}

 public void resize(int low, int high) {…}

}

This is a question I was given in a recent exam. I'm struggling to understand quite what the problem is and what the above class is trying to accomplish.

What's wrong with only being allowed to range between 0 and N-1? Why would you want to exceed the size of the array and go beyond N or <0?

What do low and high refer to?

EDIT: These are the questions which I forgot to post. Hopefully they might provide some context:

a). The class needs further private members to identify the upper and lower bounds of the array. Provide appropriate declarations for this state. [4 marks]

b). Supply an implementation of the three constructors for the BoundedIntArray class
[6 marks]

c). Provide an implementation for each method (with appropriate exceptions) for the BoundedIntArray class.
[15 marks]

d). Explain how to generalise this class so that arrays of any type can be used rather than just int’s.
[5 marks]

Source Link
M-R
  • 237
  • 2
  • 9
Loading