I have made a code to store each appointment calendar given by user to an ArrayList. Each ArrayList contains title, description, date and time.
Now I want to make an option for the user to edit the data of appointment calendar of their choice.
I use the appointment calendar's title for the comparison. Here's the code:
// Asks user to enter the Appointment title that they wish to edit
System.out.println("Please enter the appointment that you wish to edit: ");
String choicetitle = scan.next();
for (Appointment value : aplist)
{
// if the title of the Appointment matches with one of the data, then..
if (choicetitle.equalsIgnoreCase(value.title))
{
// ..the output occurs on the console and asks the user to enter the new data
input = new Scanner(System.in);
System.out.println("Please give the new data: \n");
System.out.println("Please give the date of the appointment! \n" +
"Year (format YYYY): ");
year = input.nextInt();
System.out.println("Month (format MM): ");
month = input.nextInt();
System.out.println("Day (format DD): ");
day = input.nextInt();
value.date = LocalDate.of(year, month, day);
System.out.println("Please give the time of the appointment! \n" +
"Hour (format hh): ");
hour = input.nextInt();
System.out.println("Minute (format mm): ");
min = input.nextInt();
value.time = LocalTime.of(hour, min);
System.out.println("Please give the title of the appointment: ");
value.title = input.next();
System.out.println("Please give the description of the appointment: ");
value.desc = input.next();
}
// if the user enters a title that doesn't exist
else
{
System.out.println("There's no appointment with this title!");
}
}
But if there are already 3 elements (3 appointment calendars) in the ArrayList and let's say I want to edit the third one, it gives the following output:
There's no appointment with this title!
There's no appointment with this title!
Please give the new data:
Please give the date of the appointment!
Year (format YYYY):
Is there any way so that the output:
- only gives the scanner method when the title given by the user matches with one of the title in the ArrayList,
- only gives one "There's no appointment with this title" when user enters a title that doesn't match with any of the title in ArrayList?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire