使用maven,intellij

时间:2016-03-01 03:36:43

标签: java maven intellij-idea switch-statement

当我连续多次调用Seat构造函数时,我似乎有一个奇怪的错误:

public Seat(int row, int column, int level) {
    if (level > 5 || level <= 0 || row <= 0 || column <= 0) {
        throw new IllegalArgumentException("level should be between 1 to 4 and all input should be positive");
    }
    switch(level) {
        case 1:
            if (row > 50 || column > 25) {
                throw new IllegalArgumentException("row cannot exceed 50 and column cannot exceed 25 for Orchestra" +
                        ". The valuese are " + " row = " + row + " column = " + column + " level = " + level);
            }
        case 2:
            if (row > 100 || column > 20) {
                throw new IllegalArgumentException("row cannot exceed 100 and column cannot exceed 20 for " +
                        "Main. The valuese are " + " row = " + row + " column = " + column + " level = " + level);
            }
        case 3:
            if (row > 100 || column > 15) {
                throw new IllegalArgumentException("row cannot exceed 100 and column cannot exceed 15 for" +
                        " Balcony 1. The valuese are " + " row = " + row + " column = " + column + " level = " + level);
            }
        case 4:
            if (row > 100 || column > 15) {
                throw new IllegalArgumentException("row cannot exceed 100 and column cannot exceed 15 for " +
                        "Balcony 2. The valuese are " + " row = " + row + " column = " + column + " level = " + level);
            }
    }
    rowN = row;
    columnN = column;
    levelN = level;
}

我得到的错误是

java.lang.IllegalArgumentException: row cannot exceed 100 and column cannot exceed 15 for Balcony 1. The valuese are  row = 1 column = 20 level = 2

at TicketHW.Seat.<init>(Seat.java:36)
at TicketHW.RigorousEstimate.SeatManager.convertSeatBundleToSeatHold(SeatManager.java:105)
at TicketHW.MyTicketService.findAndHoldSeats(MyTicketService.java:80)
at TicketHW.MyServiceTest2.interLevelBookingTest(MyServiceTest2.java:21)

当级别值为2时,它实际上输入3并给出错误。

0 个答案:

没有答案