系统输出打印(“输入速度限制(>;0,<;=80):”; import java.util.Scanner; 公务舱票{ 公共静态void main(字符串[]args){ 扫描仪iq=新扫描仪(System.in); System.out.pri
系统输出打印(“输入速度限制(>;0,<;=80):”;系统输出打印(“输入速度限制(>;0,<;=80):”; import java.util.Scanner; 公务舱票{ 公共静态void main(字符串[]args){ 扫描仪iq=新扫描仪(System.in); System.out.pri,java,Java,系统输出打印(“输入速度限制(>;0,<;=80):”; import java.util.Scanner; 公务舱票{ 公共静态void main(字符串[]args){ 扫描仪iq=新扫描仪(System.in); System.out.println(“票证管理器”); System.out.println(“”); 票证t=新票证(“,0,0); 系统输出打印(“输入违规者姓名:”); t、 setName(iq.next()); //系统输出打印(“输入违规者的速度(>0):”
import java.util.Scanner;
公务舱票{
公共静态void main(字符串[]args){
扫描仪iq=新扫描仪(System.in);
System.out.println(“票证管理器”);
System.out.println(“”);
票证t=新票证(“,0,0);
系统输出打印(“输入违规者姓名:”);
t、 setName(iq.next());
//系统输出打印(“输入违规者的速度(>0):”;
//t、 设置速度(iq.nextInt());
做{
系统输出打印(“输入违规者的速度(>0):”;
t、 设置速度(iq.nextInt());
}而(t.getSpeed()<0);
系统输出打印(“输入速度限制(>0,0,do{
System.out.print(“输入速度限制(>0,if(t.getSpeedLimit()>0 | | t.getSpeedLimit())这里的问题是什么?到目前为止你做了什么?当我编译时,第二个循环不起作用。它需要大于cero,小于或等于80。对于任何正整数,它肯定是真的,但它不会测试OP想要什么。@ScaryWombatCode只回答低质量的答案。添加一些解释。为什么这段代码起作用?While此代码片段可能是解决方案,确实有助于提高您文章的质量。请记住,您将在将来回答读者的问题,而这些人可能不知道您代码建议的原因。
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());
}
}
do{
System.out.print("Enter the speed limit (>0,<=80): ");
t.setSpeedLimit(iq.nextInt());
}while(t.getSpeedLimit()<=0 || t.getSpeedLimit() >80);