Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:04:42+00:00 2026-05-30T21:04:42+00:00

My problem is that I have to write code to check if a customers

  • 0

My problem is that I have to write code to check if a customers name is already in my txt file (Customers.txt).

As you can see, I write my customers name ,every fourth line in my txt File.
I would like to have the input of a customers name with SimpleInOutDialog en then that inputs needs to be compared with al the customers name in my txt file.
How do I need to do this?

The code that I already have is below.

//make SimpleInOutDialog   
    SimpleInOutDialog  input = new SimpleInOutDialog("Customers");
    namecustomer = input.readString("Give in the name");
try{
BufferedReader br = new BufferedReader(new FileReader("L:\\Documents/Informatica/6de jaar/GIP/klanten.txt"));
HashSet<String> hs = new HashSet<String>();
int i = 0;
while ((line = br.readLine()) != null)
{
    i++;

       if (i % 4 == 0){
          if(hs.contains(namecustomer)){
             //customer exists
          input.showString("The customer exists", "");}
          else
           {setNewcustomer();}}


}
}catch (Exception e){//Catch wanneer er errors zijn
    System.err.println("Error: " + e.getMessage());}
return line;
}



public void setNewcustomer(){
    // make a newSimpleInOutDialog     
    SimpleInOutDialog  input = new SimpleInOutDialog("A new customer");
    //input
    S = "Name customer: " + input.readString("Give in your name:");
    WriteToFile();
    S = "Adress: " + input.readString("Give your adress");
    WriteToFile();
    S = "Telephonenummber: " + input.readString("Give your telephonenumber");
    WriteToFile();
    //making a customerID
      UUID idCustomer = UUID.randomUUID();  
    S = "CustomerID: " + customerID.toString();
    WriteToFile();

}

public void WriteToFile(){
try{

    FileWriter writer = new FileWriter("L:\\Documents/Informatica/6de jaar/GIP/Customer.txt", true);
    BufferedWriter out = new BufferedWriter(writer);
    //Wrting away your data
    out.write(S);

    //Closing the writer
    out.close();


}catch (Exception e){//Catch when there are errors
    System.err.println("Error: " + e.getMessage());
    }
    }

The changes need to be in be in getCustomer()
Thanks!!

Hi , Solved my problem , here is the solution:

public void getKlant() {
    // SimpleInOutDialog aanmaken     
        SimpleInOutDialog  input = new SimpleInOutDialog("Klanten");
        naamklant = input.readString("Geef de volledige naam in");
    try{
    BufferedReader br = new BufferedReader(new FileReader("L:\\Documents/Informatica/6de jaar/GIP/klanten.txt"));
    HashSet<String> hs = new HashSet<String>();
    int i = 0;
    while ((line = br.readLine()) != null)
    {
        i++;
        if (i == 1){hs.add(br.readLine());}

        if (i % 4 == 0){hs.add(br.readLine());}

    }
    if(hs.contains(naamklant)){
        //klant bestaat
     input.showString("De klant bestaat", "");
     }else{setNieuweKlant();}


    }catch (Exception e){//Catch wanneer er errors zijn
        System.err.println("Error: " + e.getMessage());}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:04:44+00:00Added an answer on May 30, 2026 at 9:04 pm

    Use a HashSet to store all of the names you read and then it’s just to call the contains methode to see if the customer already exists. If the names are stored on the forth line the code should look like this

    HashSet<String> hs = new HashSet<String>();
    int i = 0;
    while ((line = br.readLine()) != null)
    {
        i++;
           if (i % 4 == 0)
           {
              if(hs.contains(line))
                 //name already exist
              else
                hs.add(line);
                // new customer do what you want with it
    
           }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an intermittent problem with some code that writes to a Windows Event
I have to write an applet that brings up a password dialog. The problem
I have problem with fancybox. I want to write a function that will run
I'd like to write some code that would take a given data frame, check
I have a little problem that perhaps you can help me with. I try
(Problem solved, please see the updates) I have some files that have incorrect filenames
I want to write the code, that can deserialize the class even if the
I have the following code which will check to see if the following fields
Basically, I have to write a basic program that solves the n-queen problem, which
I have wrote an application that syncs two folders together. The problem with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.