第十三周课堂练习补交

教材代码检查P-145

练习代码

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MathTool {
    public static int sum(int... numbers) {
        int sum=0;
        for(int number:numbers) {
            sum+=number;
        }
        return sum;
    }
    @Test
    public void MathToolTest() throws Exception{
        assertEquals(MathTool.sum(1,2,3),6);
    }
}

运行结果截图

未及时提交原因

用虚拟机启动IDEA时,IDEA出现崩溃现象,启动用时过长,导致代码未能及时提交。

码云链接

类定义

练习代码

public class Book {
    String name;
    String author;
    String sellout;
    String date;

    public Book(String name, String author, String sellout, String date) {
        this.name = name;
        this.author = author;
        this.sellout = sellout;
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getSellout() {
        return sellout;
    }

    public void setSellout(String sellout) {
        this.sellout = sellout;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", sellout='" + sellout + '\'' +
                ", date='" + date + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book book = (Book) o;

        if (!name.equals(book.name)) return false;
        if (!author.equals(book.author)) return false;
        if (!sellout.equals(book.sellout)) return false;
        return date.equals(book.date);
    }

    public static void main(String[] args) {
        Book[] book1 = {
                new Book("code", "abc", "ABC", "2017.1.3")
        };
        Book[] book2 = {
                new Book("java", "bcd", "BCD", "2017.1.4")
        };
        Book[] book3 = {
                new Book("math", "cde", "CDE", "2017.1.7")
        };
        Book[] book4 = {
                new Book("code", "abc", "ABC", "2017.1.3")
        };
        System.out.println(book1.equals(book2));
        System.out.println(book1.equals(book3));
    }
}

运行截图

未及时提交原因

对题目理解出现问题,错误地认为利用@Test测试代码,导致代码调试失败。

码云链接

posted @ 2017-05-20 19:36  Lee.X  阅读(138)  评论(0编辑  收藏  举报