不知道在我的代码中写什么 import java.util.ArrayList; 公开课工作表{ 私有数组列表数据; 私有字符串标题; /** *创建具有给定标题的新工作表 * *@param title */ 公共工作表(字符串标题){ 数据=新的ArrayList(); this.title=标题; } /** *@返回数据的浅拷贝 */ 公共ArrayList getData(){ 返回数据; } /** *@返回工作表的标题 */ 公共字符串getTitle(){ 返回标题; } /** *@param行 *@param列 *@给定行和列的项目返回值(如果有),否则为空 */ 公共双get(int行,int列){ 双retVal=null; for(数据输入:数据){ if(dataEntry.getColumn()==column&&dataEntry.getRow()==row){ retVal=dataEntry.getValue(); } } 返回返回; } /** *将给定行和列的DataEntry对象的值设置为给定值 *
*如果给定行和列的DataEntry对象已存在,请覆盖当前值 *如果给定行和列的DataEntry对象不存在,请添加新的DataEntry对象 *将给定的行、列、值添加到列表中。 * *@param行 *@param列 *@param val */ 公共无效集(int行、int列、双val){ 布尔值isNew=true; for(数据输入:数据){ if(dataEntry.getColumn()==column&&dataEntry.getRow()==row){ dataEntry.setValue(val); isNew=false; } } 如果(是新的){ DataEntry newData=新DataEntry(); newData.setColumn(column); newData.setRow(行); newData.setValue(val); data.add(newData); } } /** *@param行 *@param列 *@返回列表数据中具有给定行和列的DataEntry对象的索引 *如果未找到此类数据项对象,则返回-1 */ 公共int indexOf(int行,int列){ Double value=this.get(行、列); if(值!=null){ for(数据输入:数据){ if(dataEntry.getColumn()==column&&dataEntry.getRow()==row){ 返回data.indexOf(数据输入); } } } 返回-1; } }不知道在我的代码中写什么 import java.util.ArrayList; 公开课工作表{ 私有数组列表数据; 私有字符串标题; /** *创建具有给定标题的新工作表 * *@param title */ 公共工作表(字符串标题){ 数据=新的ArrayList(); this.title=标题; } /** *@返回数据的浅拷贝 */ 公共ArrayList getData(){ 返回数据; } /** *@返回工作表的标题 */ 公共字符串getTitle(){ 返回标题; } /** *@param行 *@param列 *@给定行和列的项目返回值(如果有),否则为空 */ 公共双get(int行,int列){ 双retVal=null; for(数据输入:数据){ if(dataEntry.getColumn()==column&&dataEntry.getRow()==row){ retVal=dataEntry.getValue(); } } 返回返回; } /** *将给定行和列的DataEntry对象的值设置为给定值 *,java,Java,*如果给定行和列的DataEntry对象已存在,请覆盖当前值 *如果给定行和列的DataEntry对象不存在,请添加新的DataEntry对象 *将给定的行、列、值添加到列表中。 * *@param行 *@param列 *@param val */ 公共无效集(int行、int列、双val){ 布尔值isNew=true; for(数据输入:数据){ if(dataEntry.getColumn()==column&&dataEntry.getRow()==row){ dataEntry.set
这应该对你有用阅读方法上面的评论,它解释了应该预期的行为我已经阅读了评论,我只是不知道在方法里面写什么。尚未在
ArrayList
中为行和列Look创建变量,它应该包含什么类型的对象?对于您需要做什么,这应该是一个很大的提示。如果给定行和列的DataEntry对象有人能告诉我它们的意思吗,我正在努力理解该怎么做
public class Client {
private ArrayList<DataEntry> data;
private String title;
/**
* create a new worksheet with given title
* @param title
*/
public Worksheet(String title) {
data = new ArrayList<DataEntry>();
this.title = title;
}
/**
* @return a shallow copy of the data
*/
public ArrayList<DataEntry> getData() {
return data;
}
/**
*
* @return title of the worksheet
*/
public String getTitle() {
return title;
}
/**
*
* @param row
* @param column
* @return value of item at given row and column (if any), null otherwise
*/
public Double get(int row, int column) {
return null; // to be completed
}
/**
* set the value of DataEntry object at given row and column to given value
*
* if a DataEntry object for given row and column already exists, overwrite the current value
* if a DataEntry object for given row and column doesn't exist, add a new DataEntry object
* with given row, column, value to the list.
* @param row
* @param column
* @param val
*/
public void set(int row, int column, double val) {
//to be completed
}
/**
*
* @param row
* @param column
* @return index of DataEntry object in list data with given row and column
* return -1 if no such DataEntry object found
*/
public int indexOf(int row, int column) {
this.get(row, column);
return 0; //to be completed
}
}
public void setRow(int r) {
row = Math.max(0, r);
}
import java.util.ArrayList;
public class Worksheet {
private ArrayList<DataEntry> data;
private String title;
/**
* create a new worksheet with given title
*
* @param title
*/
public Worksheet(String title) {
data = new ArrayList<DataEntry>();
this.title = title;
}
/**
* @return a shallow copy of the data
*/
public ArrayList<DataEntry> getData() {
return data;
}
/**
* @return title of the worksheet
*/
public String getTitle() {
return title;
}
/**
* @param row
* @param column
* @return value of item at given row and column (if any), null otherwise
*/
public Double get(int row, int column) {
Double retVal = null;
for (DataEntry dataEntry : data) {
if (dataEntry.getColumn() == column && dataEntry.getRow() == row) {
retVal = dataEntry.getValue();
}
}
return retVal;
}
/**
* set the value of DataEntry object at given row and column to given value
* <p>
* if a DataEntry object for given row and column already exists, overwrite the current value
* if a DataEntry object for given row and column doesn't exist, add a new DataEntry object
* with given row, column, value to the list.
*
* @param row
* @param column
* @param val
*/
public void set(int row, int column, double val) {
boolean isNew = true;
for (DataEntry dataEntry : data) {
if (dataEntry.getColumn() == column && dataEntry.getRow() == row) {
dataEntry.setValue(val);
isNew = false;
}
}
if (isNew) {
DataEntry newData = new DataEntry();
newData.setColumn(column);
newData.setRow(row);
newData.setValue(val);
data.add(newData);
}
}
/**
* @param row
* @param column
* @return index of DataEntry object in list data with given row and column
* return -1 if no such DataEntry object found
*/
public int indexOf(int row, int column) {
Double value = this.get(row, column);
if (value != null) {
for (DataEntry dataEntry : data) {
if (dataEntry.getColumn() == column && dataEntry.getRow() == row) {
return data.indexOf(dataEntry);
}
}
}
return -1;
}
}