Question: public class Workbook { private String title; private ArrayList sheets; /** * copyPaste (16 marks) * * @param sourceIndex * :int - The index of

public class Workbook {

private String title;

private ArrayList sheets;

/**

* copyPaste (16 marks)

*

* @param sourceIndex

* :int - The index of the source worksheet

*

* @param startRowSource

* :int - The starting row index in the source worksheet

*

* @param startColumnSource

* :int - The starting column index in the source worksheet

*

* @param endRowSource

* :int - The ending row index in the source worksheet

*

* @param endColumnSource

* :int - The ending column index in the source worksheet

*

* @param destIndex

* :int - The index of the destination worksheet

*

* @param startRowDest

* :int - The starting row index in the destination worksheet

*

* @param startColumnDest

* :int - The starting column index in the destination worksheet

*

* Copy DataEntry objects from the Worksheet with index `sourceIndex`

* which are located from startRowSource to endRowSource and

* from startColumnSource to endColumnSource (both inclusive).

*

* Paste the copied DataEntry objects into the Worksheet located at destIndex

* starting at the position startRowDest and startColumnDest.

*

* If there is no Worksheet at index sourceIndex or destIndex, do nothing.

*

* You may create your own helper methods in either this file, or the Worksheet.java file.

*

*/

public void copyPaste(int sourceIndex, int startRowSource, int startColumnSource, int endRowSource, int endColumnSource,

int destIndex, int startRowDest, int startColumnDest) {

// To be completed

}

////////////////////////////////////////////////////////////

//////////// ////////////

////// //////

/// Do not edit the below methods ///

///// //////

//////////// ////////////

////////////////////////////////////////////////////////////

public Workbook(String title) {

this.title = title;

sheets = new ArrayList();

}

public void add(Worksheet sheet) {

sheets.add(sheet);

}

public Worksheet get(int index) {

if(index >= 0 && index < sheets.size())

return sheets.get(index);

else

return null;

}

public String toString() {

String result = title+" ";

if(sheets.size()==0)

return title+": empty";

for(Worksheet sheet: sheets)

result = result + sheet.toString()+" ";

return result;

}

/**

* replace all occurrences of key item by replacement item

* across all worksheets

* @param key

* @param replacement

*/

public void replace(double key, double replacement) {

for(Worksheet sheet: sheets)

sheet.replace(key, replacement);

}

/**

* create a deep copy of worksheet at index idx (if any)

* with the given title

* @param idx

* @param title

*/

public void duplicate(int idx, String title) {

if(idx < 0 || idx >= sheets.size())

return;

Worksheet sheet = new Worksheet(title);

ArrayList data = sheets.get(idx).getData();

for(DataEntry item: data) {

int r = item.getRow();

int c = item.getColumn();

double val = item.getValue();

sheet.set(r, c, val);

}

sheets.add(sheet);

}

/**

* set value of cell at address (r, c) in sheet

* at index idx (if any) to val

* @param idx

* @param r

* @param c

* @param val

*/

public void set(int idx, int r, int c, double val) {

if(idx < 0 || idx >= sheets.size())

return;

Worksheet sheet = sheets.get(idx);

sheet.set(r, c, val);

}

public Double total(int idx, int row1, int column1, int row2, int column2) {

if(idx < 0 || idx >= sheets.size())

return null;

return sheets.get(idx).total(row1, column1, row2, column2);

}

public Double average(int idx, int row1, int column1, int row2, int column2) {

if(idx < 0 || idx >= sheets.size())

return null;

return sheets.get(idx).average(row1, column1, row2, column2);

}

public int count(int idx, int row1, int column1, int row2, int column2) {

if(idx < 0 || idx >= sheets.size())

return 0;

return sheets.get(idx).count(row1, column1, row2, column2);

}

////////////////////////////////////////////////////////////

/// End of Workbook.java ///

////////////////////////////////////////////////////////////

}

------------------------------------------------------------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!