1 商品促销日期计算程序

用户输入商品生产日期和保质期,通过程序计算促销日期。计算规则为:到保质期前14天所在周的周三为促销日。控制台交互情况如图-1所示。

图- 1

2 下面代码输出结果是?

Cell类的代码如下所示:

public class Cell{
	int row;
	int col;
	public Cell(int row, int col) {
		this.row = row;
		this.col = col;
	}
	public void drop() {
		row++;
	}
	@Override
	public String toString() {
		return "(" + row + "," + col + ")";
	}
}

运行testRef方法,程序的输出结果是:()。

	public void testRef() {
		Collection<Cell> cells = new ArrayList<Cell>();
		Cell c0 = new Cell(5, 6);
		Cell c1 = new Cell(7, 9);
		cells.add(c0);
		cells.add(c1);
		System.out.println(c0 + "," + c1);
		System.out.println(cells);  
		c0.drop();
		c1.drop();
		System.out.println(c0 + "," + c1);
		System.out.println(cells); 
	}

A.(5,6),(7,9)

[(5,6), (7,9)]

(6,6),(8,9)

[(6,6), (8,9)]

B.(5,6),(7,9)

[(5,6), (7,9)]

(5,6),(7,9)

[(5,6), (7,9)]

C.(5,6),(7,9)

[(5,6), (7,9)]

(6,6),(8,9)

[(5,6), (7,9)]

D.(6,6),(8,9)

[(6,6), (8,9)]

(6,6),(8,9)

[(6,6), (8,9)]

3 简述contains方法和equals方法的关系

4 下面代码输出的结果是?

请看如下代码:

	public void testSizeAndClearAndIsEmpty() {
		Collection<String> c = new ArrayList<String>();
		System.out.println("isEmpty:"+c.isEmpty()); 
		c.add("terry");
		c.add("allen");
		c.add("jerry");
		c.add("smith");
		System.out.println("isEmpty:" + c.isEmpty() + ",size: " + c.size());
		c.clear();
		System.out.println("isEmpty:" + c.isEmpty() + ", size: " + c.size());
	}

运行testSizeAndClearAndIsEmpty方法,程序的输出结果是:()。

A.isEmpty:false

isEmpty:true,size: 4

isEmpty:false, size: 0

B.isEmpty:true

isEmpty:false,size: 4

isEmpty:true, size: 4

C.isEmpty:false

isEmpty:true,size: 4

isEmpty:false, size: 4

D.isEmpty:true

isEmpty:false,size: 4

isEmpty:true, size: 0