// CS 2510 Spring 2011 // Assignment 4: ExcelCells.java import tester.*; import image.*; import world.World; /* * +------------+ * | Cell |<-------------------+-+ * +------------+ | | * | int row | | | * | int col | | | * | IData data |--+ | | * +------------+ | | | * | | | * V | | * +-------+ | | * | IData | | | * +---+---+ | | * / \ | | * +-+-+ | | * | | | * +------------+-------+ | | * | | | | * +------+-----+ +-----+------+ | | * | Number | | Formula | | | * +------------+ +------------+ | | * | int number | +--| IFun fun | | | * +------------+ | | Cell rand1 |---+ | * | | Cell rand2 |-----+ * | +------------+ * V * +-------+ * | IFun | * +---+---+ * / \ * +-+-+ * | * +----------+-----------+ * | | | * +---+--+ +---+---+ +---+---+ * | Plus | | Minus | | Times | * +------+ +-------+ +-------+ * */ // Represents a Cell in a spreadsheet class Cell{ int row; int col; IData data; Cell(int row, int col, IData data){ this.row = row; this.col = col; this.data = data; } /* Template: * Fields: * ... this.row ... -- int * ... this.col ... -- int * ... this.data ... -- IData * * Methods: * * Methods for Fields: */ } // Represents Data in a Cell interface IData{ } // Represents numerical data in a Cell class Number implements IData{ int number; Number(int number){ this.number = number; } /* Template: * Fields: * ... this.number ... -- int * * Methods: */ } // Represents a Formula in a Cell class Formula implements IData{ IFun fun; Cell rand1; Cell rand2; Formula(IFun fun, Cell rand1, Cell rand2){ this.fun = fun; this.rand1 = rand1; this.rand2 = rand2; } /* Template: * Fields: * ... this.fun ... -- IFun * ... this.rand1 ... -- Cell * ... this.rand2 ... -- Cell * * Methods: * * Methods for Fields: */ } // Represents a two argument Function interface IFun{ } // Represents a two argument addition function class Plus implements IFun{ Plus(){} /* Template: * Methods: */ } // Represents a two argument subtraction function class Min implements IFun{ Min(){} /* Template: * Methods: */ } // Represents a two argument multiplication function class Times implements IFun{ Times(){} /* Template: * Methods: */ } // Examples and tests for excel classes class ExamplesExcelCells{ ExamplesExcelCells(){} IData n5 = new Number(5); IData n7 = new Number(7); Cell a1 = new Cell(1, 1, this.n5); Cell a2 = new Cell(2, 1, this.n7); IData fa3 = new Formula(new Plue(), this.a1, this.a2); Cell a3 = new Cell(3, 1, this.fa3); //** Tests... }