System.out.print(“输入速度限制(> 0,<= 80):”);

时间:2019-09-30 02:49:42

标签: java

import java.util.Scanner;

public class TicketDriver {

    public static void main(String[] args) {
        Scanner iq = new Scanner(System.in);
        System.out.println("Ticket Manager");
        System.out.println("");
        Ticket t = new Ticket("",0,0);
        System.out.print("Enter the name of the violator: ");
        t.setName(iq.next());
        //System.out.print("Enter the speed of the violator (>0): ");
        //t.setSpeed(iq.nextInt());
        do{
            System.out.print("Enter the speed of the violator (>0): ");
            t.setSpeed(iq.nextInt());
        }while(t.getSpeed()< 0);
        System.out.print("Enter the speed limit (>0,<=80): ");
        t.setSpeedLimit(iq.nextInt());
        if(t.getSpeedLimit()>0 || t.getSpeedLimit() <=80) {
            System.out.print("Enter the speed limit (>0,<=80): ");
            t.setSpeedLimit(iq.nextInt());
        }
        System.out.print("Was this in a school zone(Y/N): ");
        t.setSchoolZone((iq.next()).matches("Y"));
        System.out.print("Was this in a work zone (Y/N):");
        t.setWorkZone((iq.next()).matches("Y"));
        System.out.println(t.printNotice());
    }
}

if(t.getSpeedLimit()>0 || t.getSpeedLimit() >=80)

限速循环不起作用

1 个答案:

答案 0 :(得分:0)

do{
        System.out.print("Enter the speed limit (>0,<=80): ");
        t.setSpeedLimit(iq.nextInt());
    }while(t.getSpeedLimit()<=0 || t.getSpeedLimit() >80);