if(arrival_month == depart_month){
String arrival_day1 = JOptionPane.showInputDialog("Enter your arrival day");
arrival_day = Integer.parseInt(arrival_day1);
String depart_day1 = JOptionPane.showInputDialog("Enter your Departure day");
depart_day = Integer.parseInt(depart_day1);
total_days_residing = depart_day - arrival_day;
}//end of if
else if(arrival_month > depart_month){
JOptionPane.showMessageDialog(null, "Error! Please Try Again");
}//end of else-if
else if (arrival_month <= depart_month){
String arrival_day1 = JOptionPane.showInputDialog("Enter your arrival date");
arrival_day = Integer.parseInt(arrival_day1);
while(arrival_day1.isEmpty()){
String arrival_day11 = JOptionPane.showInputDialog("Enter your arrival date");
arrival_day = Integer.parseInt(arrival_day11);
}
String depart_day1 = JOptionPane.showInputDialog("Enter your arrival date");
depart_day = Integer.parseInt(depart_day1);
while(depart_day1.isEmpty()){
String depart_day11 = JOptionPane.showInputDialog("Enter your arrival date");
arrival_day = Integer.parseInt(depart_day11);
}
//Sets Number of days in a month for the user's Arrival Month
if((arrival_month == 1)||(arrival_month == 3)||(arrival_month == 5)||(arrival_month == 7)||(arrival_month == 8)||(arrival_month == 10)||(arrival_month == 12)){
no_of_days_in_arrival_month = 31;
}
else if(arrival_month == 2){
no_of_days_in_arrival_month = 28;
}
else{
no_of_days_in_arrival_month = 30;
}
//Sets Number of Days in a month for the user's Departure Month
if((depart_month == 1)||(depart_month == 3)||(depart_month == 5)||(depart_month == 7)||(depart_month == 8)||(depart_month == 10)||(depart_month == 12)){
no_of_days_in_depart_month = 31;
}
else if(depart_month == 2){
no_of_days_in_depart_month = 28;
}
else{
no_of_days_in_depart_month = 30;
}
//Calculating Number of Days the user is going to stay
total_days_residing = (no_of_days_in_depart_month - (no_of_days_in_depart_month - depart_day) + (no_of_days_in_arrival_month - arrival_day)) ;
}//End of else
I want to reduce this code using date function and also i want to learn how to use that.
I got a different class prompting month.

New Topic/Question
Reply




MultiQuote





|