这是一个简单的问题,当我创建一个新的“音乐会”对象类时,如何使用 joptionpane 对话框限制它,当我运行它时,程序似乎并不关心我是否设置了布尔限制。我可以在一个月内输入 25,它会很好,并且在输出字符串中它显示“25”而没有错误。
if (userInput.equals("1")) {
do{
String artist = getStringInput("Artist or Group name?");
int month = getIntegerInput("Enter month in XX format ");
int day = getIntegerInput("Enter day in XX format ");
int year = getIntegerInput("Enter year in XXXX format");
int ticketCost = getIntegerInput("Enter cost per ticket ($25 - $250)");
int quantTickets = getIntegerInput("Enter Number of tickets available (Max 10,000)");
int concertId = 1000;
concert[numConcert++] = new Concert(artist,quantTickets,ticketCost,month,day,year,concertId);
班级
private String artist = "";
private int quantTickets = 0;
private int ticketCost = 0;
private int month = 0;
private int day = 0;
private int year = 0;
private int numConcert = 0;
private int concertId = 1000;
public Concert(String artist, int quantTickets, int ticketCost, int month, int day, int year, int concertId){
this.artist = artist;
this.quantTickets = quantTickets;
this.ticketCost = ticketCost;
this.month = month;
this.day = day;
this.year = year;
this.concertId = concertId;
}
public boolean setMonth (int month){
if (negative(month)) return false;
if (month > 12) return false;
this.month = month;
return true;
}
public int getMonth (){
return this.month ;
}