here is the code, assuse all other mathods in this code are well-definded. publi
ID: 3604052 • Letter: H
Question
here is the code, assuse all other mathods in this code are well-definded.
public class Worksheet {
private ArrayList data;
// DataEntry object contains row in int,column in int and value in double
private String title;
/**
* create a new worksheet with given title
* @param title
*/
public Worksheet(String title) {
data = new ArrayList();
this.title = title;
}
/**
* @return a shallow copy of the data
*/
public ArrayList getData() {
return data;
}
/**
*
* @return title of the worksheet
*/
public String getTitle() {
return title;
}
public Double get(int row, int column) {
//this mathod is well defined
}
public int indexOf(int row, int column) {
//well defined,
//index of DataEntry object in list data with given row and column
//* return -1 if no such DataEntry object found
}public int count(int row1, int column1, int row2, int column2) {
// well defined,
//return number of DataEntry objects in given address range , 0 if none
//* ((row1, column1) to (row2, column2))
}
public int count(int row1, int column1, int row2, int column2) {
//return number of DataEntry objects in given address range , 0 if none
//* ((row1, column1) to (row2, column2))
}
public double total(int row1, int column1, int row2, int column2) {
/*@return sum of values of all DataEntry objects in given address range
* ((row1, column1) to (row2, column2))
* return 0 if there are no items in the given range
*/
}
public double average(int row1, int column1, int row2, int column2) {
/*@return average of values of all DataEntry objects in given address range
* ((row1, column1) to (row2, column2))
* return 0 if there are no items in the given range
*/
}
public Integer minRow() {
}
public Integer maxRow() {
}
/**
*
* @return value of the last/first column/raw for which there is a DataEntry object
* in the list data
* return null if there is no data
*/
public Integer minColumn() {
}
public Integer maxColumn() {
}
public ArrayList getDataByRow(int row) {
@return list of values of data items from given row
* return empty list if no items belong to the given row
*/
}
public ArrayList getDataByColumn(int column) {
@return list of values of data items from given column
* return empty list if no items belong to the given column
*/
}
public String toString() {
//how to define this method?
}
}
A(e) B(1) C(2) D(3)... AC (28) 2.5 1 2 4.5 .5Explanation / Answer
From this input what you provided i see you have not provided clear informationn.
If my understanding is correct you are expecting more details about toString()0 method in Java:
toString() method is defined in Object class, having by default Object class is root class of all the classes you will have toString() method in your class by default.
Purpose of toString() method:
The main purpose of toString() method is when eer you display object it will get content address of object class ( this content is returned from toString 90 method of Object class( Hvaing jvm internally calls ( toString() mthod when you try to display reference variable and by defualt it will return address of class)
If you don't want to display address of class and display your class own data you can override toString() method in your class and return String which you want to display ( for example id and name or some other details you return that variable which name or id is storing).
for example:
Object o = new Object();
System.out.println(o); // displays address of Object class
String s= new STring("Test"); // Displays content of string object instead of address of Stirng class, the main reason for this is in String class they have overriden toString() method and return content of string instead of address of object
public class Worksheet {
private ArrayList data;
// DataEntry object contains row in int,column in int and value in double
private String title;
/**
* create a new worksheet with given title
* @param title
*/
public Worksheet(String title) {
data = new ArrayList();
this.title = title;
}
/**
* @return a shallow copy of the data
*/
public ArrayList getData() {
return data;
}
/**
*
* @return title of the worksheet
*/
public String getTitle() {
return title;
}
public Double get(int row, int column) {
//this mathod is well defined
}
public int indexOf(int row, int column) {
//well defined,
//index of DataEntry object in list data with given row and column
//* return -1 if no such DataEntry object found
}public int count(int row1, int column1, int row2, int column2) {
// well defined,
//return number of DataEntry objects in given address range , 0 if none
//* ((row1, column1) to (row2, column2))
}
public int count(int row1, int column1, int row2, int column2) {
//return number of DataEntry objects in given address range , 0 if none
//* ((row1, column1) to (row2, column2))
}
public double total(int row1, int column1, int row2, int column2) {
/*@return sum of values of all DataEntry objects in given address range
* ((row1, column1) to (row2, column2))
* return 0 if there are no items in the given range
*/
}
public double average(int row1, int column1, int row2, int column2) {
/*@return average of values of all DataEntry objects in given address range
* ((row1, column1) to (row2, column2))
* return 0 if there are no items in the given range
*/
}
public Integer minRow() {
}
public Integer maxRow() {
}
/**
*
* @return value of the last/first column/raw for which there is a DataEntry object
* in the list data
* return null if there is no data
*/
public Integer minColumn() {
}
public Integer maxColumn() {
}
public ArrayList getDataByRow(int row) {
@return list of values of data items from given row
* return empty list if no items belong to the given row
*/
}
public ArrayList getDataByColumn(int column) {
@return list of values of data items from given column
* return empty list if no items belong to the given column
*/
}
public String toString() {
// writing to convert List to String because from toString() we have to return String object only.
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.