#User input checked against what is already in an array

1 messages · Page 1 of 1 (latest)

lyric lily
#

I want to ask the user to "Enter an event title" but I also want to program to break if they enter a title that already exists within an array. Currently its only doing this after price, and num of participants are entered. Any ideas?
ive attatched a photo of my code but will also copy it here as well 🙂

   do {
        System.out.println("Add More? (Y/N)");
        char prompt = sc.next().charAt(0);
        if (prompt == 'n' || prompt == 'N'){
            break;
        }
        else if (prompt == 'y' || prompt == 'Y') {
    
            System.out.println("Enter the title of the event:");
            sc.nextLine();
            String title = sc.nextLine();
            


            System.out.println("Enter the price per person:");
            int price = sc.nextInt();

            System.out.println("Enter the number of participants:");
            int quantity = sc.nextInt();

            // EventToBook event = new EventToBook();

            event.setTitle(title);
            event.setQuantity(quantity);
            event.setPrice(price);
        
            success = booking.addEventToBook(event);
            
            // if(success){
            // // System.out.println(event.toString());
            // booking.printTotal();}
            //wrote this here to tally up after each entry but later saw that this might not be
        }

    } while (success);


    booking.printTotal();
}
strong oakBOT
#

⌛ This post has been reserved for your question.

Hey @lyric lily! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

lyric lily
#

oh and this is my current way of dealing with it but its in my booking class and is only actioning it after all the info has been input by the user ie. event title, num of people and price

celest bough
#

you need to add a check right after the input for title

lyric lily
strong oakBOT
# lyric lily awesome got it! thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.