#booking System Error

1 messages · Page 1 of 1 (latest)

lyric glade
#

I've made a booking system for a buss. I'm required to use a method to find and remove a booking with a date of birth or/and a name. I managed to do it with date of birth, but I don't know how to make it possible with Name.

gleaming nacelle
#

So yu trying to make a search index for looking up bookings?

gleaming nacelle
# lyric glade I've made a booking system for a buss. I'm required to use a method to find and ...

Okay, so i wrote a very simple way to look for names, but you will have to change how it gathers the data, and what the key word is to look for.

        System.out.println("What name are you looking for?");
        System.out.print("> ");
        Scanner input = new Scanner(System.in);//create scanner for user input
        String search = input.nextLine(); //save the user input
        System.out.println("Okay, searching for: " + search);
        List<String> names = new ArrayList<String>();//an array that holds a list of names
        try {
            Scanner scan = new Scanner(new File("names"));
            //read through the file for all the names
            while(scan.hasNextLine()) {
                names.add(scan.nextLine());
            }
            //close the scanner
            scan.close();
        } catch (FileNotFoundException e) {
            //handle any errors
            e.printStackTrace();
        }
        List<String> results = new ArrayList<String>();//an array to hold the results
        for(int i = 0; i < names.size(); i++) {
            //check to see if the name is what the user is looking for or contains something similar to it
            if(names.get(i).equals(search) || names.get(i).contains(search)) {
                results.add(names.get(i));//if it does, add it to the results
            }
        }
        //print out the results
        System.out.println("Results:");
        for(int i = 0; i < results.size(); i++) {
            System.out.println(results.get(i));
        }
        input.close();//close the scanner```

This is my way, there is a better way to about this, but this is a basic way to go about it. I don't know which error you have exactly but this is what i got. Hopefully this helps you.
lyric glade
#

Hey, I've read your code. Can I show mine that I made before?

#

@gleaming nacelle

gleaming nacelle
#

Yes, pelase do

#

itll help me what i need to look at and see what is going on

lyric glade
#

I came so far. It just dosen't work to put a name and find a booking. It automatically print "the name does not match anyone"

gleaming nacelle
#

Can you send me the .java file that this contains?

lyric glade
#

Sorry, like do you want me to paste the code?

gleaming nacelle
#

yeah you can do that, its just hard to see the code with the screenshots.. they're weird for my screen

lyric glade
#

static void TabortBokning(int[] Platser) {
try{
Scanner Scanner = new Scanner(System.in);
System.out.println("How do you want to cancel the booking (1) dateofbirth (2) name ");
int choice = Scanner.nextInt();

        String search;
        if(choice==1){
            System.out.println("Type date of birth: ");
             int dateOfBirth = Scanner.nextInt();
             search = String.valueOf(dateOfBirth);
        }
        else{
            System.out.println("type name: ");
            String förnamn = Scanner.next();
            search=förnamn;
        }
        boolean hittad=false;
        for (int i = 0; i < Platser.length; i++) {
          if(Platser[i]!= 0 && (String.valueOf(Platser[i]).equals(search) || String.valueOf(Platser[i]).equalsIgnoreCase(search))){

              Platser[i] = 0;
              System.out.println("the booking was cancelled");
              hittad=true;
              break;
          }
        }
         if (!hittad){
         System.out.println("the input does not match anyone");
       }
           }catch(InputMismatchException e){
            System.out.println("Vänligen Ange ditt födelsdatum ");

         }  
    }
#

If you want, I can send the code where I book a seat

gleaming nacelle
#

I assume the "Plaster" parameter is the bookings array that holds all the bookings correct?

lyric glade
#

Correct!

gleaming nacelle
#

okay, can you send me an example of what the array is, so i can debug this and figure it out..

lyric glade
#

Can I send you all the code so you can run it on your device ?

#

it's not much

gleaming nacelle
#

yeah you can do that

hollow burrowBOT
#

@lyric glade

Mhmm Uploaded Some Code
Uploaded these files to a Gist
lyric glade
#

public static void main(String[] args) {
Scanner Scanner = new Scanner(System.in);
int[] Platser = new int[21];
int alternativ=0;

    while (alternativ!= 6) {
        System.out.println(" Booknings Meny: ");
        System.out.println("(1). Boka plats");
        System.out.println("(2). Hitta bokning ");
        System.out.println("(3). Avboka bokning");
        System.out.println("(4). Ange antal lediga platser");
        System.out.println("(5). Berakna vinst av salda biljetter");
        System.out.println("(6). Booka fönsterplats");
        System.out.println("(7). Avsluta program\n");
        System.out.println("Vad kan vi hjalpa dig med?");
    
        
        try{
            alternativ = Scanner.nextInt();
       
        if (alternativ < 1 || alternativ > 6) {
        System.out.println("OBS! välj nummer endast mellan  1-6 , Vänligen försök igen.\n");
        continue;
        }
    
}   catch(InputMismatchException e){
        System.out.println("[Skriv endast val av nummer]\n");
                Scanner.nextLine();
                continue;
                }
gleaming nacelle
#

its fine, i got the file

lyric glade
#

oh ok

#

The instructions are on swedish, let me know if you want me to translate it

gleaming nacelle
#

Okay, I see what is going here

#

@lyric glade

lyric glade
#

YEs

gleaming nacelle
#

So, your array "Plater" Is holding the date of birth of the booking. Not the name.. So how you can fix this is by creating a booking class that will store the first name, the last name, the gender and Date of birth and make an array that holds all those Bookings.. Would you like an example of how it would look?

lyric glade
#

Yes

gleaming nacelle
#

Okay, give me a minute and ill get it

lyric glade
#

The last name and gender is unesaccery

gleaming nacelle
#

ill have comments and everything

#

Well its a user input so ill still add it

lyric glade
#

Alright!

gleaming nacelle
#

also i noticed that it was typed in a different language than English. For translation purposes, what language do you type in? so i can write comments and such so you can read

lyric glade
#

Add coments in english

#

it's fine

#

I just have it on swedish because it's a short project for my teacher

gleaming nacelle
#

Oh okay

gleaming nacelle
#

May i ask, are you familiar with ArrayLists?

#

@lyric glade

lyric glade
#

Actually no

gleaming nacelle
#

Okay, well think of it as an array like what you're using but it adds a more flexibility to add functionality. I can try to stick what you got here. If you look up 'Java ArrayList' you can go through the documentation about it.

lyric glade
#

Alright, it's fine i'll look it up

gleaming nacelle
#

Okay I got it

lyric glade
#

great!!

gleaming nacelle
#

Okay, let me send you both classes.. give me a second.. Mind if i DM them to you?

lyric glade
#

SUre!!

gleaming nacelle
#

I also did some improvements to it if you don't mind